Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmaEsElements"/> class.
        /// </summary>
        /// <param name="configuration">Fixed parameters for CMA-ES.</param>
        /// <param name="generation">The current generation.</param>
        /// <param name="distributionMean">The current distribution mean.</param>
        /// <param name="stepSize">The current step size.</param>
        /// <param name="covariances">The current covariance matrix.</param>
        /// <param name="covariancesDecomposition">The current eigendecomposition of the covariance matrix.</param>
        /// <param name="evolutionPath">The current evolution path.</param>
        /// <param name="conjugateEvolutionPath">The conjugate evolution path.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown if <paramref name="generation"/> or <paramref name="stepSize"/> are negative.
        /// </exception>
        public CmaEsElements(
            CmaEsConfiguration configuration,
            int generation,
            Vector <double> distributionMean,
            double stepSize,
            Matrix <double> covariances,
            Evd <double> covariancesDecomposition,
            Vector <double> evolutionPath,
            Vector <double> conjugateEvolutionPath)
        {
            if (generation < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(generation),
                          $"Generation must be nonnegative, but was {generation}.");
            }

            if (stepSize < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(stepSize),
                          $"Step size must be nonnegatives, but was {stepSize}.");
            }

            this.Configuration            = configuration;
            this.Generation               = generation;
            this._distributionMean        = distributionMean?.Clone();
            this.StepSize                 = stepSize;
            this._covariances             = covariances?.Clone();
            this._covariancesDiagonal     = covariancesDecomposition == null ? null : DiagonalMatrix.OfMatrix(covariancesDecomposition.D);
            this._covariancesEigenVectors = covariancesDecomposition?.EigenVectors.Clone();
            this._evolutionPath           = evolutionPath?.Clone();
            this._conjugateEvolutionPath  = conjugateEvolutionPath?.Clone();
        }
Пример #2
0
        /// <summary>
        /// Reads all internal data from file.
        /// </summary>
        /// <param name="pathToStatusFile">Path to the file to read.</param>
        public void UseStatusDump(string pathToStatusFile)
        {
            var status = StatusBase.ReadFromFile <CmaEsStatus>(pathToStatusFile);

            this._terminationCriteria.Clear();
            foreach (var terminationCriterion in status.TerminationCriteria)
            {
                this._terminationCriteria.Add(terminationCriterion.Restore());
            }

            this._configuration            = status.Data.Configuration;
            this._currentCmaesGeneration   = status.Data.Generation;
            this._distributionMean         = status.Data.DistributionMean;
            this._covariances              = status.Data.Covariances;
            this._covariancesDecomposition = this._covariances?.Evd(Symmetricity.Symmetric);
            this._stepSize               = status.Data.StepSize;
            this._evolutionPath          = status.Data.EvolutionPath;
            this._conjugateEvolutionPath = status.Data.ConjugateEvolutionPath;
        }
Пример #3
0
        /// <summary>
        /// Initializes the object to begin a new run.
        /// </summary>
        /// <param name="configuration">The <see cref="CmaEsConfiguration"/> to use.</param>
        /// <param name="terminationCriteria">Criteria when to terminate the run.</param>
        public void Initialize(CmaEsConfiguration configuration, IEnumerable <ITerminationCriterion> terminationCriteria)
        {
            this._configuration       = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this._terminationCriteria = terminationCriteria?.ToList() ??
                                        throw new ArgumentNullException(nameof(terminationCriteria));

            if (!this._terminationCriteria.Any())
            {
                throw new ArgumentOutOfRangeException(
                          nameof(terminationCriteria),
                          "There needs to be at least one termination criterion.");
            }

            this._currentCmaesGeneration = 0;
            this._covariances            = Matrix <double> .Build.DenseIdentity(this._configuration.SearchSpaceDimension);

            this._covariancesDecomposition = this._covariances.Evd();
            this._evolutionPath            = Vector <double> .Build.Dense(this._configuration.SearchSpaceDimension);

            this._conjugateEvolutionPath = Vector <double> .Build.Dense(this._configuration.SearchSpaceDimension);

            this._distributionMean = this._configuration.InitialDistributionMean;
            this._stepSize         = this._configuration.InitialStepSize;
        }