Esempio n. 1
0
 public void CopyFrom(AllScores other)
 {
     ExpectedTurnsToWin = other.ExpectedTurnsToWin;
     WpTire             = other.WpTire;
     WpBreaks           = other.WpBreaks;
     WpEngine           = other.WpEngine;
     WpGear             = other.WpGear;
 }
        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));
        }
Esempio n. 3
0
 static void SaveScoresToDisk()
 {
     if (_scores != null)
     {
         var all_scores = new AllScores {
             scores = _scores
         };
         SaveJson(FileName, all_scores);
     }
 }
        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. 5
0
    public void LoadScores()
    {
        Debug.Log(Application.persistentDataPath);
        // Read the json from the file into a string

        if (File.Exists(Application.persistentDataPath + "/scores.json"))
        {
            string dataAsJson = File.ReadAllText(Application.persistentDataPath + "/scores.json");
            allScores = JsonUtility.FromJson <AllScores>(dataAsJson);
        }
        else
        {
            string dataToJson = JsonUtility.ToJson(allScores);
            File.WriteAllText(Application.persistentDataPath + "/scores.json", dataToJson);
        }
    }
Esempio n. 6
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);
 }