- Timestamp:
- 01/15/13 13:19:28 (12 years ago)
- 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 198 198 <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionTreeInterpreter.cs" /> 199 199 <Compile Include="Interfaces\ISymbolicDataAnalysisProblem.cs" /> 200 <Compile Include="SlidingWindow\SlidingWindowVisualizer.cs" /> 200 201 <Compile Include="SymbolicDataAnalysisModel.cs"> 201 202 <SubType>Code</SubType> -
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/GenerationalSlidingWindowAnalyzer.cs
r9145 r9162 30 30 [Item("Generational Sliding Window GP Analyzer", "Analyzer which moves a sliding window every n-th generation over the training partition.")] 31 31 [StorableClass] 32 public class GenerationalSlidingWindowAnalyzer<T> : SlidingWindowAnalyzer<T>, IIterationBasedOperator 33 where T : class, IDataAnalysisProblemData { 32 public class GenerationalSlidingWindowAnalyzer : SlidingWindowAnalyzer, IIterationBasedOperator { 34 33 private const string GenerationsIntervalParameterName = "Generation Interval"; 35 34 private const string GenerationsIntervalStartParameterName = "Generation Interval Start"; … … 64 63 [StorableConstructor] 65 64 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) { } 67 66 public override IDeepCloneable Clone(Cloner cloner) { 68 return new GenerationalSlidingWindowAnalyzer <T>(this, cloner);67 return new GenerationalSlidingWindowAnalyzer(this, cloner); 69 68 } 70 69 … … 74 73 Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalParameterName, "", new IntValue(5))); 75 74 Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalStartParameterName, "", new IntValue(0))); 75 76 IterationsParameter.ActualName = "Generations"; 77 MaximumIterationsParameter.Hidden = true; 76 78 } 77 79 -
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/OffspringSelectionSlidingWindowAnalyzer.cs
r9047 r9162 29 29 [Item("Offspring Selection Sliding Window GP Analyzer", "Analyzer which moves a sliding window whenever the selection pressure exceeds a certain threshold.")] 30 30 [StorableClass] 31 public class OffspringSelectionSlidingWindowAnalyzer<T> : SlidingWindowAnalyzer<T> 32 where T : class, IDataAnalysisProblemData { 31 public class OffspringSelectionSlidingWindowAnalyzer : SlidingWindowAnalyzer { 33 32 private const string SelectionPressureParameterName = "SelectionPressure"; 34 33 private const string SelectionPressureThresholdParameterName = "SelectionPressureThreshold"; … … 52 51 [StorableConstructor] 53 52 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) { } 55 54 public override IDeepCloneable Clone(Cloner cloner) { 56 return new OffspringSelectionSlidingWindowAnalyzer <T>(this, cloner);55 return new OffspringSelectionSlidingWindowAnalyzer(this, cloner); 57 56 } 58 57 -
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowAnalyzer.cs
r9145 r9162 20 20 #endregion 21 21 22 using System;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 25 24 using HeuristicLab.Data; 26 using HeuristicLab.Operators;27 using HeuristicLab.Optimization;28 25 using HeuristicLab.Parameters; 29 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 32 29 [StorableClass] 33 30 [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 { 35 32 private const string ProblemDataParameterName = "ProblemData"; 36 private const string ResultCollectionParameterName = "Results";37 33 private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition"; 38 34 private const string SlidingWindowSizeParameterName = "Sliding Window Size"; 39 35 private const string SlidingWindowStepWidthParameterName = "Sliding Window Step Width"; 40 36 private const string InitialSlidingWindowParameterName = "Initial Sliding Window"; 41 42 private const string SlidingWindowDataResultName = "Sliding Window"; 37 private const string TerminateSlidingWindowParameterName = "TerminateSlidingWindow"; 43 38 44 39 #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]; } 50 42 } 51 43 public ILookupParameter<IntRange> FitnessCalculationPartitionParameter { 52 44 get { return (ILookupParameter<IntRange>)Parameters[FitnessCalculationPartitionParameterName]; } 53 45 } 54 55 46 public IFixedValueParameter<IntValue> SlidingWindowSizeParameter { 56 47 get { return (IFixedValueParameter<IntValue>)Parameters[SlidingWindowSizeParameterName]; } … … 60 51 } 61 52 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]; } 65 57 } 66 58 #endregion 67 59 68 60 #region properties 69 public bool EnabledByDefault { get { return false; } }61 public override bool EnabledByDefault { get { return false; } } 70 62 public IntValue SlidingWindowSize { get { return SlidingWindowSizeParameter.Value; } } 71 63 public IntValue SlidingWindowStepWidth { get { return SlidingWindowStepWidthParameter.Value; } } … … 76 68 [StorableConstructor] 77 69 protected SlidingWindowAnalyzer(bool deserializing) : base(deserializing) { } 78 protected SlidingWindowAnalyzer(SlidingWindowAnalyzer <T>original, Cloner cloner)70 protected SlidingWindowAnalyzer(SlidingWindowAnalyzer original, Cloner cloner) 79 71 : base(original, cloner) { } 80 72 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.")); 84 76 Parameters.Add(new LookupParameter<IntRange>(FitnessCalculationPartitionParameterName, "")); 85 77 Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowSizeParameterName, "", new IntValue(1))); 86 78 Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowStepWidthParameterName, "", new IntValue(1))); 87 79 Parameters.Add(new FixedValueParameter<IntRange>(InitialSlidingWindowParameterName, "", new IntRange(0, 1))); 80 Parameters.Add(new LookupParameter<BoolValue>(TerminateSlidingWindowParameterName, "")); 88 81 89 FitnessCalculationPartitionParameter.ActualName = "Sliding Window";82 ProblemDataParameter.Hidden = true; 90 83 } 91 84 92 85 public override IOperation Apply() { 86 //intialize sliding window 93 87 if (FitnessCalculationPartitionParameter.ActualValue == null) { 88 TerminateSlidingWindowParameter.ActualValue = new BoolValue(false); 94 89 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(); 105 91 } 106 92 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(); 117 94 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; 122 99 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 } 125 111 126 112 return base.Apply(); 127 113 } 128 114 129 130 115 protected abstract bool CheckForUpdate(); 131 116 } -
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowData.cs
r7845 r9162 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 28 29 29 30 namespace 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 { 32 34 33 35 [Storable] … … 43 45 } 44 46 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) 47 61 : base(original, cloner) { 48 62 slidingWindowPosition = cloner.Clone(original.slidingWindowPosition); … … 58 72 this.targetValues = targetValues.ToArray(); 59 73 } 74 75 public event EventHandler EstimatedValuesChanged; 76 private void OnEstimatedValuesChanged() { 77 var handler = EstimatedValuesChanged; 78 if (handler != null) EstimatedValuesChanged(this, EventArgs.Empty); 79 } 60 80 } 61 81 }
Note: See TracChangeset
for help on using the changeset viewer.