Ejemplo n.º 1
0
        public void CreateInitialVertices_WithStepSizeZero_Throws()
        {
            var initialVertex = DecisionVector.CreateFromArray(
                DecisionSpace.CreateForUniformDoubleArray(3, double.MinValue, double.MaxValue),
                Enumerable.Repeat(0.0, 3));

            Assert.Throws <ArgumentOutOfRangeException>(() => Simplex.CreateInitialVertices(initialVertex, 0));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a new Nelder-Mead Simplex local search optimiser.
        /// </summary>
        /// <param name="fitnessCalculator">A <see cref="FitnessCalculatorSingleObjective"/>. <see cref="Optimiser"/></param>
        /// <param name="initialLocation">Starting location for the search.</param>
        /// <param name="hyperParameters">
        /// Instance of <see cref="HyperParameterManager"/> containing values for
        /// all the coefficients required by <see cref="NelderMeadHyperParameters"/>.
        /// </param>
        public NelderMead(
            IFitnessCalculator fitnessCalculator,
            DecisionVector initialLocation,
            HyperParameterManager hyperParameters) :
            base(new Simplex(initialLocation.Count), fitnessCalculator)
        {
            // Set up simplex operations
            OperationsManager = new NelderMeadSimplexOperationsManager(hyperParameters);

            //Set up simplex
            InitialVerticesStillUnevaluated = Simplex.CreateInitialVertices(
                initialLocation,
                hyperParameters.GetHyperParameterValue <double>(NelderMeadHyperParameters.Simplex_Creation_Step_Size));

            //Initialise historian
            tempProgress.Add(NelderMeadSimplexOperations.R);
        }
Ejemplo n.º 3
0
        public void CreateInitialVertices_CreatesCorrectly(int numDims, double stepSize)
        {
            var initialVertex = DecisionVector.CreateFromArray(
                DecisionSpace.CreateForUniformDoubleArray(numDims, double.MinValue, double.MaxValue),
                Enumerable.Repeat(0.0, numDims));
            var newVertices = Simplex.CreateInitialVertices(initialVertex, stepSize);

            // Collection must be D+1 long
            Assert.True(newVertices.Count == numDims + 1);

            // Every vector must be D long
            Assert.All(newVertices, v => Assert.True(v.Count == numDims));

            // The Euclidean distance of every vector from the initial one must be equal to stepSize
            Assert.All(newVertices.Skip(1),
                       v => Assert.True(Math.Sqrt(v
                                                  .Select((a, i) => (double)a - (double)initialVertex.ElementAt(i))
                                                  .Select(a => Math.Pow(a, 2))
                                                  .Sum())
                                        == stepSize));
        }