Changeset 5685 for branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Timestamp:
- 03/15/11 12:35:14 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisValidationAnalyzer.cs
r5607 r5685 42 42 private const string ProblemDataParameterName = "ProblemData"; 43 43 private const string EvaluatorParameterName = "Evaluator"; 44 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 44 45 private const string ValidationSamplesStartParameterName = "ValidationSamplesStart"; 45 46 private const string ValidationSamplesEndParameterName = "ValidationSamplesEnd"; … … 52 53 get { return (ILookupParameter<T>)Parameters[EvaluatorParameterName]; } 53 54 } 55 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { 56 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } 57 } 54 58 public IValueLookupParameter<IntValue> ValidationSamplesStartParameter { 55 59 get { return (IValueLookupParameter<IntValue>)Parameters[ValidationSamplesStartParameterName]; } … … 59 63 } 60 64 #endregion 65 61 66 #region properties 62 67 public U ProblemData { get { return ProblemDataParameter.ActualValue; } } 63 68 public T Evaluator { get { return EvaluatorParameter.ActualValue; } } 69 public ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicDataAnalysisTreeInterpreter { get { return SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; } } 64 70 public IntValue ValidationSamplesStart { get { return ValidationSamplesStartParameter.ActualValue; } } 65 71 public IntValue ValidationSamplesEnd { get { return ValidationSamplesEndParameter.ActualValue; } } 66 72 #endregion 73 67 74 [StorableConstructor] 68 75 protected SymbolicDataAnalysisValidationAnalyzer(bool deserializing) : base(deserializing) { } … … 74 81 Parameters.Add(new LookupParameter<U>(ProblemDataParameterName, "The problem data of the symbolic data analysis problem.")); 75 82 Parameters.Add(new LookupParameter<T>(EvaluatorParameterName, "The operator to use for fitness evaluation on the validation partition.")); 83 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter for symbolic data analysis expression trees.")); 76 84 Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesStartParameterName, "The start index of the validation partition.")); 77 85 Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesEndParameterName, "The end index of the validation partition.")); -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r5624 r5685 108 108 </ItemGroup> 109 109 <ItemGroup> 110 <Compile Include="Analyzers\SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 110 111 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer.cs" /> 111 112 <Compile Include="Analyzers\SymbolicDataAnalysisValidationAnalyzer.cs" /> -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisMultiObjectiveProblem.cs
r5618 r5685 58 58 [StorableConstructor] 59 59 protected SymbolicDataAnalysisMultiObjectiveProblem(bool deserializing) : base(deserializing) { } 60 protected SymbolicDataAnalysisMultiObjectiveProblem(SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> original, Cloner cloner) : base(original, cloner) { } 60 protected SymbolicDataAnalysisMultiObjectiveProblem(SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> original, Cloner cloner) 61 : base(original, cloner) { 62 RegisterEventHandler(); 63 } 61 64 62 65 public SymbolicDataAnalysisMultiObjectiveProblem(T problemData, U evaluator, V solutionCreator) 63 66 : base(problemData, evaluator, solutionCreator) { 64 67 Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized.")); 68 69 ParameterizeOperators(); 70 RegisterEventHandler(); 71 } 72 73 [StorableHook(HookType.AfterDeserialization)] 74 private void AfterDeserialization() { 75 RegisterEventHandler(); 76 } 77 78 private void RegisterEventHandler() { 79 Evaluator.QualitiesParameter.ActualNameChanged += new System.EventHandler(QualitiesParameter_ActualNameChanged); 65 80 } 66 81 67 82 protected override void OnEvaluatorChanged() { 68 83 base.OnEvaluatorChanged(); 84 Evaluator.QualitiesParameter.ActualNameChanged += new System.EventHandler(QualitiesParameter_ActualNameChanged); 69 85 Maximization = new BoolArray(Evaluator.Maximization.ToArray()); 86 ParameterizeOperators(); 87 } 88 89 private void QualitiesParameter_ActualNameChanged(object sender, System.EventArgs e) { 90 ParameterizeOperators(); 91 } 92 93 protected override void ParameterizeOperators() { 94 base.ParameterizeOperators(); 95 foreach (var op in Operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) { 96 op.QualitiesParameter.ActualName = Evaluator.QualitiesParameter.ActualName; 97 op.MaximizationParameter.ActualName = MaximizationParameterName; 98 } 70 99 } 71 100 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r5624 r5685 47 47 private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar"; 48 48 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 49 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";50 private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";51 49 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 52 50 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; … … 57 55 private const string SymbolicExpressionTreeGrammarParameterDescription = "The grammar that should be used for symbolic expression tree."; 58 56 private const string SymoblicExpressionTreeInterpreterParameterDescription = "The interpreter that should be used to evaluate the symbolic expression tree."; 59 private const string LowerEstimationLimitParameterDescription = "The lower limit for the estimated value that can be returned by the symbolic data analysis model.";60 private const string UpperEstimationLimitParameterDescription = "The upper limit for the estimated value that can be returned by the symbolic data analysis model.";61 57 private const string MaximumSymbolicExpressionTreeDepthParameterDescription = "Maximal depth of the symbolic expression. The minimum depth needed for the algorithm is 3 because two levels are reserved for the ProgramRoot and the Start symbol."; 62 58 private const string MaximumSymbolicExpressionTreeLengthParameterDescription = "Maximal length of the symbolic expression."; … … 78 74 get { return (IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; } 79 75 } 80 public IFixedValueParameter<DoubleValue> LowerEstimationLimitParameter {81 get { return (IFixedValueParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }82 }83 public IFixedValueParameter<DoubleValue> UpperEstimationLimitParameter {84 get { return (IFixedValueParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }85 }86 76 public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { 87 77 get { return (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } … … 117 107 get { return SymbolicExpressionTreeInterpreterParameter.Value; } 118 108 set { SymbolicExpressionTreeInterpreterParameter.Value = value; } 119 }120 121 public DoubleValue LowerEstimationLimit {122 get { return LowerEstimationLimitParameter.Value; }123 }124 public DoubleValue UpperEstimationLimit {125 get { return UpperEstimationLimitParameter.Value; }126 109 } 127 110 … … 156 139 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(SymbolicExpressionTreeGrammarParameterName, SymbolicExpressionTreeGrammarParameterDescription)); 157 140 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, SymoblicExpressionTreeInterpreterParameterDescription)); 158 Parameters.Add(new FixedValueParameter<DoubleValue>(LowerEstimationLimitParameterName, LowerEstimationLimitParameterDescription, new DoubleValue()));159 Parameters.Add(new FixedValueParameter<DoubleValue>(UpperEstimationLimitParameterName, UpperEstimationLimitParameterDescription, new DoubleValue()));160 141 Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, MaximumSymbolicExpressionTreeDepthParameterDescription, new IntValue())); 161 142 Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, MaximumSymbolicExpressionTreeLengthParameterDescription, new IntValue())); … … 167 148 168 149 UpdateGrammar(); 169 Update EstimationLimits();150 UpdateDatasetPartitions(); 170 151 RegisterEventHandlers(); 171 152 InitializeOperators(); 172 153 } 173 154 174 protected abstract void UpdateEstimationLimits(); 155 protected virtual void UpdateDatasetPartitions() { 156 Evaluator.SamplesStartParameter.Value.Value = ProblemData.TrainingPartitionStart.Value; 157 Evaluator.SamplesEndParameter.Value.Value = ProblemData.TrainingPartitionEnd.Value; 158 159 foreach (var analyzer in Operators.OfType<ISymbolicDataAnalysisValidationAnalyzer<U, T>>()) { 160 analyzer.ValidationSamplesStartParameter.Value = new IntValue(ProblemData.TrainingPartitionStart.Value); 161 analyzer.ValidationSamplesEndParameter.Value = new IntValue(ProblemData.TrainingPartitionEnd.Value); 162 } 163 } 164 165 protected virtual void UpdateGrammar() { 166 foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>()) { 167 varSymbol.VariableNames = ProblemData.AllowedInputVariables; 168 } 169 foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) { 170 varSymbol.VariableNames = ProblemData.AllowedInputVariables; 171 } 172 } 175 173 176 174 private void InitializeOperators() { 177 175 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>()); 178 176 Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); 177 Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer()); 179 178 Operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer()); 180 179 ParameterizeOperators(); 181 180 } 182 181 183 private void ProblemDataParameter_ValueChanged(object sender, EventArgs e) { 184 ProblemDataParameter.Value.Changed += (object s, EventArgs args) => OnProblemDataChanged(); 185 186 OnProblemDataChanged(); 187 } 182 #region events 188 183 private void RegisterEventHandlers() { 189 184 ProblemDataParameter.ValueChanged += new EventHandler(ProblemDataParameter_ValueChanged); … … 195 190 } 196 191 192 private void ProblemDataParameter_ValueChanged(object sender, EventArgs e) { 193 ProblemDataParameter.Value.Changed += (object s, EventArgs args) => OnProblemDataChanged(); 194 OnProblemDataChanged(); 195 } 196 197 197 private void ArchitectureParameterValue_ValueChanged(object sender, EventArgs e) { 198 198 UpdateGrammar(); 199 }200 protected virtual void UpdateGrammar() {201 foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>()) {202 varSymbol.VariableNames = ProblemData.AllowedInputVariables;203 }204 foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) {205 varSymbol.VariableNames = ProblemData.AllowedInputVariables;206 }207 199 } 208 200 … … 217 209 ParameterizeOperators(); 218 210 } 211 219 212 private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) { 220 213 ParameterizeOperators(); … … 223 216 protected override void OnEvaluatorChanged() { 224 217 base.OnEvaluatorChanged(); 218 ParameterizeOperators(); 225 219 } 226 220 … … 228 222 protected virtual void OnProblemDataChanged() { 229 223 UpdateGrammar(); 230 UpdateEstimationLimits(); 224 UpdateDatasetPartitions(); 225 ParameterizeOperators(); 226 231 227 var handler = ProblemDataChanged; 232 228 if (handler != null) handler(this, EventArgs.Empty); … … 234 230 OnReset(); 235 231 } 236 237 private void ParameterizeOperators() { 232 #endregion 233 234 protected virtual void ParameterizeOperators() { 238 235 var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators); 239 236 240 237 foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) { 241 op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter .Name;238 op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameterName; 242 239 } 243 240 foreach (var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) { 244 op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter .Name;245 op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter .Name;241 op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameterName; 242 op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameterName; 246 243 } 247 244 foreach (var op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) { 248 op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter .Name;249 op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter .Name;245 op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameterName; 246 op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameterName; 250 247 } 251 248 foreach (var op in operators.OfType<ISymbolicDataAnalysisEvaluator<T>>()) { 252 op.ProblemDataParameter.ActualName = ProblemDataParameter .Name;249 op.ProblemDataParameter.ActualName = ProblemDataParameterName; 253 250 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 254 251 op.SamplesStartParameter.Value.Value = ProblemData.TrainingPartitionStart.Value; 255 252 op.SamplesEndParameter.Value.Value = ProblemData.TrainingPartitionEnd.Value; 256 }257 foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedEvaluator<T>>()) {258 op.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;259 op.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;260 253 } 261 254 foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) { … … 269 262 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 270 263 } 264 foreach (var op in operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) { 265 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameterName; 266 } 267 foreach (var op in operators.OfType<ISymbolicDataAnalysisAnalyzer>()) { 268 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 269 } 271 270 } 272 271 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs
r5618 r5685 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 26 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System; 28 30 29 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 65 67 [StorableConstructor] 66 68 protected SymbolicDataAnalysisSingleObjectiveProblem(bool deserializing) : base(deserializing) { } 67 protected SymbolicDataAnalysisSingleObjectiveProblem(SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner) : base(original, cloner) { } 69 protected SymbolicDataAnalysisSingleObjectiveProblem(SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner) 70 : base(original, cloner) { 71 RegisterEventHandler(); 72 } 68 73 69 74 public SymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator) … … 71 76 Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue())); 72 77 Parameters.Add(new FixedValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.", new DoubleValue())); 78 79 RegisterEventHandler(); 80 } 81 82 [StorableHook(HookType.AfterDeserialization)] 83 private void AfterDeserialization() { 84 RegisterEventHandler(); 85 } 86 87 private void RegisterEventHandler() { 88 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged); 73 89 } 74 90 75 91 protected override void OnEvaluatorChanged() { 76 92 base.OnEvaluatorChanged(); 93 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged); 77 94 Maximization.Value = base.Evaluator.Maximization; 95 ParameterizeOperators(); 96 } 97 98 private void QualityParameter_ActualNameChanged(object sender, EventArgs e) { 99 ParameterizeOperators(); 100 } 101 102 protected override void ParameterizeOperators() { 103 base.ParameterizeOperators(); 104 105 foreach (var op in Operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) { 106 op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 107 op.MaximizationParameter.ActualName = MaximizationParameterName; 108 } 78 109 } 79 110 }
Note: See TracChangeset
for help on using the changeset viewer.