- Timestamp:
- 03/06/17 17:53:46 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer.cs
r14185 r14721 35 35 [Item("SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic data analysis solution for single objective symbolic data analysis problems.")] 36 36 [StorableClass] 37 public abstract class SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<T> : SymbolicDataAnalysisSingleObjectiveAnalyzer, IIterationBasedOperator 38 39 where T : class, ISymbolicDataAnalysisSolution { 37 public abstract class SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<T> : SymbolicDataAnalysisSingleObjectiveAnalyzer, IIterationBasedOperator where T : class, ISymbolicDataAnalysisSolution { 40 38 private const string TrainingBestSolutionParameterName = "Best training solution"; 41 39 private const string TrainingBestSolutionQualityParameterName = "Best training solution quality"; 42 40 private const string TrainingBestSolutionGenerationParameterName = "Best training solution generation"; 41 private const string TrainingBestSolutionsHistoryParameterName = "Best training solutions history"; 43 42 private const string UpdateAlwaysParameterName = "Always update best solution"; 44 43 private const string IterationsParameterName = "Iterations"; 45 44 private const string MaximumIterationsParameterName = "Maximum Iterations"; 45 private const string StoreHistoryParameterName = "Store History"; 46 46 47 47 #region parameter properties … … 55 55 get { return (ILookupParameter<IntValue>)Parameters[TrainingBestSolutionGenerationParameterName]; } 56 56 } 57 public ILookupParameter<ItemList<T>> TrainingBestSolutionsHistoryParameter { 58 get { return (ILookupParameter<ItemList<T>>)Parameters[TrainingBestSolutionsHistoryParameterName]; } 59 } 57 60 public IFixedValueParameter<BoolValue> UpdateAlwaysParameter { 58 61 get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; } … … 63 66 public IValueLookupParameter<IntValue> MaximumIterationsParameter { 64 67 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumIterationsParameterName]; } 68 } 69 70 public IFixedValueParameter<BoolValue> StoreHistoryParameter { 71 get { return (IFixedValueParameter<BoolValue>)Parameters[StoreHistoryParameterName]; } 65 72 } 66 73 #endregion … … 74 81 set { TrainingBestSolutionQualityParameter.ActualValue = value; } 75 82 } 76 public BoolValue UpdateAlways { 77 get { return UpdateAlwaysParameter.Value; } 83 public bool UpdateAlways { 84 get { return UpdateAlwaysParameter.Value.Value; } 85 set { UpdateAlwaysParameter.Value.Value = value; } 86 } 87 88 public bool StoreHistory { 89 get { return StoreHistoryParameter.Value.Value; } 90 set { StoreHistoryParameter.Value.Value = value; } 78 91 } 79 92 #endregion 93 80 94 81 95 [StorableConstructor] … … 84 98 public SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer() 85 99 : base() { 86 Parameters.Add(new LookupParameter<T>(TrainingBestSolutionParameterName, "The training bestsymbolic data analyis solution."));100 Parameters.Add(new LookupParameter<T>(TrainingBestSolutionParameterName, "The best training symbolic data analyis solution.")); 87 101 Parameters.Add(new LookupParameter<DoubleValue>(TrainingBestSolutionQualityParameterName, "The quality of the training best symbolic data analysis solution.")); 88 102 Parameters.Add(new LookupParameter<IntValue>(TrainingBestSolutionGenerationParameterName, "The generation in which the best training solution was found.")); … … 90 104 Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, "The number of performed iterations.")); 91 105 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, "The maximum number of performed iterations.") { Hidden = true }); 106 Parameters.Add(new FixedValueParameter<BoolValue>(StoreHistoryParameterName, "Flag that determines whether all encountered best solutions should be stored as results.", new BoolValue(false))); 107 Parameters.Add(new LookupParameter<ItemList<T>>(TrainingBestSolutionsHistoryParameterName, "The history of the best training symbolic data analysis solutions.")); 92 108 UpdateAlwaysParameter.Hidden = true; 93 109 } … … 105 121 if (!Parameters.ContainsKey(MaximumIterationsParameterName)) 106 122 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, "The maximum number of performed iterations.") { Hidden = true }); 123 if (!Parameters.ContainsKey(StoreHistoryParameterName)) 124 Parameters.Add(new FixedValueParameter<BoolValue>(StoreHistoryParameterName, "Flag that determines whether all encountered best solutions should be stored as results.", new BoolValue(false))); 125 if (!Parameters.ContainsKey(TrainingBestSolutionsHistoryParameterName)) 126 Parameters.Add(new LookupParameter<ItemList<T>>(TrainingBestSolutionsHistoryParameterName, "The history of the best training symbolic data analysis solutions.")); 107 127 } 108 128 109 129 public override IOperation Apply() { 130 var results = ResultCollection; 131 #region create results 132 if (!results.ContainsKey(TrainingBestSolutionParameter.Name)) 133 results.Add(new Result(TrainingBestSolutionParameter.Name, TrainingBestSolutionParameter.Description, typeof(T))); 134 if (!results.ContainsKey(TrainingBestSolutionQualityParameter.Name)) 135 results.Add(new Result(TrainingBestSolutionQualityParameter.Name, TrainingBestSolutionQualityParameter.Description, typeof(DoubleValue))); 136 if (!results.ContainsKey(TrainingBestSolutionGenerationParameter.Name) && IterationsParameter.ActualValue != null) 137 results.Add(new Result(TrainingBestSolutionGenerationParameter.Name, TrainingBestSolutionGenerationParameter.Description, typeof(IntValue))); 138 if (StoreHistory && !results.ContainsKey(TrainingBestSolutionsHistoryParameter.Name)) { 139 140 results.Add(new Result(TrainingBestSolutionsHistoryParameter.Name, TrainingBestSolutionsHistoryParameter.Description, typeof(ItemList<T>))); 141 TrainingBestSolutionsHistoryParameter.ActualValue = new ItemList<T>(); 142 results[TrainingBestSolutionsHistoryParameter.Name].Value = TrainingBestSolutionsHistoryParameter.ActualValue; 143 } 144 #endregion 145 110 146 #region find best tree 111 147 double bestQuality = Maximization.Value ? double.NegativeInfinity : double.PositiveInfinity; … … 121 157 #endregion 122 158 123 var results = ResultCollection; 124 if (bestTree != null && (UpdateAlways.Value || TrainingBestSolutionQuality == null || 159 if (bestTree != null && (UpdateAlways || TrainingBestSolutionQuality == null || 125 160 IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value))) { 126 161 TrainingBestSolution = CreateSolution(bestTree, bestQuality); … … 129 164 TrainingBestSolutionGenerationParameter.ActualValue = new IntValue(IterationsParameter.ActualValue.Value); 130 165 131 if (!results.ContainsKey(TrainingBestSolutionParameter.Name)) { 132 results.Add(new Result(TrainingBestSolutionParameter.Name, TrainingBestSolutionParameter.Description, TrainingBestSolution)); 133 results.Add(new Result(TrainingBestSolutionQualityParameter.Name, TrainingBestSolutionQualityParameter.Description, TrainingBestSolutionQuality)); 134 if (TrainingBestSolutionGenerationParameter.ActualValue != null) 135 results.Add(new Result(TrainingBestSolutionGenerationParameter.Name, TrainingBestSolutionGenerationParameter.Description, TrainingBestSolutionGenerationParameter.ActualValue)); 136 } else { 137 results[TrainingBestSolutionParameter.Name].Value = TrainingBestSolution; 138 results[TrainingBestSolutionQualityParameter.Name].Value = TrainingBestSolutionQuality; 139 if (TrainingBestSolutionGenerationParameter.ActualValue != null) 140 results[TrainingBestSolutionGenerationParameter.Name].Value = TrainingBestSolutionGenerationParameter.ActualValue; 166 results[TrainingBestSolutionParameter.Name].Value = TrainingBestSolution; 167 results[TrainingBestSolutionQualityParameter.Name].Value = TrainingBestSolutionQuality; 168 if (TrainingBestSolutionGenerationParameter.ActualValue != null) 169 results[TrainingBestSolutionGenerationParameter.Name].Value = TrainingBestSolutionGenerationParameter.ActualValue; 141 170 171 if (StoreHistory) { 172 TrainingBestSolutionsHistoryParameter.ActualValue.Add(TrainingBestSolution); 142 173 } 143 174 }
Note: See TracChangeset
for help on using the changeset viewer.