public override double Evaluate(IChromosome chromosome)
        {
            foreach (var item in _calculator.Calculate(Config))
            {
                var inSampleConfig = ((OptimizerConfiguration)Config).Clone();
                inSampleConfig.StartDate = item.Value[0];
                inSampleConfig.EndDate   = item.Value[1];
                var inSampleOptimizer = SharpeMaximizerFactory.Create(inSampleConfig, Filter);
                inSampleOptimizer.Evaluate(chromosome);
                Best       = inSampleOptimizer.Best;
                chromosome = Best;

                //keep best to pass into out sample and next fold
                foreach (var actual in ((Chromosome)Best).ToDictionary())
                {
                    var bestActual = Config.Genes.Single(g => g.Key == actual.Key);
                    if (actual.Value.GetType() == typeof(double))
                    {
                        bestActual.Actual = (double)actual.Value;
                    }
                    else
                    {
                        bestActual.Actual = (int)actual.Value;
                    }
                }

                var list = ((Chromosome)Best).ToDictionary();
                AllBest.Add(list);
                var id = Guid.NewGuid().ToString("N");
                list.Add("Id", id);

                var outSampleConfig = ((OptimizerConfiguration)Config).Clone();
                outSampleConfig.StartDate = item.Value[2];
                outSampleConfig.EndDate   = item.Value[3];

                lock (Locker)
                {
                    HasRunActual = false;
                }
                var score = this.GetScore(list, outSampleConfig);

                var fitness = CalculateFitness(score);

                AllScores.Add(fitness);

                var output = new StringBuilder();
                output.Append("Id: " + id + ", ");
                output.Append(((Chromosome)Best).ToKeyValueString());
                output.Append(", ");
                output.AppendFormat("Start: {0}, End: {1}, ", outSampleConfig.StartDate, outSampleConfig.EndDate);
                output.AppendFormat("{0}: {1}", Name, fitness.Value.ToString("0.##"));
                LogProvider.GenerationsLogger.Info(output);
            }

            Best.Fitness = (double)AllScores.Average(a => a.Fitness);

            return((double)AllScores.Average(a => a.Value));
        }
        public void AddThisScoreToScoreDistribution(double score)
        {
            // creates a distribution of scores for this PSM
            int roundScore = (int)Math.Floor(score);

            while (AllScores.Count <= roundScore)
            {
                AllScores.Add(0);
            }
            AllScores[roundScore]++;
        }
Esempio n. 3
0
 /// <summary>
 /// Adds a new score to the set.
 /// </summary>
 /// <param name="s">The score to add.</param>
 public void Add(Score s)
 {
     AllScores.Add(s);
     FilterScores(s.GameplayDifficulty).Add(s);
 }