public void CorrectMeans()
        {
            const int numScores     = 4;
            const int numObjectives = 3;

            MpiObjectiveScores[] scores        = new MpiObjectiveScores[numScores];
            double[]             expectedMeans = new double[numObjectives];

            for (int i = 0; i < numScores; i++)
            {
                IObjectiveScore[] objectives = new IObjectiveScore[numObjectives];
                for (int j = 0; j < numObjectives; j++)
                {
                    double fs = FakeScore(i + j);
                    expectedMeans[j] += fs;
                    objectives[j]     = new DoubleObjectiveScore(String.Format("{0}-{1}", i, j), fs, true);
                }

                scores[i] = new MpiObjectiveScores(objectives, config);
            }

            for (int i = 0; i < numObjectives; i++)
            {
                expectedMeans[i] /= numScores;
            }

            var result = ObjectiveScoresHelper.Mean(scores, config);

            for (int i = 0; i < numObjectives; i++)
            {
                Assert.That((double)result.GetObjective(i).ValueComparable, Is.EqualTo(expectedMeans[i]).Within(1e-8));
            }
        }
Example #2
0
        private IObjectiveScores[] createSample(bool converged = false)
        {
            /*
             * > s = rnorm(7, 1000, 12)
             * [1] 1024.0471  980.6007 1006.0446  972.9169 1000.0527 1004.0899 1008.8202
             * > sd(s)/mean(s)
             * [1] 0.01741291
             * [1] 1001.3914 1005.0520 1015.2980 1016.9730  981.3532 1000.1558  999.8205
             * > sd(s)/mean(s)
             * [1] 0.01179792
             * [1]  960.8459  880.2550  918.0862  964.6065  994.5268  910.9359 1204.6796
             * > sd(s)/mean(s)
             * [1] 0.1104401
             * [1]  ,  955.1453 1155.3053 1147.6358 1020.7405  910.9917  723.9004
             * > sd(s)/mean(s)
             * [1] 0.1555959
             */

            var pset = new TestHyperCube[7];

            double[] narrow_one = { 1024.0471, 980.6007, 1006.0446, 972.9169, 1000.0527, 1004.0899, 1008.8202 };
            double[] narrow_two = { 1001.3914, 1005.0520, 1015.2980, 1016.9730, 981.3532, 1000.1558, 999.8205 };
            double[] large_one  = { 960.8459, 880.2550, 918.0862, 964.6065, 994.5268, 910.9359, 1204.6796 };
            double[] large_two  = { 899.5851, 955.1453, 1155.3053, 1147.6358, 1020.7405, 910.9917, 723.9004 };

            for (int i = 0; i < narrow_one.Length; i++)
            {
                pset[i] = new TestHyperCube(2, 1000, 0, 4000);
                pset[i].SetValues(narrow_one[i], (converged ? narrow_two[i] : large_one[i]));
            }
            var d = new DoubleObjectiveScore("FakeNSE", 0.5, true);

            return(Array.ConvertAll(pset, (x => new MultipleScores <TestHyperCube>(new IObjectiveScore[] { d }, x))));
        }
        protected override IObjectiveScores <T> evalScore(T sysConfig)
        {
            var    names    = sysConfig.GetVariableNames();
            double result   = calcObjective(sysConfig, names);
            var    dblScore = new DoubleObjectiveScore("Paraboloid", result, maximise: false);

            return(new MultipleScores <T>(new IObjectiveScore[] { dblScore }, sysConfig));
        }
        public IObjectiveScores <T> EvaluateScore(T systemConfiguration)
        {
            double score = calculateScore(systemConfiguration);
            DoubleObjectiveScore objectiveScore  = new DoubleObjectiveScore("Sum of Squared Residuals", score, false);
            MultipleScores <T>   objectiveScores = new MultipleScores <T>(new DoubleObjectiveScore[] { objectiveScore }, systemConfiguration);

            return(objectiveScores);
        }
        public IObjectiveScores <TestHyperCube> EvaluateScore(TestHyperCube sysConfig)
        {
            var names = sysConfig.GetVariableNames();

            IObjectiveScore[] scores = new IObjectiveScore[names.Length];
            for (int i = 0; i < names.Length; i++)
            {
                var name = names[i];
                scores[i] = new DoubleObjectiveScore(name + "_s", sysConfig.GetValue(name), maximise: false);
            }
            return(new MultipleScores <TestHyperCube>(scores, sysConfig));
        }
