Changeset 18075 for branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Timestamp:
- 10/29/21 16:56:22 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs
r18072 r18075 12 12 using HeuristicLab.Data; 13 13 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 14 using HeuristicLab.PluginInfrastructure; 14 15 15 16 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 17 18 [Item(Name = "Structured Symbolic Regression Single Objective Problem (single-objective)", Description = "A problem with a structural definition and unfixed subfunctions.")] 18 19 [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 150)] 19 public class StructuredSymbolicRegressionSingleObjectiveProblem : SingleObjectiveBasicProblem<MultiEncoding>, IRegressionProblem, IProblemInstanceConsumer< RegressionProblemData> {20 public class StructuredSymbolicRegressionSingleObjectiveProblem : SingleObjectiveBasicProblem<MultiEncoding>, IRegressionProblem, IProblemInstanceConsumer<IRegressionProblemData> { 20 21 21 22 #region Constants 22 23 private const string ProblemDataParameterName = "ProblemData"; 23 private const string StructureDefinitionParameterName = "Structure Definition";24 24 private const string StructureTemplateParameterName = "Structure Template"; 25 private const string InterpreterParameterName = "Interpreter"; 25 26 26 27 private const string StructureTemplateDescriptionText = … … 33 34 #region Parameters 34 35 public IValueParameter<IRegressionProblemData> ProblemDataParameter => (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; 35 public IFixedValueParameter<StringValue> StructureDefinitionParameter => (IFixedValueParameter<StringValue>)Parameters[StructureDefinitionParameterName];36 36 public IFixedValueParameter<StructureTemplate> StructureTemplateParameter => (IFixedValueParameter<StructureTemplate>)Parameters[StructureTemplateParameterName]; 37 public IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter => (IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; 37 38 #endregion 38 39 … … 46 47 } 47 48 48 public string StructureDefinition { 49 get => StructureDefinitionParameter.Value.Value; 50 set => StructureDefinitionParameter.Value.Value = value; 51 } 52 53 public StructureTemplate StructureTemplate { 54 get => StructureTemplateParameter.Value; 55 } 56 57 public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get; } = new SymbolicDataAnalysisExpressionTreeInterpreter(); 49 public StructureTemplate StructureTemplate => StructureTemplateParameter.Value; 50 51 public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter => InterpreterParameter.Value; 58 52 59 53 IParameter IDataAnalysisProblem.ProblemDataParameter => ProblemDataParameter; … … 74 68 structureTemplate.Changed += OnTemplateChanged; 75 69 76 Parameters.Add(new ValueParameter<IRegressionProblemData>(ProblemDataParameterName, problemData)); 77 Parameters.Add(new FixedValueParameter<StructureTemplate>(StructureTemplateParameterName, 78 StructureTemplateDescriptionText, structureTemplate)); 79 80 70 Parameters.Add(new ValueParameter<IRegressionProblemData>( 71 ProblemDataParameterName, 72 problemData)); 73 74 Parameters.Add(new FixedValueParameter<StructureTemplate>( 75 StructureTemplateParameterName, 76 StructureTemplateDescriptionText, 77 structureTemplate)); 78 79 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>( 80 InterpreterParameterName, 81 new SymbolicDataAnalysisExpressionTreeInterpreter()) 82 { Hidden = true }); 83 84 ProblemDataParameter.ValueChanged += ProblemDataParameterValueChanged; 81 85 } 82 86 … … 93 97 #endregion 94 98 99 private void ProblemDataParameterValueChanged(object sender, EventArgs e) { 100 StructureTemplate.Reset(); 101 // InfoBox for Reset? 102 } 103 95 104 private void OnTemplateChanged(object sender, EventArgs args) { 96 105 SetupStructureTemplate(); … … 103 112 foreach (var f in StructureTemplate.SubFunctions.Values) { 104 113 SetupVariables(f); 105 if(!Encoding.Encodings.Any(x => x.Name == f.Name)) // to prevent the same encoding twice 106 Encoding.Add(new SymbolicExpressionTreeEncoding(f.Name, f.Grammar, f.MaximumSymbolicExpressionTreeLength, f.MaximumSymbolicExpressionTreeDepth)); 114 if (!Encoding.Encodings.Any(x => x.Name == f.Name)) // to prevent the same encoding twice 115 Encoding.Add(new SymbolicExpressionTreeEncoding( 116 f.Name, 117 f.Grammar, 118 f.MaximumSymbolicExpressionTreeLength, 119 f.MaximumSymbolicExpressionTreeDepth)); 107 120 } 108 121 } … … 133 146 results.Add(new Result("Best Tree", tree)); 134 147 } 135 136 148 } 137 149 … … 168 180 169 181 private ISymbolicExpressionTree BuildTree(Individual individual) { 182 if (StructureTemplate.Tree == null) 183 throw new ArgumentException("No structure template defined!"); 184 170 185 var templateTree = (ISymbolicExpressionTree)StructureTemplate.Tree.Clone(); 171 186 … … 175 190 var subFunctionTreeNode = n as SubFunctionTreeNode; 176 191 var subFunctionTree = individual.SymbolicExpressionTree(subFunctionTreeNode.Name); 177 //var parent = n.Parent;178 179 // remove SubFunctionTreeNode180 //parent.RemoveSubtree(parent.IndexOfSubtree(subFunctionTreeNode));181 192 182 193 // add new tree 183 194 var subTree = subFunctionTree.Root.GetSubtree(0) // Start 184 195 .GetSubtree(0); // Offset 185 //parent.AddSubtree(subTree);186 196 subFunctionTreeNode.AddSubtree(subTree); 187 197 } … … 223 233 } 224 234 225 public void Load(RegressionProblemData data) { 226 ProblemData = data; 227 SetupStructureTemplate(); 228 } 235 public void Load(IRegressionProblemData data) => ProblemData = data; 229 236 } 230 237 }
Note: See TracChangeset
for help on using the changeset viewer.