Changeset 18062 for branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective
- Timestamp:
- 10/01/21 10:55:19 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs
r18061 r18062 11 11 using HeuristicLab.Parameters; 12 12 using HeuristicLab.Data; 13 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 13 14 14 15 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.SingleObjective { … … 27 28 public IValueParameter<IRegressionProblemData> ProblemDataParameter => (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; 28 29 public IFixedValueParameter<StringValue> StructureDefinitionParameter => (IFixedValueParameter<StringValue>)Parameters[StructureDefinitionParameterName]; 29 public IValueParameter<ISymbolicDataAnalysisGrammar> GrammarParameter => (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[GrammarParameterName]; 30 public IValueParameter<ISymbolicDataAnalysisGrammar> GrammarParameter => (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[GrammarParameterName]; // könnte auch weg? 30 31 #endregion 31 32 … … 61 62 #region Constructors & Cloning 62 63 public StructuredSymbolicRegressionSingleObjectiveProblem() { 63 Parameters.Add(new ValueParameter<RegressionProblemData>(ProblemDataParameterName, new RegressionProblemData())); 64 Parameters.Add(new FixedValueParameter<StringValue>(StructureDefinitionParameterName, new StringValue(""))); 65 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, new LinearScalingGrammar())); 64 var problemData = new ShapeConstrainedRegressionProblemData(); 65 var grammar = new LinearScalingGrammar(); 66 var varSym = (Variable)grammar.GetSymbol("Variable"); 67 varSym.AllVariableNames = problemData.InputVariables.Select(x => x.Value); 68 varSym.VariableNames = problemData.InputVariables.Select(x => x.Value); 69 varSym.Enabled = true; 70 71 Parameters.Add(new ValueParameter<RegressionProblemData>(ProblemDataParameterName, problemData)); 72 Parameters.Add(new FixedValueParameter<StringValue>(StructureDefinitionParameterName, new StringValue("e^f(x)/F(y)"))); 73 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, grammar)); 74 var parser = new InfixExpressionParser(); 75 var tree = parser.Parse(StructureDefinition); 76 77 GetSubFunctions(tree); 66 78 } 67 79 … … 77 89 #endregion 78 90 91 public void GetSubFunctions(ISymbolicExpressionTree tree) { 92 int count = 1; 93 foreach(var node in tree.IterateNodesPrefix()) 94 if(node.Symbol is SubFunctionSymbol) 95 Encoding.Add(new SymbolicExpressionTreeEncoding($"f{count++}", Grammar/*new LinearScalingGrammar()*/, 25, 8)); 96 } 97 79 98 public override double Evaluate(Individual individual, IRandom random) { 99 foreach(var kvp in individual.Values) { 100 if(kvp.Value is SymbolicExpressionTree tree) { 101 foreach(var n in tree.IterateNodesPrefix()) { 102 if(n.Symbol is Variable v) { 103 var t = v.VariableNames; 104 } 105 } 106 Console.WriteLine(tree); 107 } 108 } 80 109 return 0.0; 81 110 }
Note: See TracChangeset
for help on using the changeset viewer.