Example #1
0
 public EpisodeStats(EpisodesData episode)
 {
     foreach (StepData step in episode.steps)
     {
         double current_E_p = Math.Abs(step.data[4]);
         E_p += current_E_p;
         if (current_E_p > max_E_p)
         {
             max_E_p = current_E_p;
         }
         if (current_E_p < min_E_p)
         {
             min_E_p = current_E_p;
         }
         double current_r = step.data[19];
         r += current_r;
         if (current_r > max_r)
         {
             max_r = current_r;
         }
         if (current_r < min_r)
         {
             min_r = current_r;
         }
         double ratio    = (-current_r + 1) / current_E_p;
         double shouldBe = (1 - (current_E_p / 1000));
         if (Math.Abs(current_r - shouldBe) > 0.001)
         {
             Console.WriteLine("Reward discrepancy: " + (current_r - shouldBe));
         }
     }
     E_p /= episode.steps.Count;
     r   /= episode.steps.Count;
 }
Example #2
0
            /// <summary>
            /// Read the binary log file. To know whether the log information has been succesfully loaded
            /// or not, BinFileLoadSuccess can be checked after calling this method.
            /// </summary>
            /// <returns></returns>
            public bool LoadBinaryLog(string LogFileName)
            {
                try
                {
                    using (FileStream logFile = File.OpenRead(LogFileName))
                    {
                        using (BinaryReader binaryReader = new BinaryReader(logFile))
                        {
                            ReadExperimentLogHeader(binaryReader);
                            Episodes = new EpisodesData[TotalNumEpisodes];

                            for (int i = 0; i < TotalNumEpisodes; i++)
                            {
                                Episodes[i] = new EpisodesData();
                                EpisodesData episodeData = Episodes[i];

                                episodeData.ReadEpisodeHeader(binaryReader);
                                //if we find an episode subindex greater than the current max, we update it
                                //Episode subindex= Episode within an evaluation
                                if (episodeData.subIndex > NumEpisodesPerEvaluation)
                                {
                                    NumEpisodesPerEvaluation = episodeData.subIndex;
                                }

                                //count evaluation and training episodes
                                if (episodeData.type == 0)
                                {
                                    EvaluationEpisodes.Add(episodeData);
                                }
                                else
                                {
                                    TrainingEpisodes.Add(episodeData);
                                }

                                StepData stepData  = new StepData();
                                bool     bLastStep = stepData.readStep(binaryReader, episodeData.numVariablesLogged);

                                while (!bLastStep)
                                {
                                    //we only add the step if it's not the last one
                                    //last steps don't contain any info but the end marker
                                    episodeData.steps.Add(stepData);

                                    stepData  = new StepData();
                                    bLastStep = stepData.readStep(binaryReader, episodeData.numVariablesLogged);
                                }
                            }
                            SuccessfulLoad = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    SuccessfulLoad = false;
                }
                return(SuccessfulLoad);
            }