Beispiel #1
0
        /// <summary>
        /// An Optimization Solver Using CMA-ES
        /// </summary>
        /// <param name="function">Objective function.</param>
        /// <param name="initnial">Initial values.</param>
        /// <param name="sigma">Step size of CMA-ES.</param>
        /// <param name="randSeed">(Optional) A seed number.</param>
        public CMAESOptimizer(Func <IList <double>, double> function, IList <double> initnial, double sigma, int randSeed = 0)
        {
            this.function = function;
            maxIteration  = initnial.Count * 200;

            cma = new CMA(initnial, sigma, seed: randSeed);

            ResultValue = double.MaxValue;
        }
Beispiel #2
0
        /// <summary>
        /// An Optimization Solver Using CMA-ES
        /// </summary>
        /// <param name="function">Objective function.</param>
        /// <param name="initial">Initial values.</param>
        /// <param name="sigma">Step size of CMA-ES.</param>
        /// <param name="lowerBounds">Lower limit of the optimized search range.</param>
        /// <param name="upperBounds">Upper limit of the optimized search range.</param>
        /// <param name="randSeed">(Optional) A seed number.</param>
        public CMAESOptimizer(Func <IList <double>, double> function, IList <double> initial, double sigma, IList <double> lowerBounds, IList <double> upperBounds, int randSeed = 0)
        {
            if (initial.Count != lowerBounds.Count)
            {
                throw new ArgumentException("Length of lowerBounds must be equal to that of initial.");
            }
            if (initial.Count != upperBounds.Count)
            {
                throw new ArgumentException("Length of upperBounds must be equal to that of initial");
            }

            this.function = function;
            maxIteration  = initial.Count * 200;

            Matrix <double> bounds = Matrix <double> .Build.Dense(initial.Count, 2);

            bounds.SetColumn(0, lowerBounds.ToArray());
            bounds.SetColumn(1, upperBounds.ToArray());

            cma = new CMA(initial, sigma, bounds, seed: randSeed);

            ResultValue = double.MaxValue;
        }