Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14543


Ignore:
Timestamp:
01/04/17 18:38:52 (8 years ago)
Author:
jzenisek
Message:

#2719 enhanced Optimizer functionality; added results

Location:
branches/HeuristicLab.DatastreamAnalysis
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis.Views/3.4/Plugin.cs

    r14538 r14543  
    2323
    2424namespace HeuristicLab.DatastreamAnalysis.Views {
    25   [Plugin("HeuristicLab.DatastreamAnalysis.Views", "3.4.14.14536")]
     25  [Plugin("HeuristicLab.DatastreamAnalysis.Views", "3.4.14.14538")]
    2626  [PluginFile("HeuristicLab.DatastreamAnalysis.Views-3.4.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Collections", "3.3")]
  • branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis.Views/3.4/Properties/AssemblyInfo.cs

    r14538 r14543  
    5454// [assembly: AssemblyVersion("1.0.*")]
    5555[assembly: AssemblyVersion("3.4.0.0")]
    56 [assembly: AssemblyFileVersion("3.4.14.14536")]
     56[assembly: AssemblyFileVersion("3.4.14.14538")]
  • branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/Datastream.cs

    r14538 r14543  
    181181    public Datastream() : base() {
    182182      Parameters.Add(new ValueParameter<RegressionProblemData>(ProblemDataParameterName, "ProblemData for analysis with selected ensembles.", null));
    183       Parameters.Add(new FixedValueParameter<IntRange>(InitialSlidingWindowParameterName, "Initial sliding window boundaries", new IntRange(0, 5)));
    184       Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowSizeParameterName, "Sliding window size", new IntValue(5)));
     183      Parameters.Add(new FixedValueParameter<IntRange>(InitialSlidingWindowParameterName, "Initial sliding window boundaries", new IntRange(0, 20)));
     184      Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowSizeParameterName, "Sliding window size", new IntValue(20)));
    185185      Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowStepWidthParameterName, "Sliding window step width", new IntValue(1)));
    186       Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowMovementIntervalParameterName, "Sliding window movement interval (milliseconds)", new IntValue(2000)));
     186      Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowMovementIntervalParameterName, "Sliding window movement interval (milliseconds)", new IntValue(500)));
    187187      RegisterParameterEvents();
    188188      InitializeState();
  • branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/DatastreamAnalysisOptimizer.cs

    r14538 r14543  
    144144      set { ((IntValue)Results["Sliding Window Movements"].Value).Value = value; }
    145145    }
    146     private double ResultsBestQuality {
    147       get { return ((DoubleValue)Results["Best Quality"].Value).Value; }
    148       set { ((DoubleValue)Results["Best Quality"].Value).Value = value; }
    149     }
    150146    private DataTable ResultsQualities {
    151147      get { return ((DataTable)Results["Qualities"].Value); }
    152148    }
    153149
    154     private const string ResultsQualitiesR2 = "R²";
    155     private const string ResultsQualitiesPearson = "Pearson";
     150    private const string ResultsQualitiesMSE = "Mean squared error";
     151    private const string ResultsQualitiesPR2 = "Pearson R²";
    156152
    157153    private DataTable ResultsTargets {
     
    161157    private const string ResultsTargetsReal = "Real";
    162158
     159    private DataTable ResultsQualitiesBars {
     160      get { return ((DataTable) Results["Ensembles"].Value); }
     161    }
     162
    163163    protected void SetupResults() {
    164164      Results.Clear();
    165165
    166166      Results.Add(new Result("Sliding Window Movements", new IntValue(0)));
    167       Results.Add(new Result("Best Quality", new DoubleValue(0)));
    168167      Results.Add(new Result("Qualities", new DataTable("Qualities")));
    169168      Results.Add(new Result("Targets", new DataTable("Targets")));
    170169
    171       ResultsQualities.Rows.Add(new DataRow(ResultsQualitiesR2));
    172       ResultsQualities.Rows.Add(new DataRow(ResultsQualitiesPearson));
     170      ResultsQualitiesBars.Rows.Add(new DataRow("Ensembles"));
     171
    173172      ResultsTargets.Rows.Add(new DataRow(ResultsTargetsReal));
    174173      foreach (var ensemble in Ensembles) {
     174        // targets table
    175175        ResultsTargets.Rows.Add(new DataRow(ensemble.Name));
     176
     177        // qualities (series)
     178        //ResultsQualities.Rows.Add(new DataRow(ensemble.Name + " - " + ResultsQualitiesMSE));
     179        ResultsQualities.Rows.Add(new DataRow(ensemble.Name + " - " + ResultsQualitiesPR2));
     180
     181        // qualities (bars)
     182        //ResultsQualitiesBars.Rows.Add(new DataRow(ensemble.Name + " - " + ResultsQualitiesPR2));
     183        //ResultsQualitiesBars.Rows["Ensembles"].Values.
    176184      }
    177185    }
     
    180188
    181189    #region constructors, cloner,...
    182 
    183190    public DatastreamAnalysisOptimizer() : base() {
    184191      name = "Datastream Analysis";
     
    248255      if (prepared) {
    249256        SetupResults();
    250         //prepared = false;
     257        Datastream.InitializeState();
    251258      }
    252259
     
    273280          OnPaused();
    274281        }
    275         //if(!Datastream.SlidingWindowMovementPossible) OnStopped();
    276         //else OnPaused();
    277282      });
    278 
    279283    }
    280284
     
    361365
    362366    protected void Run(CancellationToken cancellationToken) {
    363       // init algorithm
    364       var problemData = Datastream.ProblemData;
    365       var targetVarName = problemData.TargetVariable;
    366       var activeVariables = problemData.AllowedInputVariables;
    367367
    368368      if (prepared) {
    369         // replay datastream until FitnessPartition.End
    370         //for (int i = 0; i < Datastream.FitnessPartition.End; i++) {
    371         //  var val = problemData.Dataset.GetDoubleValue(targetVarName, i);
    372         //  ResultsTargets.Rows[ResultsTargetsReal].Values.Add(val);
    373         //}
    374         //replayedIndex = Datastream.FitnessPartition.End;
    375369        replayedIndex = 0;
    376370        prepared = false;
    377371      }
    378372
    379 
    380       Random rnd = new Random();
    381 
    382373      try {
     374
     375        // play and evaluate initial window
     376        PlayDatastream();
     377        if(Datastream.SlidingWindowEvaluationPossible) Evaluate();
     378        replayedIndex = Datastream.FitnessPartition.End;
     379
    383380        do {
    384           do {
     381          while(Datastream.SlidingWindowMovementPossible) {
    385382            cancellationToken.ThrowIfCancellationRequested();
    386383
     384            // perform (delayed) window movement
    387385            Thread.Sleep(Datastream.SlidingWindowMovementInterval.Value);
    388386            Datastream.MoveSlidingWindow();
    389 
    390             if (Datastream.SlidingWindowEvaluationPossible) {
    391               foreach (var ensemble in Ensembles) {
    392                 // TODO do the window evaluation
    393                 double estimatedVal = problemData.Dataset.GetDoubleValue(targetVarName, replayedIndex)
    394                                       * (1.0 + (((double)rnd.Next(0, 30)) / 100));
    395                 for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) {
    396                   ResultsTargets.Rows[ensemble.Name].Values.Add(estimatedVal);
    397                 }
    398               }
    399             }
    400 
    401             // replay datastream until FitnessPartition.End
    402             for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) {
    403               var val = problemData.Dataset.GetDoubleValue(targetVarName, i);
    404               ResultsTargets.Rows[ResultsTargetsReal].Values.Add(val);
    405             }
     387            ResultsSlidingWindowMovements++;
     388
     389            // play and evaluate the moved window
     390            PlayDatastream();
     391            if (Datastream.SlidingWindowEvaluationPossible) Evaluate();
    406392            replayedIndex = Datastream.FitnessPartition.End;
    407 
    408 
    409             // TODO: collect results and display them
    410 
    411             int exp = rnd.Next(100);
    412             ResultsQualities.Rows[ResultsQualitiesR2].Values.Add(exp);
    413             ResultsQualities.Rows[ResultsQualitiesPearson].Values.Add((double)exp / 10);
    414             ResultsSlidingWindowMovements++;
    415             ResultsBestQuality = (double)exp / 42;
    416 
    417           } while (Datastream.SlidingWindowMovementPossible);
     393          }
    418394        } while (Datastream.UpdateAvailable);
    419395        finished = true;
     
    426402        // reset everything
    427403        //Prepare(true);
     404      }
     405    }
     406
     407    private void PlayDatastream() {
     408      var problemData = Datastream.ProblemData;
     409      var targetVarName = problemData.TargetVariable;
     410
     411      for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) {
     412        var realValue = problemData.Dataset.GetDoubleValue(targetVarName, i);
     413        ResultsTargets.Rows[ResultsTargetsReal].Values.Add(realValue);
     414      }
     415    }
     416
     417    private void Evaluate() {
     418      var problemData = Datastream.ProblemData;
     419      var dataset = problemData.Dataset;
     420      var targetVarName = problemData.TargetVariable;
     421
     422      var realRows = Enumerable.Range(Datastream.FitnessPartition.Start, Datastream.FitnessPartition.Size).ToList();
     423      var realValues = dataset.GetDoubleValues(targetVarName, realRows);
     424
     425      foreach (var ensemble in Ensembles) {
     426
     427        var rows = Enumerable.Range(Datastream.FitnessPartition.Start, Datastream.FitnessPartition.Size);
     428        var estimatedValuesPerModelPerRow = ensemble.Models.Select(x => x.GetEstimatedValues(datastream.ProblemData.Dataset, rows).ToArray());
     429        var estimatedValues = Enumerable.Range(0, Datastream.FitnessPartition.Size).Select(r => estimatedValuesPerModelPerRow.Select(e => e[r]).Average()).ToArray(); // per row
     430        var averageEstimatedValuesPerModel = estimatedValuesPerModelPerRow.Select(x => x.Average()); // per model
     431        var averageEstimatedValue = averageEstimatedValuesPerModel.Average();
     432
     433        // determine quality
     434        var mse = Math.Pow(averageEstimatedValue - realValues.Average(), 2);
     435        OnlineCalculatorError error;
     436        var pR = OnlinePearsonsRCalculator.Calculate(estimatedValues, realValues, out error);
     437        var pR2 = error == OnlineCalculatorError.None ? pR * pR : 0.0;
     438
     439        DataRow qualitiesBarsRow = ResultsQualitiesBars.Rows[ensemble.Name + " - " + ResultsQualitiesPR2];
     440
     441        for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) {
     442          ResultsTargets.Rows[ensemble.Name].Values.Add(averageEstimatedValue);
     443
     444          //ResultsQualities.Rows[ensemble.Name + " - " + ResultsQualitiesMSE].Values.Add(mse);
     445          ResultsQualities.Rows[ensemble.Name + " - " + ResultsQualitiesPR2].Values.Add(pR2);
     446        }
    428447      }
    429448    }
  • branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/Plugin.cs

    r14538 r14543  
    2323
    2424namespace HeuristicLab.DatastreamAnalysis {
    25   [Plugin("HeuristicLab.DatastreamAnalysis", "3.4.14.14536")]
     25  [Plugin("HeuristicLab.DatastreamAnalysis", "3.4.14.14538")]
    2626  [PluginFile("HeuristicLab.DatastreamAnalysis-3.4.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Collections", "3.3")]
  • branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/Properties/AssemblyInfo.cs

    r14538 r14543  
    5454// [assembly: AssemblyVersion("1.0.*")]
    5555[assembly: AssemblyVersion("3.4.0.0")]
    56 [assembly: AssemblyFileVersion("3.4.14.14536")]
     56[assembly: AssemblyFileVersion("3.4.14.14538")]
Note: See TracChangeset for help on using the changeset viewer.