/// <summary> /// Checks adding a 0.2-standard deviation vector in any single coordinate does /// not change the distribution mean. /// </summary> /// <param name="data">Internal <see cref="CmaEs{TSearchPoint}"/> data.</param> /// <returns>Whether no change occurred in distribution mean.</returns> public bool IsMet(CmaEsElements data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (!data.IsCompletelySpecified()) { throw new ArgumentOutOfRangeException( nameof(data), "Data must be completely specified for this termination criterion."); } for (int i = 0; i < data.Configuration.SearchSpaceDimension; i++) { var shiftedMean = data.DistributionMean[i] + ((0.2 * data.StepSize) * data.Covariances[i, i]); if (data.DistributionMean[i].Equals(shiftedMean)) { // Might be true due to numerical issues. Then we should stop. return(true); } } return(false); }
public void IsCompletelySpecifiedReturnsTrueForEverythingSpecified() { var data = new CmaEsElements( this._configuration, this._generation, this._distributionMean, this._stepSize, this._covariances, this._covariancesDecomposition, this._evolutionPath, this._conjugateEvolutionPath); Assert.True( data.IsCompletelySpecified(), "Data is completely specified."); }
public void IsCompletelySpecifiedReturnsFalseForMissingConjugateEvolutionPath() { var noConjugateEvolutionPath = new CmaEsElements( this._configuration, this._generation, this._distributionMean, this._stepSize, this._covariances, this._covariancesDecomposition, this._evolutionPath, conjugateEvolutionPath: null); Assert.False( noConjugateEvolutionPath.IsCompletelySpecified(), "Data without a conjugate evolution path is not completely specified."); }
public void IsCompletelySpecifiedReturnsFalseForMissingDistributionMean() { var noDistributionMean = new CmaEsElements( this._configuration, this._generation, distributionMean: null, stepSize: this._stepSize, covariances: this._covariances, covariancesDecomposition: this._covariancesDecomposition, evolutionPath: this._evolutionPath, conjugateEvolutionPath: this._conjugateEvolutionPath); Assert.False( noDistributionMean.IsCompletelySpecified(), "Data without a distribution mean is not completely specified."); }
/// <summary> /// Checks if the factor between current and initial step size is greater than a <see cref="MaxFactor"/> times /// the square root of the covariance matrix's largest eigenvalue. /// </summary> /// <param name="data">Internal <see cref="CmaEs{TSearchPoint}"/> data.</param> /// <returns>Whether the factor is greater.</returns> public bool IsMet(CmaEsElements data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (!data.IsCompletelySpecified()) { throw new ArgumentOutOfRangeException( nameof(data), "Data must be completely specified for this termination criterion."); } var largestEigenvalue = data.CovariancesDiagonal.Diagonal().Maximum(); return(data.StepSize / data.Configuration.InitialStepSize > MaxFactor *Math.Sqrt(largestEigenvalue)); }
/// <summary> /// Checks adding a 0.1-standard deviation vector in a principal axis direction of the covariance matrix does /// not change the distribution mean. /// <para>Axis is chosen dependent on generation.</para> /// </summary> /// <param name="data">Internal <see cref="CmaEs{TSearchPoint}"/> data.</param> /// <returns>Whether no change occurred in distribution mean.</returns> public bool IsMet(CmaEsElements data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (!data.IsCompletelySpecified()) { throw new ArgumentOutOfRangeException( nameof(data), "Data must be completely specified for this termination criterion."); } int index = data.Generation % data.Configuration.SearchSpaceDimension; var principalAxisDirection = Math.Sqrt(data.CovariancesDiagonal[index, index]) * data.CovariancesEigenVectors.Column(index); var shiftedMean = data.DistributionMean + ((0.1 * data.StepSize) * principalAxisDirection); // Might be true due to numerical issues. return(data.DistributionMean.Equals(shiftedMean)); }