I need a similar (or the same) 2D surface to the one in the picture to produce some plots of my own experiments. Any ideas how can I find $f(x, y)$ of this surface?
PS: The picture is taken from Andrew NG's Coursera Machine Learning class, week 5.
I need a similar (or the same) 2D surface to the one in the picture to produce some plots of my own experiments. Any ideas how can I find $f(x, y)$ of this surface?
PS: The picture is taken from Andrew NG's Coursera Machine Learning class, week 5.
Okay. I gave some time to this, and here is what I found.
Matlab/octave has a function called peaks. This function plots the following function on 2d surface:
$$ \begin{align} f(x,y) &= 3*(1-x)^2*exp(-x^2 - (y+1)^2) \dots \\ & - 10*(x/5 - x^3 - y^5)*exp(-x^2-y^2) \dots \\ & - 1/3*exp(-(x+1)^2 - y^2) \end{align} $$
This is a pretty interesting surface. Here is the visualization:
Before finding peaks function, I was trying to mix couple 2d gaussian distributions. Here is the octave code that I wrote:
tx = linspace (-3, 3, 100)';
[xx, yy] = meshgrid (tx, tx);
% Each row contains a 2D gaussian parameters in the form:
% f(x, y) = A * exp(- (( ((x_0 - x)^2 ) / (2 * sigma_0^2) ) +
% ( ((y_0 - y)^2 ) / (2 * sigma_1^2) ) ) );
% in this order: A, x_0, y_0, sigma_0, sigma_1.
p = [ 1.80 0 1.7 0.55 0.55;
-1.30 -0.5 -1.5 0.45 0.45;
-0.45 -1.5 0.5 0.40 0.40;
0.95 -0.5 -0.5 0.55 0.55;
0.95 1.5 0 0.55 0.55; ];
zz = zeros( size(xx) );
for i=1:size(p, 1)
zz += p(i,1) * exp(- (( ((xx-p(i,2)).^2) / (2 * p(i,4) ^ 2) ) +
( ((yy-p(i,3)).^2) / (2 * p(i,5) ^ 2) )) );
end
surf(xx, yy, zz);
Here is the plot of the octave code:
The advantage of using the sum of gaussians over peaks function is that one can easily change the surface by playing with the mean and sigma values whichever the way he/she wants the surface to be.