Skip to content

Commit

Permalink
added correlation matrix computation, including for vd-cma, ref CMA-E…
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Benazera committed Feb 27, 2015
1 parent 0e8cdbc commit 4093add
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cmasolutions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,33 @@ namespace libcmaes
}
}

dMat CMASolutions::corr() const
{
dMat corr, dinvcov;
if (_cov.size() > 0) // full cov
{
dinvcov = _cov.diagonal().cwiseSqrt().cwiseInverse();
corr = dMat(_cov.rows(),_cov.cols());
for (int i=0;i<_cov.cols();i++)
corr.col(i) = _cov.col(i).cwiseProduct(dinvcov);
for (int i=0;i<_cov.rows();i++)
corr.row(i) = corr.row(i).cwiseProduct(dinvcov.transpose());
}
else if (_v.size() > 0) //vd
{
// we need to compute the full covariance matrix, which is counter productive in large-scale settings
dMat cov =_sepcov.asDiagonal()*(dMat::Identity(_sepcov.rows(),_sepcov.rows())+_v*_v.transpose())*(_sepcov.asDiagonal());
dinvcov = cov.diagonal().cwiseSqrt().cwiseInverse();
corr = dMat(cov.rows(),cov.cols());
for (int i=0;i<cov.cols();i++)
corr.col(i) = cov.col(i).cwiseProduct(dinvcov);
for (int i=0;i<cov.rows();i++)
corr.row(i) = corr.row(i).cwiseProduct(dinvcov.transpose());
}
else return dMat::Constant(_sepcov.rows(),1,1.0); // sep
return corr;
}

void CMASolutions::update_eigenv(const dVec &eigenvalues,
const dMat &eigenvectors)
{
Expand Down
6 changes: 6 additions & 0 deletions cmasolutions.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ namespace libcmaes
return dVec(); // should never reach here.
}

/**
* \brief returns correlation matrix
* @return correlation matrix
*/
dMat corr() const;

/**
* \brief returns current value of step-size sigma
* @return current step-size
Expand Down

0 comments on commit 4093add

Please sign in to comment.