an 29, 2010


% hyperparameters
mean0 = params.mean0;
precMat0 = inv(params.covMat0);
nu0 = params.nu0;
S0 = params.S0;
[d,n] = size(data);

% Initialize chain by setting mu= sample mean
xbar = mean(data,2);
mu = xbar;
for i = 1:nSamples
  % sample Sigma given mu
  nu = nu0 + n;
  diff = data - repmat(mu,1,n);
  S = S0 + diff*diff';
  Sigma = iwishrnd(S,nu);
  
  % sample mu given Sigma
  precMat = inv(Sigma);
  covMat = inv(precMat0 + n*precMat);
  mean_ = covMat*(precMat0*mean0 + n*precMat*xbar);
  mu = m