public void TestConstrainedFeasibleRegion()
        {
            // Test that the parameter set does not deal with its constraints,
            // because the URS should, to try to preserve uniformity of sampling with varying bounds.
            var p = new TwoParamsConstraints();

            Assert.IsTrue(p.IsWithinBounds);
            var names = p.GetVariableNames();

            Assert.AreEqual(5, p.GetValue(names[1]));
            Assert.AreEqual(5, p.GetMaxValue(names[1]));
            p.SetValue(names[1], 10);
            Assert.IsFalse(p.IsWithinBounds);
            Assert.AreEqual(10, p.GetValue(names[1]));


            var rng = new BasicRngFactory(0);
            var urs = new UniformRandomSamplingFactory <TwoParamsConstraints>(rng.CreateFactory(), new TwoParamsConstraints());
            int n   = 200;
            var pop = new TwoParamsConstraints[n];

            for (int i = 0; i < n; i++)
            {
                pop[i] = urs.CreateRandomCandidate();
                Assert.IsTrue(pop[i].IsWithinBounds);
            }
            var hcOps   = urs.CreateNew(rng.CreateFactory());
            var hcArray = Array.ConvertAll(pop, x => (IHyperCube <double>)x);

            for (int i = 0; i < n; i++)
            {
                p = (TwoParamsConstraints)hcOps.GenerateRandomWithinHypercube(hcArray);
                Assert.IsTrue(p.IsWithinBounds);
            }
        }
Пример #2
0
        public void TestCoeffVariationTerminationCriteria()
        {
            double threshold   = 2.5e-2;
            var    termination = new ShuffledComplexEvolution <TestHyperCube> .CoefficientOfVariationTerminationCondition(threshold : threshold);

            IObjectiveScores[] population = createSample(converged: false);
            double             cv         = termination.GetMaxParameterCoeffVar(population);

            Assert.AreEqual(0.1104401, cv, 1e-6);
            Assert.IsFalse(termination.IsBelowCvThreshold(population));

            population = createSample(converged: true);
            cv         = termination.GetMaxParameterCoeffVar(population);
            Assert.AreEqual(0.01741291, cv, 1e-6);
            Assert.IsTrue(termination.IsBelowCvThreshold(population));


            termination = new ShuffledComplexEvolution <TestHyperCube> .CoefficientOfVariationTerminationCondition(threshold : threshold, maxHours : 0.1);

            var rng       = new BasicRngFactory(0);
            var evaluator = new ObjEvalTestHyperCube(new ParaboloidObjEval <TestHyperCube>(bestParam: 2));
            var engine    = createSce(termination, rng, evaluator);
            var results   = engine.Evolve();

            //Console.WriteLine("Current shuffle: {0}", engine.CurrentShuffle);
            Assert.IsFalse(termination.HasReachedMaxTime());
        }
Пример #3
0
        private ICandidateFactory <MpiSysConfig> CreatePopulationInitialiser(
            IClonableObjectiveEvaluator <MpiSysConfig> objectiveEvaluator,
            MpiSysConfig templateParameterSet,
            MpiSysConfig[] seedsPopulation,
            string initialisationOption = "")
        {
            Log.Debug("Root: creating population initialiser");
            var options = initialisationOption.Split(':');
            var seeds   = new List <MpiSysConfig> {
                templateParameterSet
            };

            if (seedsPopulation != null)
            {
                seeds.AddRange(seedsPopulation);
            }
            var rng = new BasicRngFactory(SceParameterDefinition.RandomizationSeed);

            ICandidateFactory <MpiSysConfig> result = CreatePopulationInitialiser(
                templateParameterSet,
                rng,
                objectiveEvaluator,
                options);

            if (result is BestOfSampling <MpiSysConfig> )
            {
                return(result);
            }
            else
            {
                return(new SeededSamplingFactory <MpiSysConfig>(result, seeds));
            }
        }
