# rbfComputeBasis

## PURPOSE

Get locations and sizes of radial basis functions for use in rbf network.

## SYNOPSIS

function rbfBasis = rbfComputeBasis( X, k, cluster, scale, show )

## DESCRIPTION

     Get locations and sizes of radial basis functions for use in rbf network.

     Radial basis function are a simple, fast method for universal function
     approximation / regression. The idea is to find a mapping X->y where X
     and y are continuous real variables. The mapping is linear over features
     of X: y=rbfWeight*features(X). The features are of the form:
      f_j(x) = exp(-||x-mu_j||_2^2 / 2 sig_j^2 ).
     The number of basis functions controls the complexity of the network. Too
     many basis functions can lead to overfitting, too few to bad
     interpolation. Rbf networks are trained in two phases.  First, the radial
     basis functions are found in an unsupervised manner (using only Xtrain),
     for example by clustering Xtrain.  Next, given the basis functions,
     Xtrain and ytrain, the basis weights are found by solving the system:
      rbfWeight * features(Xtrain) = ytrain
     At this point, to interpolate any new points, Xtest, use:
      ytest = rbfWeight * features(Xtest)
     The code below achieves all three steps:
      rbfBasis  = rbfComputeBasis( Xtrain, k, cluster, scale, show );
      rbfWeight = rbfComputeFtrs(Xtrain,rbfBasis) \ ytrain;
      ytest     = rbfComputeFtrs(Xtest,rbfBasis) * rbfWeight;
     Note, in the returned rbfBasis struct there are a number of flags that
     control how the rbf features are computed. These can be altered to
     achieve the desired effect.

     For an in depth discussion of rbf networks see:
      Christopher M. Bishop. "Neural Networks for Pattern Recognition"

     USAGE
      rbfBasis = rbfComputeBasis( X, k, [cluster], [scale], [show] )

     INPUTS
      X           - [N x d] N points of d dimensions each
      k           - number of basis functions to use
      cluster     - [1]: Computes cluster centers for use as rbf functions.
                  - 0: Evenly centered basis functions (ok for small d)
      scale       - [5] Alter computed value of sigma by given factor
                    set larger for smoother results, too small -> bad interp
      show        - [0] will display results in figure(show)
                    if show<0, assumes X is array Nxs^2 of N sxs patches

     OUTPUTS
      rfbBasis
       .d          - feature vector size
       .k          - number of basis functions actually used
       .mu         - [d x k] rbf centers
       .vars       - [1 x k] rbf widths
       .var        - rbf average width
       .globalVar  - [1] if true use single average var for rbfs
       .constant   - [0] if true include extra basis with constant activation
       .normalize  - [0] if true normalize overall rbf response to sum to 1

     EXAMPLE

     See also RBFDEMO, RBFCOMPUTEFTRS

     Piotr's Image&Video Toolbox      Version 2.50
     Copyright 2012 Piotr Dollar.  [pdollar-at-caltech.edu]
     Please email me if you find bugs, or have suggestions or questions!
     Licensed under the Simplified BSD License [see external/bsd.txt]