Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/26/14 01:42:09 (11 years ago)
Author:
bburlacu
Message:

#1837: Introduced the SlidingWindowBestSolutionsCollectionView which shows how well each individual sliding window solution performs on the other portions of the training data.

Location:
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs

    r10373 r10396  
    8888    protected BoolValue PruneOnlyZeroImpactNodes { get { return PruneOnlyZeroImpactNodesParameter.Value; } }
    8989    #endregion
     90
     91    [StorableConstructor]
     92    protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer(bool deserializing) : base(deserializing) { }
    9093    protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer(SymbolicDataAnalysisSingleObjectivePruningAnalyzer original, Cloner cloner)
    9194      : base(original, cloner) {
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r10373 r10396  
    158158    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" />
    159159    <Compile Include="SlidingWindow\OffspringSelectionSlidingWindowAnalyzer.cs" />
     160    <Compile Include="SlidingWindow\SlidingWindowBestSolutionsCollection.cs">
     161      <SubType>Code</SubType>
     162    </Compile>
    160163    <Compile Include="SlidingWindow\SlidingWindowData.cs" />
    161164    <Compile Include="SlidingWindow\GenerationalSlidingWindowAnalyzer.cs" />
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowAnalyzer.cs

    r9707 r10396  
    2020#endregion
    2121
     22using System;
     23using System.Linq;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
    2426using HeuristicLab.Data;
     27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2528using HeuristicLab.Operators;
    2629using HeuristicLab.Optimization;
     
    3134  [StorableClass]
    3235  [Item("Sliding Window GP Analyzer", "Base class for concrete sliding window GP analyzers.")]
    33   public abstract class SlidingWindowAnalyzer : SymbolicDataAnalysisAnalyzer {
     36  public abstract class SlidingWindowAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer {
    3437    private const string ProblemDataParameterName = "ProblemData";
    3538    private const string EvaluatorParameterName = "Evaluator";
     
    4144    private const string InitialSlidingWindowParameterName = "Initial Sliding Window";
    4245    private const string TerminateSlidingWindowParameterName = "TerminateSlidingWindow";
     46    private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    4347
    4448    #region parameter properties
     49    private ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter {
     50      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; }
     51    }
    4552    public IValueLookupParameter<IDataAnalysisProblemData> ProblemDataParameter {
    4653      get { return (IValueLookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
     
    7582    public override bool EnabledByDefault { get { return false; } }
    7683    public IntValue SlidingWindowSize { get { return SlidingWindowSizeParameter.Value; } }
    77     public IntValue ValidiationSlidingWindowSize { get { return ValidationSlidingWindowSizeParameter.Value; } }
     84    public IntValue ValidationSlidingWindowSize { get { return ValidationSlidingWindowSizeParameter.Value; } }
    7885    public IntValue SlidingWindowStepWidth { get { return SlidingWindowStepWidthParameter.Value; } }
    7986    public IntRange InitialSlidingWindow { get { return InitialSlidingWindowParameter.Value; } }
     87    public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get { return InterpreterParameter.ActualValue; } }
     88    public IDataAnalysisProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } }
    8089    #endregion
    81 
    8290
    8391    [StorableConstructor]
     
    97105      Parameters.Add(new FixedValueParameter<IntRange>(InitialSlidingWindowParameterName, "", new IntRange(0, 1)));
    98106      Parameters.Add(new LookupParameter<BoolValue>(TerminateSlidingWindowParameterName, ""));
     107      if (!Parameters.ContainsKey(InterpreterParameterName))
     108        Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(InterpreterParameterName, ""));
     109      if (!Parameters.ContainsKey("Quality"))
     110        Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", ""));
     111      if (!Parameters.ContainsKey("Maximization"))
     112        Parameters.Add(new LookupParameter<BoolValue>("Maximization", "The direction of optimization."));
     113      ProblemDataParameter.Hidden = true;
    99114
    100       ProblemDataParameter.Hidden = true;
    101115    }
    102116
     
    105119      if (!Parameters.ContainsKey(EvaluatorParameterName))
    106120        Parameters.Add(new LookupParameter<IEvaluator>(EvaluatorParameterName, ""));
     121      if (!Parameters.ContainsKey(InterpreterParameterName))
     122        Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(InterpreterParameterName, ""));
     123      if (!Parameters.ContainsKey("Quality"))
     124        Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", ""));
     125      if (!Parameters.ContainsKey("Maximization"))
     126        Parameters.Add(new LookupParameter<BoolValue>("Maximization", "The direction of optimization."));
     127      if (!Parameters.ContainsKey(ProblemDataParameterName))
     128        Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName));
    107129    }
    108130
     
    112134        TerminateSlidingWindowParameter.ActualValue = new BoolValue(false);
    113135        FitnessCalculationPartitionParameter.ActualValue = (IntRange)InitialSlidingWindow.Clone();
    114         ValidationPartitionParameter.ActualValue = new IntRange(InitialSlidingWindow.End, InitialSlidingWindow.End + ValidiationSlidingWindowSize.Value);
     136        ValidationPartitionParameter.ActualValue = new IntRange(InitialSlidingWindow.End, InitialSlidingWindow.End + ValidationSlidingWindowSize.Value);
    115137        return base.Apply();
    116138      }
    117139
    118140      if (!CheckForUpdate()) return base.Apply();
     141
     142      SaveBestSolution();
    119143
    120144      //update necessary - move sliding window
     
    136160      FitnessCalculationPartitionParameter.ActualValue.End = fitnessPartition.End;
    137161      ValidationPartitionParameter.ActualValue.Start = fitnessPartition.End;
    138       ValidationPartitionParameter.ActualValue.End = ValidationPartitionParameter.ActualValue.Start + ValidiationSlidingWindowSize.Value;
     162      ValidationPartitionParameter.ActualValue.End = ValidationPartitionParameter.ActualValue.Start + ValidationSlidingWindowSize.Value;
    139163
    140164      //reevaluate all individuals with new sliding window
     
    147171    }
    148172
     173    private ISymbolicExpressionTree FindBestIndividual() {
     174      var pop = SymbolicExpressionTree.Zip(Quality, (t, q) => new { Tree = t, Quality = q.Value }).ToList();
     175      Func<double, double, int> comparer = (a, b) => Maximization.Value ? a.CompareTo(b) : b.CompareTo(a);
     176      pop.Sort((a, b) => comparer(a.Quality, b.Quality));
     177      return pop.Last().Tree;
     178    }
     179
     180    private void SaveBestSolution() {
     181      var bestSolutionsCollection = (SlidingWindowBestSolutionsCollection)ResultCollection["Best Solutions"].Value;
     182
     183      if (bestSolutionsCollection.ProblemData == null)
     184        bestSolutionsCollection.ProblemData = ProblemData;
     185
     186      if (bestSolutionsCollection.Interpreter == null)
     187        bestSolutionsCollection.Interpreter = Interpreter;
     188
     189      var fitnessPartition = FitnessCalculationPartitionParameter.ActualValue;
     190      var best = FindBestIndividual();
     191      var range = new IntRange(fitnessPartition.Start, fitnessPartition.End);
     192
     193      bestSolutionsCollection.Add(best, range);
     194    }
     195
    149196    protected abstract bool CheckForUpdate();
    150197  }
Note: See TracChangeset for help on using the changeset viewer.