Example #6
0
 /// <summary>
 /// Doesn't really print what is needed
 /// </summary>
 /// <param name="items"></param>
 public static void PrintObjScores(IObjectiveScores[] items)
 {
     for (int i = 0; i < items.Length; i++)
     {
         for (int j = 0; j < items[i].ObjectiveCount; j++)
         {
             IObjectiveScore      objScore             = items[i].GetObjective(j);
             DoubleObjectiveScore doubleObjectiveScore = objScore as DoubleObjectiveScore;
             string objectiveType = doubleObjectiveScore.GetText( );
             string systemConfig  = items[i].SystemConfiguration.GetConfigurationDescription();
             Console.WriteLine(string.Concat(objectiveType, System.Environment.NewLine, systemConfig));
         }
     }
     Console.WriteLine("***********");
 }
        private MpiObjectiveScores[] CreateRandomScores(int numScores, int objectivesPerScore)
        {
            MpiObjectiveScores[] scores = new MpiObjectiveScores[numScores];

            for (int i = 0; i < numScores; i++)
            {
                IObjectiveScore[] objectives = new IObjectiveScore[objectivesPerScore];
                for (int j = 0; j < objectivesPerScore; j++)
                {
                    objectives[j] = new DoubleObjectiveScore(String.Format("{0}-{1}", i, j), FakeScore(i + j), true);
                }

                scores[i] = new MpiObjectiveScores(objectives, config);
            }

            return(scores);
        }
Example #8
0
        public static IObjectiveScores[] CreateTestScores(int objectivesPerScore, MpiSysConfig[] configs)
        {
            int numScores = configs.Length;

            IObjectiveScores[] scores = new IObjectiveScores[numScores];
            for (int i = 0; i < numScores; i++)
            {
                IObjectiveScore[] objectives = new IObjectiveScore[objectivesPerScore];
                for (int j = 0; j < objectivesPerScore; j++)
                {
                    objectives[j] = new DoubleObjectiveScore(String.Format("Score:{0}-{1}", i, j), FakeScore(i + j), true);
                }

                scores[i] = new MpiObjectiveScores(objectives, configs[i]);
            }

            return(scores);
        }
        /// <summary>
        /// Calculates the per-objective means of the specified scores.
        /// </summary>
        /// <param name="scoresArray">The scores.</param>
        /// <param name="sysConfig">The sys config.</param>
        /// <returns>A single <see cref="IObjectiveScores"/> instance where the i'th score is the
        /// mean of the i'th score in each element of the scores array.
        /// The result score names are taken from the first input element.</returns>
        /// <remarks>
        /// This method makes a few assumptions which are not checked for performance reasons:
        ///     - each element in the scores array has the same objective count. More specifically,
        ///       if an element has more scores than element 0, the additional scores will be ignored.
        ///       If an element has less scores, then an out of bounds array access error will occur.
        ///     - score names are ignored. It is assumed that every element in scores has named scores
        ///       occuring in the same order.
        /// </remarks>
        public static MpiObjectiveScores Mean(MpiObjectiveScores[] scoresArray, MpiSysConfig sysConfig)
        {
            if (scoresArray == null)
            {
                throw new ArgumentNullException("scoresArray");
            }
            if (sysConfig == null)
            {
                throw new ArgumentNullException("sysConfig");
            }
            if (scoresArray.Length < 1)
            {
                throw new ArgumentException("Scores array is empty", "scoresArray");
            }

            IObjectiveScores referenceScore = scoresArray[0];
            int objectiveCount = referenceScore.ObjectiveCount;

            double[] means = new double[objectiveCount];
            for (int objectiveIdx = 0; objectiveIdx < objectiveCount; objectiveIdx++)
            {
                foreach (MpiObjectiveScores objectiveScores in scoresArray)
                {
                    means[objectiveIdx] += (double)objectiveScores.GetObjective(objectiveIdx).ValueComparable;
                }

                means[objectiveIdx] /= scoresArray.Length;
            }
            IObjectiveScore[] meanScores = new IObjectiveScore[objectiveCount];
            for (int i = 0; i < means.Length; i++)
            {
                meanScores[i] = new DoubleObjectiveScore(referenceScore.GetObjective(i).Name, means[i], referenceScore.GetObjective(i).Maximise);
            }

            return(new MpiObjectiveScores(meanScores, sysConfig));
        }
        public static IObjectiveScores <T> CreateSingleObjective <T>(T sysConfig, double result, string scoreName, bool maximise = false) where T : IHyperCube <double>
        {
            var dblScore = new DoubleObjectiveScore(scoreName, result, maximise: maximise);

            return(new MultipleScores <T>(new IObjectiveScore[] { dblScore }, sysConfig));
        }