Пример #4
0
        private static ShuffledComplexEvolution <ICloneableSystemConfiguration> createSce(IClonableObjectiveEvaluator <ICloneableSystemConfiguration> evaluator)
        {
            var rng    = new BasicRngFactory(0);
            var engine = new ShuffledComplexEvolution <ICloneableSystemConfiguration>(
                evaluator,
                new UniformRandomSamplingFactory <IHyperCube <double> >(rng.CreateFactory(), new UnivariateReal(0)),
                new ShuffledComplexEvolution <ICloneableSystemConfiguration> .MaxShuffleTerminationCondition(),
                5, 20, 10, 3, 20, 7,
                rng,
                new ZitlerThieleFitnessAssignment());

            return(engine);
        }
Пример #5
0
        private static ICandidateFactory <MpiSysConfig> CreatePopulationInitialiser(
            MpiSysConfig templateParameterSet,
            BasicRngFactory rng,
            IClonableObjectiveEvaluator <MpiSysConfig> objectiveEvaluator,
            params string[] options)
        {
            switch (options[0].ToLower())
            {
            case "bestof":
                int      poolSize   = int.Parse(options[1]);
                int      bestPoints = int.Parse(options[2]);
                string[] subOptions = Subset(3, options);

                if (poolSize < bestPoints)
                {
                    Log.WarnFormat(
                        "Root: Best of Sampling pool size ({0}) is smaller than best points ({1}). Setting best points to match pool size.",
                        poolSize,
                        bestPoints);
                    bestPoints = poolSize;
                }

                Log.DebugFormat("Root: creating BestOfSampling. Pool size: {0}, best points: {1}", poolSize, bestPoints);
                return
                    (new BestOfSampling <MpiSysConfig>(
                         CreatePopulationInitialiser(templateParameterSet, rng, objectiveEvaluator, subOptions),
                         poolSize,
                         bestPoints,
                         objectiveEvaluator,
                         new DefaultFitnessAssignment()));

            case "lhc":
                Log.Debug("Root: creating Latin Hypercube Sampling");
                return(new LatinHypercubeSampling <MpiSysConfig>(rng, templateParameterSet));

            case "weibull":
                Log.Debug("Root: creating weibull distribution");
                return(new SeededSamplingFactory <MpiSysConfig>(
                           new WeibullGen <MpiSysConfig>(rng, templateParameterSet),
                           new List <MpiSysConfig> {
                    templateParameterSet
                }));

            case "":
            case "urs":
            default:
                Log.Debug("Root: creating URS");
                return(new UniformRandomSamplingFactory <MpiSysConfig>(rng, templateParameterSet));
            }
        }
Пример #6
0
        private static ShuffledComplexEvolution <TestHyperCube> createSce(double cvThreshold, double maxHours, double objCalcPauseSec, TestObjEval <TestHyperCube> innerObjCalc = null, int maxShuffle = 15)
        {
            var termination = new ShuffledComplexEvolution <TestHyperCube> .CoefficientOfVariationTerminationCondition(threshold : cvThreshold, maxHours : maxHours);

            var rng = new BasicRngFactory(0);

            if (innerObjCalc == null)
            {
                innerObjCalc = new ParaboloidObjEval <TestHyperCube>(bestParam: 2);
            }
            var evaluator = new ObjEvalTestHyperCube(innerObjCalc, pauseSeconds: objCalcPauseSec);
            var engine    = createSce(termination, rng, evaluator, maxShuffle: maxShuffle);

            return(engine);
        }
Пример #7
0
        private static ShuffledComplexEvolution <TestHyperCube> createSce(ShuffledComplexEvolution <TestHyperCube> .CoefficientOfVariationTerminationCondition termination, BasicRngFactory rng, ObjEvalTestHyperCube evaluator, int maxShuffle = 15)
        {
            var engine = new ShuffledComplexEvolution <TestHyperCube>(
                evaluator,
                new UniformRandomSamplingFactory <TestHyperCube>(rng.CreateFactory(), new TestHyperCube(2, 0, -10, 10)),
                termination,
                5, 20, 10, 3, 20, maxShuffle,
                rng,
                new DefaultFitnessAssignment());

            return(engine);
        }