[7832] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 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 |
|
---|
[8206] | 22 | using System;
|
---|
[7832] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 29 | using HeuristicLab.Operators;
|
---|
| 30 | using HeuristicLab.Optimization;
|
---|
| 31 | using HeuristicLab.Parameters;
|
---|
| 32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
|
---|
| 35 | [Item("ReplaceBranchMultiMoveGenerator", "")]
|
---|
| 36 | [StorableClass]
|
---|
| 37 | public class ReplaceBranchMultiMoveGenerator : SingleSuccessorOperator, IStochasticOperator, ISymbolicExpressionTreeMoveOperator, IMultiMoveGenerator,
|
---|
[8214] | 38 | ISymbolicDataAnalysisInterpreterOperator, ISymbolicExpressionTreeGrammarBasedOperator, ISymbolicExpressionTreeSizeConstraintOperator {
|
---|
[7832] | 39 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 40 | get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
|
---|
| 41 | }
|
---|
| 42 | public IValueLookupParameter<IntValue> SampleSizeParameter {
|
---|
| 43 | get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
|
---|
| 44 | }
|
---|
| 45 | public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
|
---|
| 46 | get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters["Interpreter"]; }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
|
---|
| 50 | get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters["Grammar"]; }
|
---|
| 51 | }
|
---|
| 52 | public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
|
---|
| 53 | get { return (ILookupParameter<IRegressionProblemData>)Parameters["ProblemData"]; }
|
---|
| 54 | }
|
---|
| 55 | public IntValue SampleSize {
|
---|
| 56 | get { return SampleSizeParameter.Value; }
|
---|
| 57 | set { SampleSizeParameter.Value = value; }
|
---|
| 58 | }
|
---|
| 59 | public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
|
---|
| 60 | get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
|
---|
| 61 | }
|
---|
| 62 | public ILookupParameter<ReplaceBranchMove> ReplaceBranchMoveParameter {
|
---|
| 63 | get { return (LookupParameter<ReplaceBranchMove>)Parameters["ReplaceBranchMove"]; }
|
---|
| 64 | }
|
---|
[8206] | 65 |
|
---|
| 66 | public IValueParameter<IntValue> ReplacementBranchesPoolSize {
|
---|
| 67 | get { return (IValueParameter<IntValue>)Parameters["ReplacementBranchesPoolSize"]; }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public IValueParameter<IntValue> MaxReplacementBranchLength {
|
---|
| 71 | get { return (IValueParameter<IntValue>)Parameters["MaxReplacementBranchLength"]; }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public IValueParameter<IntValue> MaxReplacementBranchDepth {
|
---|
| 75 | get { return (IValueParameter<IntValue>)Parameters["MaxReplacementBranchDepth"]; }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[7832] | 78 | protected ScopeParameter CurrentScopeParameter {
|
---|
| 79 | get { return (ScopeParameter)Parameters["CurrentScope"]; }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[8214] | 82 | public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
|
---|
| 83 | get { return (IValueLookupParameter<IntValue>)Parameters["MaximumSymbolicExpressionTreeDepth"]; }
|
---|
| 84 | }
|
---|
[7832] | 85 |
|
---|
[8214] | 86 | public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
|
---|
| 87 | get { return (IValueLookupParameter<IntValue>)Parameters["MaximumSymbolicExpressionTreeLength"]; }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | public IValueLookupParameter<IntValue> NeighbourhoodSizeParameter {
|
---|
| 91 | get { return (IValueLookupParameter<IntValue>)Parameters["NeighbourhoodSize"]; }
|
---|
| 92 | }
|
---|
[8286] | 93 | public IValueLookupParameter<BoolValue> SemanticParameter {
|
---|
| 94 | get { return (IValueLookupParameter<BoolValue>)Parameters["Semantic"]; }
|
---|
| 95 | }
|
---|
[8292] | 96 | public ILookupParameter<ItemList<ISymbolicExpressionTree>> FragmentsParameter {
|
---|
| 97 | get { return (ILookupParameter<ItemList<ISymbolicExpressionTree>>)Parameters["Fragments"]; }
|
---|
| 98 | }
|
---|
| 99 | public ILookupParameter<ItemList<DoubleArray>> FragmentOutputsParameter {
|
---|
| 100 | get { return (ILookupParameter<ItemList<DoubleArray>>)Parameters["FragmentOutputs"]; }
|
---|
| 101 | }
|
---|
[8214] | 102 |
|
---|
[7832] | 103 | [StorableConstructor]
|
---|
| 104 | protected ReplaceBranchMultiMoveGenerator(bool deserializing) : base(deserializing) { }
|
---|
| 105 | protected ReplaceBranchMultiMoveGenerator(ReplaceBranchMultiMoveGenerator original, Cloner cloner) : base(original, cloner) { }
|
---|
| 106 | public ReplaceBranchMultiMoveGenerator()
|
---|
| 107 | : base() {
|
---|
| 108 | Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
|
---|
| 109 | Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
|
---|
| 110 |
|
---|
| 111 | Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic expression tree for which moves should be generated."));
|
---|
| 112 | Parameters.Add(new LookupParameter<ReplaceBranchMove>("ReplaceBranchMove", "The moves that should be generated in subscopes."));
|
---|
| 113 | Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
|
---|
| 114 | Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>("Grammar"));
|
---|
| 115 | Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>("Interpreter"));
|
---|
| 116 | Parameters.Add(new LookupParameter<IRegressionProblemData>("ProblemData"));
|
---|
[8206] | 117 | Parameters.Add(new ValueParameter<IntValue>("ReplacementBranchesPoolSize", new IntValue(10000)));
|
---|
| 118 | Parameters.Add(new ValueParameter<IntValue>("MaxReplacementBranchLength", new IntValue(8)));
|
---|
| 119 | Parameters.Add(new ValueParameter<IntValue>("MaxReplacementBranchDepth", new IntValue(4)));
|
---|
[8214] | 120 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumSymbolicExpressionTreeDepth"));
|
---|
| 121 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumSymbolicExpressionTreeLength"));
|
---|
| 122 | Parameters.Add(new ValueLookupParameter<IntValue>("NeighbourhoodSize", new IntValue(5)));
|
---|
[8286] | 123 | Parameters.Add(new ValueLookupParameter<BoolValue>("Semantic", new BoolValue()));
|
---|
[8292] | 124 | Parameters.Add(new LookupParameter<ItemList<ISymbolicExpressionTree>>("Fragments"));
|
---|
| 125 | Parameters.Add(new LookupParameter<ItemList<DoubleArray>>("FragmentOutputs"));
|
---|
[7832] | 126 | }
|
---|
| 127 |
|
---|
[8214] | 128 |
|
---|
| 129 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 130 | private void AfterDeserialization() {
|
---|
| 131 | if (!Parameters.ContainsKey("MaximumSymbolicExpressionTreeDepth")) {
|
---|
| 132 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumSymbolicExpressionTreeDepth"));
|
---|
| 133 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumSymbolicExpressionTreeLength"));
|
---|
| 134 | }
|
---|
| 135 | if (!Parameters.ContainsKey("NeighbourhoodSize")) {
|
---|
| 136 | Parameters.Add(new ValueLookupParameter<IntValue>("NeighbourhoodSize", new IntValue(5)));
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 |
|
---|
[7832] | 142 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 143 | return new ReplaceBranchMultiMoveGenerator(this, cloner);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | public override IOperation Apply() {
|
---|
| 147 | var random = RandomParameter.ActualValue;
|
---|
[8292] | 148 | if (FragmentsParameter.ActualValue == null || FragmentOutputsParameter.ActualValue == null) {
|
---|
[7832] | 149 | InitializeOperator();
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | var tree = SymbolicExpressionTreeParameter.ActualValue;
|
---|
| 153 |
|
---|
| 154 | string moveParameterName = ReplaceBranchMoveParameter.ActualName;
|
---|
| 155 | var moveScopes = new List<Scope>();
|
---|
| 156 | int n = SampleSizeParameter.ActualValue.Value;
|
---|
| 157 |
|
---|
| 158 | var moves = GenerateMoves(tree, random, n);
|
---|
| 159 |
|
---|
| 160 | foreach (var m in moves) {
|
---|
| 161 | var moveScope = new Scope(moveScopes.Count.ToString());
|
---|
| 162 | moveScope.Variables.Add(new HeuristicLab.Core.Variable(moveParameterName, m));
|
---|
| 163 | moveScopes.Add(moveScope);
|
---|
| 164 | }
|
---|
| 165 | CurrentScopeParameter.ActualValue.SubScopes.AddRange(moveScopes);
|
---|
| 166 | return base.Apply();
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | public IEnumerable<ReplaceBranchMove> GenerateMoves(ISymbolicExpressionTree tree, IRandom random, int n) {
|
---|
[8286] | 170 | int maxDepth = MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value;
|
---|
| 171 | int maxLength = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
|
---|
[8292] | 172 | var possibleInternalChildren = (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix()
|
---|
[8286] | 173 | from i in Enumerable.Range(0, parent.SubtreeCount)
|
---|
| 174 | let currentChild = parent.GetSubtree(i)
|
---|
| 175 | where currentChild.SubtreeCount > 0
|
---|
[8292] | 176 | where tree.Root.GetBranchLevel(currentChild) < maxDepth + 2
|
---|
[8286] | 177 | where tree.Length - currentChild.GetLength() < maxLength
|
---|
| 178 | select new CutPoint(parent, i)).ToArray();
|
---|
[7832] | 179 |
|
---|
[8292] | 180 | var possibleLeaveChildren = (from parent in tree.Root.GetSubtree(0).IterateNodesPrefix()
|
---|
[8286] | 181 | from i in Enumerable.Range(0, parent.SubtreeCount)
|
---|
| 182 | let currentChild = parent.GetSubtree(i)
|
---|
| 183 | where currentChild.SubtreeCount == 0
|
---|
[8292] | 184 | where tree.Root.GetBranchLevel(currentChild) < maxDepth + 2
|
---|
[8286] | 185 | where tree.Length - 1 < maxLength
|
---|
| 186 | select new CutPoint(parent, i)).ToArray();
|
---|
[8292] | 187 | if (possibleInternalChildren.Length == 0) possibleInternalChildren = possibleLeaveChildren;
|
---|
| 188 | if (possibleLeaveChildren.Length == 0) possibleLeaveChildren = possibleInternalChildren;
|
---|
[8286] | 189 |
|
---|
[7832] | 190 | var root = (new ProgramRootSymbol()).CreateTreeNode();
|
---|
| 191 | var start = (new StartSymbol()).CreateTreeNode();
|
---|
| 192 | root.AddSubtree(start);
|
---|
| 193 | var t = new SymbolicExpressionTree(root);
|
---|
| 194 | var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
|
---|
| 195 | var ds = ProblemDataParameter.ActualValue.Dataset;
|
---|
[8207] | 196 | var rows = ProblemDataParameter.ActualValue.TrainingIndices;
|
---|
[7832] | 197 |
|
---|
[8286] | 198 | bool semantic = SemanticParameter.ActualValue.Value;
|
---|
[8292] | 199 | int maxNeighbours = NeighbourhoodSizeParameter.ActualValue.Value;
|
---|
| 200 | var count = 0;
|
---|
| 201 | while (count < n) {
|
---|
| 202 | // select a random replacement point
|
---|
| 203 | CutPoint[] possibleChildren;
|
---|
| 204 | if (random.NextDouble() < 0.9)
|
---|
| 205 | possibleChildren = possibleInternalChildren;
|
---|
| 206 | else possibleChildren = possibleLeaveChildren;
|
---|
| 207 | var selected = possibleChildren[random.Next(possibleChildren.Length)];
|
---|
| 208 | // evaluate
|
---|
| 209 | start.AddSubtree(selected.Parent.GetSubtree(selected.ChildIndex));
|
---|
| 210 | var output = interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray();
|
---|
| 211 | start.RemoveSubtree(0);
|
---|
[7832] | 212 |
|
---|
[8292] | 213 | if (semantic) {
|
---|
| 214 | foreach (var m in FindMostSimilarFragments(tree, maxLength, maxDepth, selected, random, maxNeighbours, output)) {
|
---|
| 215 | yield return m;
|
---|
| 216 | count++;
|
---|
| 217 | }
|
---|
| 218 | } else {
|
---|
| 219 | foreach (var m in FindRandomFragments(tree, maxLength, maxDepth, selected, random, maxNeighbours, output)) {
|
---|
| 220 | yield return m;
|
---|
| 221 | count++;
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
[8286] | 224 | }
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | private IEnumerable<ReplaceBranchMove> FindRandomFragments(ISymbolicExpressionTree tree, int maxLength, int maxDepth, CutPoint selected,
|
---|
| 228 | IRandom random, int maxNeighbours, double[] output) {
|
---|
[8292] | 229 | var selectedFragments = new List<int>(maxNeighbours);
|
---|
[8286] | 230 | int treeLength = tree.Length;
|
---|
| 231 | int removedFragementLength = selected.Parent.GetSubtree(selected.ChildIndex).GetLength();
|
---|
| 232 | int parentBranchLevel = tree.Root.GetBranchLevel(selected.Parent);
|
---|
| 233 | int iterations = 0;
|
---|
| 234 | int maxIterations = maxNeighbours + 100;
|
---|
[8292] | 235 | var fragments = FragmentsParameter.ActualValue;
|
---|
| 236 | var fragmentOutput = FragmentOutputsParameter.ActualValue;
|
---|
[8286] | 237 | // select random fragments
|
---|
| 238 | while (selectedFragments.Count < maxNeighbours && iterations++ < maxIterations) {
|
---|
| 239 | int r = random.Next(fragments.Count);
|
---|
| 240 | var selectedFragment = fragments[r];
|
---|
| 241 | var selectedFragmentOutput = fragmentOutput[r];
|
---|
| 242 | // if the branch is allowed in the selected point
|
---|
| 243 | if (treeLength - removedFragementLength + selectedFragment.Length <= maxLength + 4 &&
|
---|
| 244 | parentBranchLevel + selectedFragment.Depth - 2 <= maxDepth + 2 &&
|
---|
| 245 | tree.Root.Grammar.IsAllowedChildSymbol(selected.Parent.Symbol, selectedFragment.Root.GetSubtree(0).GetSubtree(0).Symbol, selected.ChildIndex)) {
|
---|
[8292] | 246 | selectedFragments.Add(r);
|
---|
[8286] | 247 | }
|
---|
| 248 | }
|
---|
| 249 | // yield moves (we need to add linear scaling parameters for the inserted tree)
|
---|
| 250 | return selectedFragments
|
---|
[8292] | 251 | .Select(i => new ReplaceBranchMove(tree, selected.Parent, selected.ChildIndex, fragments[i].Root.GetSubtree(0).GetSubtree(0), output, fragmentOutput[i].ToArray(), i));
|
---|
[8286] | 252 | }
|
---|
| 253 |
|
---|
| 254 | private IEnumerable<ReplaceBranchMove> FindMostSimilarFragments(ISymbolicExpressionTree tree, int maxLength, int maxDepth, CutPoint selected,
|
---|
| 255 | IRandom random, int maxNeighbours, double[] output) {
|
---|
[8292] | 256 | var fragments = FragmentsParameter.ActualValue;
|
---|
| 257 | var fragmentOutput = FragmentOutputsParameter.ActualValue;
|
---|
| 258 | var bestTrees = new SortedList<double, List<int>>(fragments.Count);
|
---|
[8286] | 259 | int treeLength = tree.Length;
|
---|
| 260 | int removedFragementLength = selected.Parent.GetSubtree(selected.ChildIndex).GetLength();
|
---|
| 261 | int parentBranchLevel = tree.Root.GetBranchLevel(selected.Parent);
|
---|
| 262 | // iterate over the whole pool of branches for replacement
|
---|
| 263 | for (int i = 0; i < fragments.Count; i++) {
|
---|
| 264 | // if the branch is allowed in the selected point
|
---|
| 265 | if (treeLength - removedFragementLength + fragments[i].Length <= maxLength + 4 &&
|
---|
| 266 | parentBranchLevel + fragments[i].Depth - 2 <= maxDepth + 2 &&
|
---|
| 267 | tree.Root.Grammar.IsAllowedChildSymbol(selected.Parent.Symbol, fragments[i].Root.GetSubtree(0).GetSubtree(0).Symbol, selected.ChildIndex)) {
|
---|
| 268 | OnlineCalculatorError error;
|
---|
| 269 | // calculate the similarity
|
---|
| 270 | double similarity = OnlinePearsonsRSquaredCalculator.Calculate(output, fragmentOutput[i], out error);
|
---|
| 271 | similarity = Math.Round(similarity, 5);
|
---|
| 272 | if (error != OnlineCalculatorError.None) similarity = 0.0;
|
---|
| 273 | // if we found a new bestSimilarity then keep the replacement branch in a sorted list (keep maximally the n best for this replacement point)
|
---|
| 274 | if (similarity < 1 && ((bestTrees.Count < maxNeighbours) || similarity > bestTrees.ElementAt(0).Key)) {
|
---|
| 275 | if (!bestTrees.ContainsKey(similarity)) {
|
---|
[8292] | 276 | var l = new List<int>();
|
---|
[8286] | 277 | bestTrees.Add(similarity, l);
|
---|
[8214] | 278 | }
|
---|
[8292] | 279 | bestTrees[similarity].Add(i);
|
---|
[8286] | 280 | if (bestTrees.Count > maxNeighbours) bestTrees.RemoveAt(0);
|
---|
[7832] | 281 | }
|
---|
| 282 | }
|
---|
| 283 | }
|
---|
[8286] | 284 | int c = 0;
|
---|
| 285 | // yield moves (we need to add linear scaling parameters for the inserted tree)
|
---|
| 286 | while (c < maxNeighbours) {
|
---|
| 287 | var l = bestTrees.ElementAt(c % bestTrees.Count).Value;
|
---|
[8292] | 288 | var index = l[random.Next(l.Count)];
|
---|
[8286] | 289 | yield return
|
---|
[8292] | 290 | new ReplaceBranchMove(tree, selected.Parent, selected.ChildIndex, fragments[index].Root.GetSubtree(0).GetSubtree(0),
|
---|
| 291 | output, fragmentOutput[index].ToArray(), index);
|
---|
[8286] | 292 | c++;
|
---|
| 293 | }
|
---|
[7832] | 294 | }
|
---|
| 295 |
|
---|
| 296 | private void InitializeOperator() {
|
---|
[8206] | 297 | // init locally and set only at the end in case of exceptions
|
---|
| 298 | var trees = new List<ISymbolicExpressionTree>();
|
---|
| 299 | var treeOutput = new List<double[]>();
|
---|
[7832] | 300 | var random = RandomParameter.ActualValue;
|
---|
| 301 | var g = SymbolicExpressionTreeGrammarParameter.ActualValue;
|
---|
[8206] | 302 | var constSym = g.Symbols.Single(s => s is Constant);
|
---|
[7832] | 303 | // temporarily disable constants
|
---|
| 304 | double oldConstFreq = constSym.InitialFrequency;
|
---|
| 305 | constSym.InitialFrequency = 0.0;
|
---|
| 306 | var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
|
---|
| 307 | var ds = ProblemDataParameter.ActualValue.Dataset;
|
---|
[8207] | 308 | var rows = ProblemDataParameter.ActualValue.TrainingIndices;
|
---|
[8206] | 309 | // create pool of random branches for replacement (no constants)
|
---|
| 310 | // and evaluate the output
|
---|
[8214] | 311 | // only keep fragments if the output does not contain invalid values
|
---|
[8206] | 312 | var n = ReplacementBranchesPoolSize.Value.Value;
|
---|
| 313 | while (trees.Count < n) {
|
---|
| 314 | var t = ProbabilisticTreeCreator.Create(random, g, MaxReplacementBranchLength.Value.Value, MaxReplacementBranchDepth.Value.Value);
|
---|
[7832] | 315 | var output = interpreter.GetSymbolicExpressionTreeValues(t, ds, rows);
|
---|
[8206] | 316 | if (!output.Any(x => double.IsInfinity(x) || double.IsNaN(x))) {
|
---|
| 317 | trees.Add(t);
|
---|
| 318 | treeOutput.Add(output.ToArray());
|
---|
| 319 | }
|
---|
[7832] | 320 | }
|
---|
| 321 | // enable constants again
|
---|
| 322 | constSym.InitialFrequency = oldConstFreq;
|
---|
[8292] | 323 | // set parameters
|
---|
| 324 | FragmentsParameter.ActualValue = new ItemList<ISymbolicExpressionTree>(trees);
|
---|
| 325 | FragmentOutputsParameter.ActualValue = new ItemList<DoubleArray>(treeOutput.Select(a => new DoubleArray(a)));
|
---|
[7832] | 326 | }
|
---|
| 327 | }
|
---|
| 328 | }
|
---|