Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/15/13 13:19:28 (12 years ago)
Author:
mkommend
Message:

#1837: Refactored sliding window analyzers and updated the provided algorithm.

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

Legend:

Unmodified
Added
Removed
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r9126 r9162  
    198198    <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionTreeInterpreter.cs" />
    199199    <Compile Include="Interfaces\ISymbolicDataAnalysisProblem.cs" />
     200    <Compile Include="SlidingWindow\SlidingWindowVisualizer.cs" />
    200201    <Compile Include="SymbolicDataAnalysisModel.cs">
    201202      <SubType>Code</SubType>
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/GenerationalSlidingWindowAnalyzer.cs

    r9145 r9162  
    3030  [Item("Generational Sliding Window GP Analyzer", "Analyzer which moves a sliding window every n-th generation over the training partition.")]
    3131  [StorableClass]
    32   public class GenerationalSlidingWindowAnalyzer<T> : SlidingWindowAnalyzer<T>, IIterationBasedOperator
    33     where T : class, IDataAnalysisProblemData {
     32  public class GenerationalSlidingWindowAnalyzer : SlidingWindowAnalyzer, IIterationBasedOperator {
    3433    private const string GenerationsIntervalParameterName = "Generation Interval";
    3534    private const string GenerationsIntervalStartParameterName = "Generation Interval Start";
     
    6463    [StorableConstructor]
    6564    protected GenerationalSlidingWindowAnalyzer(bool deserializing) : base(deserializing) { }
    66     protected GenerationalSlidingWindowAnalyzer(GenerationalSlidingWindowAnalyzer<T> original, Cloner cloner) : base(original, cloner) { }
     65    protected GenerationalSlidingWindowAnalyzer(GenerationalSlidingWindowAnalyzer original, Cloner cloner) : base(original, cloner) { }
    6766    public override IDeepCloneable Clone(Cloner cloner) {
    68       return new GenerationalSlidingWindowAnalyzer<T>(this, cloner);
     67      return new GenerationalSlidingWindowAnalyzer(this, cloner);
    6968    }
    7069
     
    7473      Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalParameterName, "", new IntValue(5)));
    7574      Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalStartParameterName, "", new IntValue(0)));
     75
     76      IterationsParameter.ActualName = "Generations";
     77      MaximumIterationsParameter.Hidden = true;
    7678    }
    7779
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/OffspringSelectionSlidingWindowAnalyzer.cs

    r9047 r9162  
    2929  [Item("Offspring Selection Sliding Window GP Analyzer", "Analyzer which moves a sliding window whenever the selection pressure exceeds a certain threshold.")]
    3030  [StorableClass]
    31   public class OffspringSelectionSlidingWindowAnalyzer<T> : SlidingWindowAnalyzer<T>
    32     where T : class, IDataAnalysisProblemData {
     31  public class OffspringSelectionSlidingWindowAnalyzer : SlidingWindowAnalyzer {
    3332    private const string SelectionPressureParameterName = "SelectionPressure";
    3433    private const string SelectionPressureThresholdParameterName = "SelectionPressureThreshold";
     
    5251    [StorableConstructor]
    5352    protected OffspringSelectionSlidingWindowAnalyzer(bool deserializing) : base(deserializing) { }
    54     protected OffspringSelectionSlidingWindowAnalyzer(OffspringSelectionSlidingWindowAnalyzer<T> original, Cloner cloner) : base(original, cloner) { }
     53    protected OffspringSelectionSlidingWindowAnalyzer(OffspringSelectionSlidingWindowAnalyzer original, Cloner cloner) : base(original, cloner) { }
    5554    public override IDeepCloneable Clone(Cloner cloner) {
    56       return new OffspringSelectionSlidingWindowAnalyzer<T>(this, cloner);
     55      return new OffspringSelectionSlidingWindowAnalyzer(this, cloner);
    5756    }
    5857
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowAnalyzer.cs

    r9145 r9162  
    2020#endregion
    2121
    22 using System;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    2524using HeuristicLab.Data;
    26 using HeuristicLab.Operators;
    27 using HeuristicLab.Optimization;
    2825using HeuristicLab.Parameters;
    2926using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3229  [StorableClass]
    3330  [Item("Sliding Window GP Analyzer", "Base class for concrete sliding window GP analyzers.")]
    34   public abstract class SlidingWindowAnalyzer<T> : SingleSuccessorOperator, IAnalyzer where T : class,IDataAnalysisProblemData {
     31  public abstract class SlidingWindowAnalyzer : SymbolicDataAnalysisAnalyzer {
    3532    private const string ProblemDataParameterName = "ProblemData";
    36     private const string ResultCollectionParameterName = "Results";
    3733    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
    3834    private const string SlidingWindowSizeParameterName = "Sliding Window Size";
    3935    private const string SlidingWindowStepWidthParameterName = "Sliding Window Step Width";
    4036    private const string InitialSlidingWindowParameterName = "Initial Sliding Window";
    41 
    42     private const string SlidingWindowDataResultName = "Sliding Window";
     37    private const string TerminateSlidingWindowParameterName = "TerminateSlidingWindow";
    4338
    4439    #region parameter properties
    45     public IValueLookupParameter<T> ProblemDataParameter {
    46       get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; }
    47     }
    48     public ILookupParameter<ResultCollection> ResultCollectionParameter {
    49       get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; }
     40    public IValueLookupParameter<IDataAnalysisProblemData> ProblemDataParameter {
     41      get { return (IValueLookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
    5042    }
    5143    public ILookupParameter<IntRange> FitnessCalculationPartitionParameter {
    5244      get { return (ILookupParameter<IntRange>)Parameters[FitnessCalculationPartitionParameterName]; }
    5345    }
    54 
    5546    public IFixedValueParameter<IntValue> SlidingWindowSizeParameter {
    5647      get { return (IFixedValueParameter<IntValue>)Parameters[SlidingWindowSizeParameterName]; }
     
    6051    }
    6152    public IFixedValueParameter<IntRange> InitialSlidingWindowParameter {
    62       get {
    63         return (IFixedValueParameter<IntRange>)Parameters[InitialSlidingWindowParameterName];
    64       }
     53      get { return (IFixedValueParameter<IntRange>)Parameters[InitialSlidingWindowParameterName]; }
     54    }
     55    public ILookupParameter<BoolValue> TerminateSlidingWindowParameter {
     56      get { return (ILookupParameter<BoolValue>)Parameters[TerminateSlidingWindowParameterName]; }
    6557    }
    6658    #endregion
    6759
    6860    #region properties
    69     public bool EnabledByDefault { get { return false; } }
     61    public override bool EnabledByDefault { get { return false; } }
    7062    public IntValue SlidingWindowSize { get { return SlidingWindowSizeParameter.Value; } }
    7163    public IntValue SlidingWindowStepWidth { get { return SlidingWindowStepWidthParameter.Value; } }
     
    7668    [StorableConstructor]
    7769    protected SlidingWindowAnalyzer(bool deserializing) : base(deserializing) { }
    78     protected SlidingWindowAnalyzer(SlidingWindowAnalyzer<T> original, Cloner cloner)
     70    protected SlidingWindowAnalyzer(SlidingWindowAnalyzer original, Cloner cloner)
    7971      : base(original, cloner) { }
    8072
    81     protected SlidingWindowAnalyzer() {
    82       Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName, "The result collection to store the analysis results."));
    83       Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
     73    protected SlidingWindowAnalyzer()
     74      : base() {
     75      Parameters.Add(new ValueLookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
    8476      Parameters.Add(new LookupParameter<IntRange>(FitnessCalculationPartitionParameterName, ""));
    8577      Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowSizeParameterName, "", new IntValue(1)));
    8678      Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowStepWidthParameterName, "", new IntValue(1)));
    8779      Parameters.Add(new FixedValueParameter<IntRange>(InitialSlidingWindowParameterName, "", new IntRange(0, 1)));
     80      Parameters.Add(new LookupParameter<BoolValue>(TerminateSlidingWindowParameterName, ""));
    8881
    89       FitnessCalculationPartitionParameter.ActualName = "Sliding Window";
     82      ProblemDataParameter.Hidden = true;
    9083    }
    9184
    9285    public override IOperation Apply() {
     86      //intialize sliding window
    9387      if (FitnessCalculationPartitionParameter.ActualValue == null) {
     88        TerminateSlidingWindowParameter.ActualValue = new BoolValue(false);
    9489        FitnessCalculationPartitionParameter.ActualValue = (IntRange)InitialSlidingWindow.Clone();
    95       } else if (CheckForUpdate()) {
    96         var fitnessPartition = FitnessCalculationPartitionParameter.ActualValue;
    97         if (fitnessPartition.End - fitnessPartition.Start == SlidingWindowSize.Value)
    98           fitnessPartition.Start += SlidingWindowStepWidth.Value;
    99 
    100         fitnessPartition.End += SlidingWindowStepWidth.Value;
    101         if (fitnessPartition.End - fitnessPartition.Start > SlidingWindowSize.Value)
    102           fitnessPartition.End = fitnessPartition.Start + SlidingWindowSize.Value;
    103 
    104         //TODO check if fitnesspartition exceeds training partition
     90        return base.Apply();
    10591      }
    10692
    107       //create and update result
    108       var results = ResultCollectionParameter.ActualValue;
    109       SlidingWindowData slidingWindowData;
    110       if (!results.ContainsKey(SlidingWindowDataResultName)) {
    111         string targetVariable;
    112         var classificationProblemData = ProblemDataParameter.ActualValue as IClassificationProblemData;
    113         var regressionProblemData = ProblemDataParameter.ActualValue as IRegressionProblemData;
    114         if (classificationProblemData != null) targetVariable = classificationProblemData.TargetVariable;
    115         else if (regressionProblemData != null) targetVariable = regressionProblemData.TargetVariable;
    116         else throw new NotSupportedException();
     93      if (!CheckForUpdate()) return base.Apply();
    11794
    118         var targetData = ProblemDataParameter.ActualValue.Dataset.GetDoubleValues(targetVariable);
    119         slidingWindowData = new SlidingWindowData(FitnessCalculationPartitionParameter.ActualValue, targetData);
    120         results.Add(new Result(SlidingWindowDataResultName, slidingWindowData));
    121       } else slidingWindowData = (SlidingWindowData)results[SlidingWindowDataResultName].Value;
     95      //update necessary - move sliding window
     96      var fitnessPartition = (IntRange)FitnessCalculationPartitionParameter.ActualValue.Clone();
     97      if (fitnessPartition.End - fitnessPartition.Start == SlidingWindowSize.Value)
     98        fitnessPartition.Start += SlidingWindowStepWidth.Value;
    12299
    123       slidingWindowData.SlidingWindowPosition.Start = FitnessCalculationPartitionParameter.ActualValue.Start;
    124       slidingWindowData.SlidingWindowPosition.End = FitnessCalculationPartitionParameter.ActualValue.End;
     100      fitnessPartition.End += SlidingWindowStepWidth.Value;
     101      if (fitnessPartition.End - fitnessPartition.Start > SlidingWindowSize.Value)
     102        fitnessPartition.End = fitnessPartition.Start + SlidingWindowSize.Value;
     103
     104      //check if update should be performed or if the algorithm should stop
     105      if (fitnessPartition.End > ProblemDataParameter.ActualValue.TrainingPartition.End)
     106        TerminateSlidingWindowParameter.ActualValue.Value = true;
     107      else {
     108        FitnessCalculationPartitionParameter.ActualValue.Start = fitnessPartition.Start;
     109        FitnessCalculationPartitionParameter.ActualValue.End = fitnessPartition.End;
     110      }
    125111
    126112      return base.Apply();
    127113    }
    128114
    129 
    130115    protected abstract bool CheckForUpdate();
    131116  }
  • branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowData.cs

    r7845 r9162  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    30   [Item("Sliding Window Position", "TODO")]
    31   public class SlidingWindowData : Item {
     31  [StorableClass]
     32  [Item("Sliding Window Position", "")]
     33  public sealed class SlidingWindowData : Item {
    3234
    3335    [Storable]
     
    4345    }
    4446
    45     protected SlidingWindowData(bool deserializing) : base(deserializing) { }
    46     protected SlidingWindowData(SlidingWindowData original, Cloner cloner)
     47    [Storable]
     48    private IEnumerable<double> estimatedValues;
     49    public IEnumerable<double> EstimatedValues {
     50      get { return estimatedValues; }
     51      set {
     52        if (value == null) throw new ArgumentNullException();
     53        estimatedValues = value.ToArray();
     54        OnEstimatedValuesChanged();
     55      }
     56    }
     57
     58    [StorableConstructor]
     59    private SlidingWindowData(bool deserializing) : base(deserializing) { }
     60    private SlidingWindowData(SlidingWindowData original, Cloner cloner)
    4761      : base(original, cloner) {
    4862      slidingWindowPosition = cloner.Clone(original.slidingWindowPosition);
     
    5872      this.targetValues = targetValues.ToArray();
    5973    }
     74
     75    public event EventHandler EstimatedValuesChanged;
     76    private void OnEstimatedValuesChanged() {
     77      var handler = EstimatedValuesChanged;
     78      if (handler != null) EstimatedValuesChanged(this, EventArgs.Empty);
     79    }
    6080  }
    6181}
Note: See TracChangeset for help on using the changeset viewer.