internal TrainerResult(ActionScore[] progressivePrediction, int[] observedActions, float[] observedProbabilities) { if (progressivePrediction == null) throw new ArgumentNullException(nameof(progressivePrediction)); if (observedActions == null) throw new ArgumentNullException(nameof(observedActions)); if (observedProbabilities == null) throw new ArgumentNullException(nameof(observedProbabilities)); if (observedActions.Length != observedProbabilities.Length) throw new ArgumentException($"Actions (length: {observedActions.Length}) and probabilities (length: {observedProbabilities.Length}) must be of equal length"); this.ProgressiveRanking = progressivePrediction.Select(a => (int)a.Action).ToArray(); var probabilitiesOrderedByRanking = progressivePrediction.Select(a => a.Score).ToArray(); this.ProgressiveProbabilities = new float[probabilitiesOrderedByRanking.Length]; for (int i = 0; i < probabilitiesOrderedByRanking.Length; i++) this.ProgressiveProbabilities[ProgressiveRanking[i]] = probabilitiesOrderedByRanking[i]; // Ranking is 0-based this.ObservedRanking = observedActions; this.ObservedProbabilities = new float[observedProbabilities.Length]; for (int i = 0; i < observedActions.Length; i++) this.ObservedProbabilities[observedActions[i] - 1] = observedProbabilities[i]; }
private void AssertAreEqual(ActionScore[] expected, ActionScore[] actual) { Assert.AreEqual(expected.Length, actual.Length); for (int i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i].Action, actual[i].Action); Assert.AreEqual(expected[i].Score, actual[i].Score, 0.0001); } CollectionAssert.AreEqual( expected: Enumerable.Range(0, expected.Length).Select(i => (uint)i).ToList(), actual: actual.Select(a => a.Action).OrderBy(a => a).ToList()); }