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)); } }
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)); }
private static int CompareObjectiveScore(T x, T y, int i) { IObjectiveScore xScore = x.GetObjective(i); IObjectiveScore yScore = y.GetObjective(i); int comparison = xScore.ValueComparable.CompareTo(yScore.ValueComparable); if (xScore.Maximise) { comparison = -comparison; } return(comparison); }
/// <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("***********"); }
public int Compare(T x, T y) { if (x.ObjectiveCount != 1 || y.ObjectiveCount != 1) { throw new ArgumentException("This comparer works only for single objective scores"); } IObjectiveScore xScore = x.GetObjective(0); IObjectiveScore yScore = y.GetObjective(0); int comparison = xScore.ValueComparable.CompareTo(yScore.ValueComparable); if (xScore.Maximise) { comparison = -comparison; } return(comparison); }
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); }
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 SingleScore(IObjectiveScore score, TSysConfig sysConfig) : base(new[] { score }, sysConfig) { }