Skip to content

Commit

Permalink
Merge pull request #10 from rl27/master
Browse files Browse the repository at this point in the history
Bugfixes in CMA code
  • Loading branch information
yn-cloud committed May 12, 2024
2 parents 7ca8a5d + 197e66f commit f52795d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions CMAES.NET/CMA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void Tell(List<Tuple<Vector<double>, double>> solutions)
_C = (_C + _C.Transpose()) / 2;
MathNet.Numerics.LinearAlgebra.Factorization.Evd<double> evd_C = _C.Evd();
B = evd_C.EigenVectors;
D = Vector<double>.Build.Dense(evd_C.EigenValues.PointwiseSqrt().Select(tmp => tmp.Real).ToArray());
D = Vector<double>.Build.Dense(evd_C.EigenValues.PointwiseSqrt().Select(tmp => tmp.Real <= 0 ? _epsilon : tmp.Real).ToArray());
}
else
{
Expand Down Expand Up @@ -260,7 +260,7 @@ public void Tell(List<Tuple<Vector<double>, double>> solutions)
{
D_bunno1_diagMatrix[i, i] = D_bunno1_diag[i];
}
Matrix<double> C_2 = B * D_bunno1_diagMatrix * B;
Matrix<double> C_2 = B * D_bunno1_diagMatrix * B.Transpose();
_p_sigma = ((1 - _c_sigma) * _p_sigma) + (Math.Sqrt(_c_sigma * (2 - _c_sigma) * _mu_eff) * C_2 * y_w);

double norm_pSigma = _p_sigma.L2Norm();
Expand Down Expand Up @@ -334,8 +334,7 @@ private Vector<double> SampleSolution()
_C = (_C + _C.Transpose()) / 2;
MathNet.Numerics.LinearAlgebra.Factorization.Evd<double> evd_C = _C.Evd();
Matrix<double> B = evd_C.EigenVectors;
Vector<double> D = Vector<double>.Build.Dense(evd_C.EigenValues.PointwiseSqrt().Select(tmp => tmp.Real).ToArray());
D += _epsilon;
Vector<double> D = Vector<double>.Build.Dense(evd_C.EigenValues.PointwiseSqrt().Select(tmp => tmp.Real <= 0 ? _epsilon : tmp.Real).ToArray());
_B = B;
_D = D;
Matrix<double> D2diagonal = Matrix<double>.Build.DenseDiagonal(D.Count, 1);
Expand Down

0 comments on commit f52795d

Please sign in to comment.