- Timestamp:
- 01/26/14 01:42:09 (11 years ago)
- 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 88 88 protected BoolValue PruneOnlyZeroImpactNodes { get { return PruneOnlyZeroImpactNodesParameter.Value; } } 89 89 #endregion 90 91 [StorableConstructor] 92 protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer(bool deserializing) : base(deserializing) { } 90 93 protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer(SymbolicDataAnalysisSingleObjectivePruningAnalyzer original, Cloner cloner) 91 94 : base(original, cloner) { -
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r10373 r10396 158 158 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" /> 159 159 <Compile Include="SlidingWindow\OffspringSelectionSlidingWindowAnalyzer.cs" /> 160 <Compile Include="SlidingWindow\SlidingWindowBestSolutionsCollection.cs"> 161 <SubType>Code</SubType> 162 </Compile> 160 163 <Compile Include="SlidingWindow\SlidingWindowData.cs" /> 161 164 <Compile Include="SlidingWindow\GenerationalSlidingWindowAnalyzer.cs" /> -
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowAnalyzer.cs
r9707 r10396 20 20 #endregion 21 21 22 using System; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; 24 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 28 using HeuristicLab.Operators; 26 29 using HeuristicLab.Optimization; … … 31 34 [StorableClass] 32 35 [Item("Sliding Window GP Analyzer", "Base class for concrete sliding window GP analyzers.")] 33 public abstract class SlidingWindowAnalyzer : SymbolicDataAnalysis Analyzer {36 public abstract class SlidingWindowAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer { 34 37 private const string ProblemDataParameterName = "ProblemData"; 35 38 private const string EvaluatorParameterName = "Evaluator"; … … 41 44 private const string InitialSlidingWindowParameterName = "Initial Sliding Window"; 42 45 private const string TerminateSlidingWindowParameterName = "TerminateSlidingWindow"; 46 private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 43 47 44 48 #region parameter properties 49 private ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter { 50 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; } 51 } 45 52 public IValueLookupParameter<IDataAnalysisProblemData> ProblemDataParameter { 46 53 get { return (IValueLookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; } … … 75 82 public override bool EnabledByDefault { get { return false; } } 76 83 public IntValue SlidingWindowSize { get { return SlidingWindowSizeParameter.Value; } } 77 public IntValue Valid iationSlidingWindowSize { get { return ValidationSlidingWindowSizeParameter.Value; } }84 public IntValue ValidationSlidingWindowSize { get { return ValidationSlidingWindowSizeParameter.Value; } } 78 85 public IntValue SlidingWindowStepWidth { get { return SlidingWindowStepWidthParameter.Value; } } 79 86 public IntRange InitialSlidingWindow { get { return InitialSlidingWindowParameter.Value; } } 87 public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get { return InterpreterParameter.ActualValue; } } 88 public IDataAnalysisProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } } 80 89 #endregion 81 82 90 83 91 [StorableConstructor] … … 97 105 Parameters.Add(new FixedValueParameter<IntRange>(InitialSlidingWindowParameterName, "", new IntRange(0, 1))); 98 106 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; 99 114 100 ProblemDataParameter.Hidden = true;101 115 } 102 116 … … 105 119 if (!Parameters.ContainsKey(EvaluatorParameterName)) 106 120 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)); 107 129 } 108 130 … … 112 134 TerminateSlidingWindowParameter.ActualValue = new BoolValue(false); 113 135 FitnessCalculationPartitionParameter.ActualValue = (IntRange)InitialSlidingWindow.Clone(); 114 ValidationPartitionParameter.ActualValue = new IntRange(InitialSlidingWindow.End, InitialSlidingWindow.End + Valid iationSlidingWindowSize.Value);136 ValidationPartitionParameter.ActualValue = new IntRange(InitialSlidingWindow.End, InitialSlidingWindow.End + ValidationSlidingWindowSize.Value); 115 137 return base.Apply(); 116 138 } 117 139 118 140 if (!CheckForUpdate()) return base.Apply(); 141 142 SaveBestSolution(); 119 143 120 144 //update necessary - move sliding window … … 136 160 FitnessCalculationPartitionParameter.ActualValue.End = fitnessPartition.End; 137 161 ValidationPartitionParameter.ActualValue.Start = fitnessPartition.End; 138 ValidationPartitionParameter.ActualValue.End = ValidationPartitionParameter.ActualValue.Start + Valid iationSlidingWindowSize.Value;162 ValidationPartitionParameter.ActualValue.End = ValidationPartitionParameter.ActualValue.Start + ValidationSlidingWindowSize.Value; 139 163 140 164 //reevaluate all individuals with new sliding window … … 147 171 } 148 172 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 149 196 protected abstract bool CheckForUpdate(); 150 197 }
Note: See TracChangeset
for help on using the changeset viewer.