1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HEAL.Attic;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
30 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
31 | using HeuristicLab.Optimization;
|
---|
32 | using HeuristicLab.Parameters;
|
---|
33 | using HeuristicLab.Problems.Instances;
|
---|
34 | using HeuristicLab.Problems.Instances.DataAnalysis;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
|
---|
37 | [StorableType("7464E84B-65CC-440A-91F0-9FA920D730F9")]
|
---|
38 | [Item(Name = "Structured Symbolic Regression Single Objective Problem (single-objective)", Description = "A problem with a structural definition and unfixed subfunctions.")]
|
---|
39 | [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 150)]
|
---|
40 | public class StructuredSymbolicRegressionSingleObjectiveProblem : SingleObjectiveBasicProblem<MultiEncoding>, IRegressionProblem, IProblemInstanceConsumer<IRegressionProblemData> {
|
---|
41 |
|
---|
42 | #region Constants
|
---|
43 | private const string ProblemDataParameterName = "ProblemData";
|
---|
44 | private const string StructureTemplateParameterName = "Structure Template";
|
---|
45 | private const string InterpreterParameterName = "Interpreter";
|
---|
46 | private const string EstimationLimitsParameterName = "EstimationLimits";
|
---|
47 | private const string BestTrainingSolutionParameterName = "Best Training Solution";
|
---|
48 | private const string ApplyLinearScalingParameterName = "Apply Linear Scaling";
|
---|
49 | private const string OptimizeParametersParameterName = "Optimize Parameters";
|
---|
50 |
|
---|
51 | private const string SymbolicExpressionTreeName = "SymbolicExpressionTree";
|
---|
52 | private const string NumericParametersEncoding = "Numeric Parameters";
|
---|
53 |
|
---|
54 | private const string StructureTemplateDescriptionText =
|
---|
55 | "Enter your expression as string in infix format into the empty input field.\n" +
|
---|
56 | "By checking the \"Apply Linear Scaling\" checkbox you can add the relevant scaling terms to your expression.\n" +
|
---|
57 | "After entering the expression click parse to build the tree.\n" +
|
---|
58 | "To edit the defined sub-functions, click on the corresponding-colored node in the tree view.\n" +
|
---|
59 | "Check the info box besides the input field for more information.";
|
---|
60 | #endregion
|
---|
61 |
|
---|
62 | #region Parameters
|
---|
63 | public IValueParameter<IRegressionProblemData> ProblemDataParameter => (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName];
|
---|
64 | public IFixedValueParameter<StructureTemplate> StructureTemplateParameter => (IFixedValueParameter<StructureTemplate>)Parameters[StructureTemplateParameterName];
|
---|
65 | public IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter => (IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName];
|
---|
66 | public IFixedValueParameter<DoubleLimit> EstimationLimitsParameter => (IFixedValueParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName];
|
---|
67 | public IResultParameter<ISymbolicRegressionSolution> BestTrainingSolutionParameter => (IResultParameter<ISymbolicRegressionSolution>)Parameters[BestTrainingSolutionParameterName];
|
---|
68 |
|
---|
69 | public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter => (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName];
|
---|
70 | public IFixedValueParameter<BoolValue> OptimizeParametersParameter => (IFixedValueParameter<BoolValue>)Parameters[OptimizeParametersParameterName];
|
---|
71 | #endregion
|
---|
72 |
|
---|
73 | #region Properties
|
---|
74 |
|
---|
75 | public IRegressionProblemData ProblemData {
|
---|
76 | get => ProblemDataParameter.Value;
|
---|
77 | set {
|
---|
78 | ProblemDataParameter.Value = value;
|
---|
79 | ProblemDataChanged?.Invoke(this, EventArgs.Empty);
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public StructureTemplate StructureTemplate => StructureTemplateParameter.Value;
|
---|
84 |
|
---|
85 | public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter => InterpreterParameter.Value;
|
---|
86 |
|
---|
87 | IParameter IDataAnalysisProblem.ProblemDataParameter => ProblemDataParameter;
|
---|
88 | IDataAnalysisProblemData IDataAnalysisProblem.ProblemData => ProblemData;
|
---|
89 |
|
---|
90 | public DoubleLimit EstimationLimits => EstimationLimitsParameter.Value;
|
---|
91 |
|
---|
92 | public bool ApplyLinearScaling {
|
---|
93 | get => ApplyLinearScalingParameter.Value.Value;
|
---|
94 | set => ApplyLinearScalingParameter.Value.Value = value;
|
---|
95 | }
|
---|
96 |
|
---|
97 | public bool OptimizeParameters {
|
---|
98 | get => OptimizeParametersParameter.Value.Value;
|
---|
99 | set => OptimizeParametersParameter.Value.Value = value;
|
---|
100 | }
|
---|
101 |
|
---|
102 | public override bool Maximization => false;
|
---|
103 | #endregion
|
---|
104 |
|
---|
105 | #region EventHandlers
|
---|
106 | public event EventHandler ProblemDataChanged;
|
---|
107 | #endregion
|
---|
108 |
|
---|
109 | #region Constructors & Cloning
|
---|
110 | public StructuredSymbolicRegressionSingleObjectiveProblem() {
|
---|
111 | var provider = new PhysicsInstanceProvider();
|
---|
112 | var descriptor = new SheetBendingProcess();
|
---|
113 | var problemData = provider.LoadData(descriptor);
|
---|
114 | var shapeConstraintProblemData = new ShapeConstrainedRegressionProblemData(problemData);
|
---|
115 |
|
---|
116 | var structureTemplate = new StructureTemplate();
|
---|
117 |
|
---|
118 | Parameters.Add(new ValueParameter<IRegressionProblemData>(
|
---|
119 | ProblemDataParameterName,
|
---|
120 | shapeConstraintProblemData));
|
---|
121 |
|
---|
122 | Parameters.Add(new FixedValueParameter<StructureTemplate>(
|
---|
123 | StructureTemplateParameterName,
|
---|
124 | StructureTemplateDescriptionText,
|
---|
125 | structureTemplate));
|
---|
126 |
|
---|
127 | Parameters.Add(new FixedValueParameter<BoolValue>(
|
---|
128 | ApplyLinearScalingParameterName, new BoolValue(true)
|
---|
129 | ));
|
---|
130 |
|
---|
131 | Parameters.Add(new FixedValueParameter<BoolValue>(
|
---|
132 | OptimizeParametersParameterName, new BoolValue(true)
|
---|
133 | ));
|
---|
134 |
|
---|
135 | Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(
|
---|
136 | InterpreterParameterName,
|
---|
137 | new SymbolicDataAnalysisExpressionTreeBatchInterpreter()) { Hidden = true });
|
---|
138 | Parameters.Add(new FixedValueParameter<DoubleLimit>(
|
---|
139 | EstimationLimitsParameterName,
|
---|
140 | new DoubleLimit(double.NegativeInfinity, double.PositiveInfinity)) { Hidden = true });
|
---|
141 | Parameters.Add(new ResultParameter<ISymbolicRegressionSolution>(BestTrainingSolutionParameterName, "") { Hidden = true });
|
---|
142 |
|
---|
143 | this.EvaluatorParameter.Hidden = true;
|
---|
144 |
|
---|
145 | Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer());
|
---|
146 | Operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer());
|
---|
147 | Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
|
---|
148 |
|
---|
149 | RegisterEventHandlers();
|
---|
150 |
|
---|
151 | StructureTemplate.ApplyLinearScaling = ApplyLinearScaling;
|
---|
152 | StructureTemplate.Template =
|
---|
153 | "(" +
|
---|
154 | "(210000 / (210000 + h)) * ((sigma_y * t * t) / (wR * Rt * t)) + " +
|
---|
155 | "PlasticHardening(_) - Elasticity(_)" +
|
---|
156 | ")" +
|
---|
157 | " * C(_)";
|
---|
158 | }
|
---|
159 |
|
---|
160 | public StructuredSymbolicRegressionSingleObjectiveProblem(StructuredSymbolicRegressionSingleObjectiveProblem original, Cloner cloner) : base(original, cloner) {
|
---|
161 | RegisterEventHandlers();
|
---|
162 | }
|
---|
163 |
|
---|
164 | public override IDeepCloneable Clone(Cloner cloner) =>
|
---|
165 | new StructuredSymbolicRegressionSingleObjectiveProblem(this, cloner);
|
---|
166 |
|
---|
167 | [StorableConstructor]
|
---|
168 | protected StructuredSymbolicRegressionSingleObjectiveProblem(StorableConstructorFlag _) : base(_) { }
|
---|
169 |
|
---|
170 |
|
---|
171 | [StorableHook(HookType.AfterDeserialization)]
|
---|
172 | private void AfterDeserialization() {
|
---|
173 | if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
|
---|
174 | Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, new BoolValue(StructureTemplate.ApplyLinearScaling)));
|
---|
175 | }
|
---|
176 |
|
---|
177 | if (!Parameters.ContainsKey(OptimizeParametersParameterName)) {
|
---|
178 | Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeParametersParameterName, new BoolValue(false)));
|
---|
179 | }
|
---|
180 |
|
---|
181 | RegisterEventHandlers();
|
---|
182 | }
|
---|
183 |
|
---|
184 | #endregion
|
---|
185 |
|
---|
186 | private void RegisterEventHandlers() {
|
---|
187 | if (StructureTemplate != null) {
|
---|
188 | StructureTemplate.Changed += OnTemplateChanged;
|
---|
189 | }
|
---|
190 |
|
---|
191 | ProblemDataParameter.ValueChanged += ProblemDataParameterValueChanged;
|
---|
192 | ApplyLinearScalingParameter.Value.ValueChanged += (o, e) => StructureTemplate.ApplyLinearScaling = ApplyLinearScaling;
|
---|
193 | }
|
---|
194 |
|
---|
195 | private void ProblemDataParameterValueChanged(object sender, EventArgs e) {
|
---|
196 | StructureTemplate.Reset();
|
---|
197 | // InfoBox for Reset?
|
---|
198 | }
|
---|
199 |
|
---|
200 | private void OnTemplateChanged(object sender, EventArgs args) {
|
---|
201 | ApplyLinearScaling = StructureTemplate.ApplyLinearScaling;
|
---|
202 | SetupEncoding();
|
---|
203 | }
|
---|
204 |
|
---|
205 | private void SetupEncoding() {
|
---|
206 | foreach (var e in Encoding.Encodings.ToArray())
|
---|
207 | Encoding.Remove(e);
|
---|
208 |
|
---|
209 |
|
---|
210 | var templateNumberTreeNodes = StructureTemplate.Tree.IterateNodesPrefix().OfType<NumberTreeNode>();
|
---|
211 | if (templateNumberTreeNodes.Any()) {
|
---|
212 | var templateParameterValues = templateNumberTreeNodes.Select(n => n.Value).ToArray();
|
---|
213 | var encoding = new RealVectorEncoding(NumericParametersEncoding, templateParameterValues.Length);
|
---|
214 |
|
---|
215 | var creator = encoding.Operators.OfType<NormalDistributedRealVectorCreator>().First();
|
---|
216 | creator.MeanParameter.Value = new RealVector(templateParameterValues);
|
---|
217 | creator.SigmaParameter.Value = new DoubleArray(templateParameterValues.Length);
|
---|
218 | encoding.SolutionCreator = creator;
|
---|
219 |
|
---|
220 | Encoding.Add(encoding);
|
---|
221 | }
|
---|
222 |
|
---|
223 | foreach (var subFunction in StructureTemplate.SubFunctions) {
|
---|
224 | subFunction.SetupVariables(ProblemData.AllowedInputVariables);
|
---|
225 | // prevent the same encoding twice
|
---|
226 | if (Encoding.Encodings.Any(x => x.Name == subFunction.Name)) continue;
|
---|
227 |
|
---|
228 | var encoding = new SymbolicExpressionTreeEncoding(
|
---|
229 | subFunction.Name,
|
---|
230 | subFunction.Grammar,
|
---|
231 | subFunction.MaximumSymbolicExpressionTreeLength,
|
---|
232 | subFunction.MaximumSymbolicExpressionTreeDepth);
|
---|
233 | Encoding.Add(encoding);
|
---|
234 | }
|
---|
235 |
|
---|
236 | //set single point crossover for numeric parameters
|
---|
237 | var multiCrossover = (IParameterizedItem)Encoding.Operators.OfType<MultiEncodingCrossover>().First();
|
---|
238 | foreach (var param in multiCrossover.Parameters.OfType<ConstrainedValueParameter<ICrossover>>()) {
|
---|
239 | var singlePointCrossover = param.ValidValues.OfType<SinglePointCrossover>().FirstOrDefault();
|
---|
240 | param.Value = singlePointCrossover ?? param.ValidValues.First();
|
---|
241 | }
|
---|
242 |
|
---|
243 | //adapt crossover probability for subtree crossover
|
---|
244 | foreach (var param in multiCrossover.Parameters.OfType<ConstrainedValueParameter<ICrossover>>()) {
|
---|
245 | var subtreeCrossover = param.ValidValues.OfType<SubtreeCrossover>().FirstOrDefault();
|
---|
246 | if (subtreeCrossover != null) {
|
---|
247 | subtreeCrossover.CrossoverProbability = 1.0 / Encoding.Encodings.OfType<SymbolicExpressionTreeEncoding>().Count();
|
---|
248 | param.Value = subtreeCrossover;
|
---|
249 | }
|
---|
250 | }
|
---|
251 |
|
---|
252 | //set multi manipulator as default manipulator for all symbolic expression tree encoding parts
|
---|
253 | var manipulator = (IParameterizedItem)Encoding.Operators.OfType<MultiEncodingManipulator>().First();
|
---|
254 | foreach (var param in manipulator.Parameters.OfType<ConstrainedValueParameter<IManipulator>>()) {
|
---|
255 | var m = param.ValidValues.OfType<MultiSymbolicExpressionTreeManipulator>().FirstOrDefault();
|
---|
256 | param.Value = m ?? param.ValidValues.First();
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
|
---|
261 | base.Analyze(individuals, qualities, results, random);
|
---|
262 |
|
---|
263 | var best = GetBestIndividual(individuals, qualities).Item1;
|
---|
264 |
|
---|
265 | if (!results.ContainsKey(BestTrainingSolutionParameter.ActualName)) {
|
---|
266 | results.Add(new Result(BestTrainingSolutionParameter.ActualName, typeof(SymbolicRegressionSolution)));
|
---|
267 | }
|
---|
268 |
|
---|
269 | var tree = (ISymbolicExpressionTree)best[SymbolicExpressionTreeName];
|
---|
270 | var model = new SymbolicRegressionModel(ProblemData.TargetVariable, tree, Interpreter);
|
---|
271 | var solution = model.CreateRegressionSolution(ProblemData);
|
---|
272 |
|
---|
273 | results[BestTrainingSolutionParameter.ActualName].Value = solution;
|
---|
274 | }
|
---|
275 |
|
---|
276 |
|
---|
277 | public override double Evaluate(Individual individual, IRandom random) {
|
---|
278 | var templateTree = StructureTemplate.Tree;
|
---|
279 | if (templateTree == null)
|
---|
280 | throw new ArgumentException("No structure template defined!");
|
---|
281 |
|
---|
282 | var tree = BuildTreeFromIndividual(templateTree, individual, containsNumericParameters: StructureTemplate.ContainsNumericParameters);
|
---|
283 | individual[SymbolicExpressionTreeName] = tree;
|
---|
284 |
|
---|
285 | if (OptimizeParameters) {
|
---|
286 | var excludeNodes = GetTemplateTreeNodes(tree.Root).OfType<IVariableTreeNode>();
|
---|
287 | ParameterOptimization.OptimizeTreeParameters(ProblemData, tree, interpreter: Interpreter, excludeNodes: excludeNodes);
|
---|
288 | } else if (ApplyLinearScaling) {
|
---|
289 | LinearScaling.AdjustLinearScalingParams(ProblemData, tree, Interpreter);
|
---|
290 | }
|
---|
291 |
|
---|
292 | UpdateIndividualFromTree(tree, individual, containsNumericParameters: StructureTemplate.ContainsNumericParameters);
|
---|
293 |
|
---|
294 | //calculate NMSE
|
---|
295 | var estimatedValues = Interpreter.GetSymbolicExpressionTreeValues(tree, ProblemData.Dataset, ProblemData.TrainingIndices);
|
---|
296 | var boundedEstimatedValues = estimatedValues.LimitToRange(EstimationLimits.Lower, EstimationLimits.Upper);
|
---|
297 | var targetValues = ProblemData.TargetVariableTrainingValues;
|
---|
298 | var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState);
|
---|
299 | if (errorState != OnlineCalculatorError.None)
|
---|
300 | nmse = 1.0;
|
---|
301 |
|
---|
302 | //evaluate constraints
|
---|
303 | var constraints = Enumerable.Empty<ShapeConstraint>();
|
---|
304 | if (ProblemData is ShapeConstrainedRegressionProblemData scProbData)
|
---|
305 | constraints = scProbData.ShapeConstraints.EnabledConstraints;
|
---|
306 | if (constraints.Any()) {
|
---|
307 | var boundsEstimator = new IntervalArithBoundsEstimator();
|
---|
308 | var constraintViolations = IntervalUtil.GetConstraintViolations(constraints, boundsEstimator, ProblemData.VariableRanges, tree);
|
---|
309 |
|
---|
310 | // infinite/NaN constraints
|
---|
311 | if (constraintViolations.Any(x => double.IsNaN(x) || double.IsInfinity(x)))
|
---|
312 | nmse = 1.0;
|
---|
313 |
|
---|
314 | if (constraintViolations.Any(x => x > 0.0))
|
---|
315 | nmse = 1.0;
|
---|
316 | }
|
---|
317 |
|
---|
318 | return nmse;
|
---|
319 | }
|
---|
320 |
|
---|
321 | private static IEnumerable<ISymbolicExpressionTreeNode> GetTemplateTreeNodes(ISymbolicExpressionTreeNode rootNode) {
|
---|
322 | yield return rootNode;
|
---|
323 | foreach (var node in rootNode.Subtrees) {
|
---|
324 | if (node is SubFunctionTreeNode) {
|
---|
325 | yield return node;
|
---|
326 | continue;
|
---|
327 | }
|
---|
328 |
|
---|
329 | foreach (var subNode in GetTemplateTreeNodes(node))
|
---|
330 | yield return subNode;
|
---|
331 | }
|
---|
332 | }
|
---|
333 |
|
---|
334 | private static ISymbolicExpressionTree BuildTreeFromIndividual(ISymbolicExpressionTree template, Individual individual, bool containsNumericParameters) {
|
---|
335 | var resolvedTree = (ISymbolicExpressionTree)template.Clone();
|
---|
336 |
|
---|
337 | //set numeric parameter values
|
---|
338 | if (containsNumericParameters) {
|
---|
339 | var realVector = individual.RealVector(NumericParametersEncoding);
|
---|
340 | var numberTreeNodes = resolvedTree.IterateNodesPrefix().OfType<NumberTreeNode>().ToArray();
|
---|
341 |
|
---|
342 | if (realVector.Length != numberTreeNodes.Length)
|
---|
343 | throw new InvalidOperationException("The number of numeric parameters in the tree does not match the provided numerical values.");
|
---|
344 |
|
---|
345 | for (int i = 0; i < numberTreeNodes.Length; i++)
|
---|
346 | numberTreeNodes[i].Value = realVector[i];
|
---|
347 | }
|
---|
348 |
|
---|
349 | // build main tree
|
---|
350 | foreach (var subFunctionTreeNode in resolvedTree.IterateNodesPrefix().OfType<SubFunctionTreeNode>()) {
|
---|
351 | var subFunctionTree = individual.SymbolicExpressionTree(subFunctionTreeNode.Name);
|
---|
352 |
|
---|
353 | // extract function tree
|
---|
354 | var subTree = subFunctionTree.Root.GetSubtree(0) // StartSymbol
|
---|
355 | .GetSubtree(0); // First Symbol
|
---|
356 | subTree = (ISymbolicExpressionTreeNode)subTree.Clone();
|
---|
357 | subFunctionTreeNode.AddSubtree(subTree);
|
---|
358 | }
|
---|
359 | return resolvedTree;
|
---|
360 | }
|
---|
361 |
|
---|
362 | private static void UpdateIndividualFromTree(ISymbolicExpressionTree tree, Individual individual, bool containsNumericParameters) {
|
---|
363 | var clonedTree = (ISymbolicExpressionTree)tree.Clone();
|
---|
364 |
|
---|
365 | foreach (var subFunctionTreeNode in clonedTree.IterateNodesPrefix().OfType<SubFunctionTreeNode>()) {
|
---|
366 | var grammar = ((ISymbolicExpressionTree)individual[subFunctionTreeNode.Name]).Root.Grammar;
|
---|
367 | var functionTreeNode = subFunctionTreeNode.GetSubtree(0);
|
---|
368 | //remove function code to make numeric parameters extraction easier
|
---|
369 | subFunctionTreeNode.RemoveSubtree(0);
|
---|
370 |
|
---|
371 |
|
---|
372 | var rootNode = (SymbolicExpressionTreeTopLevelNode)new ProgramRootSymbol().CreateTreeNode();
|
---|
373 | rootNode.SetGrammar(grammar);
|
---|
374 | var startNode = (SymbolicExpressionTreeTopLevelNode)new StartSymbol().CreateTreeNode();
|
---|
375 | startNode.SetGrammar(grammar);
|
---|
376 |
|
---|
377 | rootNode.AddSubtree(startNode);
|
---|
378 | startNode.AddSubtree(functionTreeNode);
|
---|
379 | var functionTree = new SymbolicExpressionTree(rootNode);
|
---|
380 | individual[subFunctionTreeNode.Name] = functionTree;
|
---|
381 | }
|
---|
382 |
|
---|
383 | //set numeric parameter values
|
---|
384 | if (containsNumericParameters) {
|
---|
385 | var realVector = individual.RealVector(NumericParametersEncoding);
|
---|
386 | var numberTreeNodes = clonedTree.IterateNodesPrefix().OfType<NumberTreeNode>().ToArray();
|
---|
387 |
|
---|
388 | if (realVector.Length != numberTreeNodes.Length)
|
---|
389 | throw new InvalidOperationException("The number of numeric parameters in the tree does not match the provided numerical values.");
|
---|
390 |
|
---|
391 | for (int i = 0; i < numberTreeNodes.Length; i++)
|
---|
392 | realVector[i] = numberTreeNodes[i].Value;
|
---|
393 | }
|
---|
394 | }
|
---|
395 |
|
---|
396 | public void Load(IRegressionProblemData data) {
|
---|
397 | ProblemData = data;
|
---|
398 | }
|
---|
399 | }
|
---|
400 | }
|
---|