Skip to content

Instantly share code, notes, and snippets.

@spaghetti-source
Created May 19, 2013 13:52
Show Gist options
  • Save spaghetti-source/5607699 to your computer and use it in GitHub Desktop.
Save spaghetti-source/5607699 to your computer and use it in GitHub Desktop.
% Radial Basis Function expansion
%
% f(x) = sum k(x, yi) wi
% -> w = k(X,Y) \ f(X)
% here k(x,y) := rho(|x-y|), e.g., exp(-|x-y2|^2)
% input data
N = 100;
X = rand(N,1);
fX = abs( cos( 2 * 3.14 * (X .* X) ) );
% key points
M = 10;
Y = X(randperm(size(X,1)));
Y = X(randperm(size(X,1))); Y = Y(1:M);
% estimate
beta = 0.1;
D = repmat(X,1,size(Y,1))-repmat(Y',size(X,1),1);
K = exp( - D .* D / beta );
w = K \ fX;
% test
S = 1000;
Z = [0:1.0/S:1]';
D = repmat(Z,1,size(Y,1)) - repmat(Y',size(Z,1),1);
K = exp( - D .* D / beta );
fZ = K * w;
xlim([0,1]);
plot(X, fX, 'r.');
hold on;
plot(Z, fZ, 'b-');
hold off;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment