mnmbs
mnmbs

Reputation: 363

Matlab implement gaussian process

I want to implement the following gaussian process in Matlab. So far i tried normpdf and normrnd but the results are not what i was expecting. B is an NxN matrix and the expected result for en is a Nx1 vector. Using both methods I get an NxN matrix.

Any suggestions?

gaussian process

Upvotes: 1

Views: 297

Answers (2)

Tommaso Belluzzo
Tommaso Belluzzo

Reputation: 23685

I think this is what you are looking for:

% Number of samples for each variable:
k = 100;

% Your parameters:
mu = [0; 0]; % Vector of Means (0 in your case)
cov = [3 1; 1 3]; % Covariance Matrix (your B)

% Draw the samples...
s = mvnrnd(mu,cov,k);

If you want to perform the same calculation manually (by generating a sample of independent standard normal variables and then applying the appropriate transformation):

% Number of samples for each variable:
k = 100;

% Your parameters:
mu = [0 0]; % Vector of Means (0 in your case)
cov = [3 1; 1 3]; % Covariance Matrix (your B)

% Draw the samples...
s_ind = randn(k,size(cov,1));
s = repmat(mu,k,1) + (chol(cov) * ind_s);

Upvotes: 1

mikkola
mikkola

Reputation: 3476

The documentation page for randn shows the following example for generating samples from a bivariate normal distribution:

mu = [1 2];
sigma = [1 0.5; 0.5 2];
R = chol(sigma);
z = repmat(mu,10,1) + randn(10,2)*R

mu is the mean vector which you should set to a zero vector of appropriate size. sigma is the covariance matrix, B^-1 in your example. The example above draws 10 samples, you can change this to however many you need. Also remember to change the dimension 2 to N in your application.

Upvotes: 1

Related Questions