- Timestamp:
- 10/20/21 14:39:46 (3 years ago)
- Location:
- branches/3136_Structural_GP
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs
r18068 r18071 49 49 } 50 50 51 public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get; } = new SymbolicDataAnalysisExpressionTreeInterpreter(); 52 51 53 IParameter IDataAnalysisProblem.ProblemDataParameter => ProblemDataParameter; 52 54 IDataAnalysisProblemData IDataAnalysisProblem.ProblemData => ProblemData; … … 110 112 } 111 113 112 if (results.TryGetValue("Best Tree", out IResult result)) 113 result.Value = BuildTree(individuals[bestIdx]); 114 else 115 results.Add(new Result("Best Tree", BuildTree(individuals[bestIdx]))); 114 if (results.TryGetValue("Best Tree", out IResult result)) { 115 var tree = BuildTree(individuals[bestIdx]); 116 AdjustLinearScalingParams(tree, Interpreter); 117 result.Value = tree; 118 } 119 else { 120 var tree = BuildTree(individuals[bestIdx]); 121 AdjustLinearScalingParams(tree, Interpreter); 122 results.Add(new Result("Best Tree", tree)); 123 } 124 116 125 } 117 126 118 127 public override double Evaluate(Individual individual, IRandom random) { 119 128 var tree = BuildTree(individual); 120 var interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 129 130 AdjustLinearScalingParams(tree, Interpreter); 121 131 var estimationInterval = ProblemData.VariableRanges.GetInterval(ProblemData.TargetVariable); 122 132 var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 123 interpreter, tree,133 Interpreter, tree, 124 134 estimationInterval.LowerBound, estimationInterval.UpperBound, 125 135 ProblemData, ProblemData.TrainingIndices, false); 126 136 127 137 return quality; 138 } 139 140 private void AdjustLinearScalingParams(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter) { 141 var offsetNode = tree.Root.GetSubtree(0).GetSubtree(0); 142 var scalingNode = offsetNode.Subtrees.Where(x => !(x is ConstantTreeNode)).First(); 143 144 var offsetConstantNode = (ConstantTreeNode)offsetNode.Subtrees.Where(x => x is ConstantTreeNode).First(); 145 var scalingConstantNode = (ConstantTreeNode)scalingNode.Subtrees.Where(x => x is ConstantTreeNode).First(); 146 147 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, ProblemData.Dataset, ProblemData.TrainingIndices); 148 var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices); 149 150 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out double a, out double b, out OnlineCalculatorError error); 151 if(error == OnlineCalculatorError.None) { 152 offsetConstantNode.Value = a; 153 scalingConstantNode.Value = b; 154 } 128 155 } 129 156 … … 136 163 var subFunctionTreeNode = n as SubFunctionTreeNode; 137 164 var subFunctionTree = individual.SymbolicExpressionTree(subFunctionTreeNode.Name); 138 var parent = n.Parent;165 //var parent = n.Parent; 139 166 140 167 // remove SubFunctionTreeNode 141 parent.RemoveSubtree(parent.IndexOfSubtree(subFunctionTreeNode));168 //parent.RemoveSubtree(parent.IndexOfSubtree(subFunctionTreeNode)); 142 169 143 170 // add new tree 144 171 var subTree = subFunctionTree.Root.GetSubtree(0) // Start 145 172 .GetSubtree(0); // Offset 146 parent.AddSubtree(subTree); 173 //parent.AddSubtree(subTree); 174 subFunctionTreeNode.AddSubtree(subTree); 147 175 } 148 176 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.cs
r18069 r18071 33 33 if(visualTreeNode != null) { 34 34 var subFunctionTreeNode = visualTreeNode.Content as SubFunctionTreeNode; 35 if( Content.SubFunctions.TryGetValue(subFunctionTreeNode.Name, out SubFunction subFunction))35 if(subFunctionTreeNode != null && Content.SubFunctions.TryGetValue(subFunctionTreeNode.Name, out SubFunction subFunction)) 36 36 viewHost.Content = subFunction; 37 37 } … … 55 55 infoLabel.ForeColor = Color.DarkOrange; 56 56 } 57 58 57 59 58 private void PaintTree() { -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r17963 r18071 79 79 CubeRoot = 51, 80 80 Tanh = 52, 81 SubFunction = 53 81 82 }; 82 83 public static class OpCodes { … … 134 135 public const byte CubeRoot = (byte)OpCode.CubeRoot; 135 136 public const byte Tanh = (byte)OpCode.Tanh; 136 137 public const byte SubFunction = (byte)OpCode.SubFunction; 137 138 138 139 private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { 139 140 { typeof(Addition), OpCodes.Add }, 140 141 { typeof(Subtraction), OpCodes.Sub }, 141 142 { typeof(Multiplication), OpCodes.Mul }, … … 189 190 { typeof(AnalyticQuotient), OpCodes.AnalyticQuotient }, 190 191 { typeof(Cube), OpCodes.Cube }, 191 { typeof(CubeRoot), OpCodes.CubeRoot } 192 { typeof(CubeRoot), OpCodes.CubeRoot }, 193 { typeof(SubFunctionSymbol), OpCodes.SubFunction } 192 194 }; 193 195 -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r17180 r18071 528 528 } 529 529 } 530 case OpCodes.SubFunction: { 531 return Evaluate(dataset, ref row, state); 532 } 530 533 default: 531 534 throw new NotSupportedException(); -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs
r18069 r18071 46 46 set { 47 47 applyLinearScaling = value; 48 //subFunctions = GetSubFunctions();49 48 OnChanged(); 50 49 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/SubFunction.cs
r18069 r18071 52 52 #region Constructors 53 53 public SubFunction() { 54 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, new LinearScalingGrammar()));55 Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, new IntValue( 10)));56 Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, new IntValue( 30)));54 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, new ArithmeticExpressionGrammar())); 55 Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, new IntValue(8))); 56 Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, new IntValue(20))); 57 57 58 // TODO: separate events for each parameter59 58 GrammarParameter.ValueChanged += OnParameterValueChanged; 60 59 MaximumSymbolicExpressionTreeDepthParameter.Value.ValueChanged += OnParameterValueChanged;
Note: See TracChangeset
for help on using the changeset viewer.