- Timestamp:
- 08/10/16 20:10:25 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r14109 r14251 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;30 29 using HeuristicLab.Optimization; 31 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 93 92 var parser = new InfixExpressionParser(); 94 93 var tree = parser.Parse(modelStructure); 95 var simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier(); 96 94 // parser handles double and string variables equally by creating a VariableTreeNode 95 // post-process to replace VariableTreeNodes by FactorVariableTreeNodes for all string variables 96 var factorSymbol = new FactorVariable(); 97 factorSymbol.VariableNames = 98 problemData.AllowedInputVariables.Where(name => problemData.Dataset.VariableHasType<string>(name)); 99 factorSymbol.AllVariableNames = factorSymbol.VariableNames; 100 factorSymbol.VariableValues = 101 factorSymbol.VariableNames.Select(name => new KeyValuePair<string, List<string>>(name, problemData.Dataset.GetReadOnlyStringValues(name).Distinct().ToList())); 102 103 foreach (var parent in tree.IterateNodesPrefix().ToArray()) { 104 for (int i = 0; i < parent.SubtreeCount; i++) { 105 var child = parent.GetSubtree(i) as VariableTreeNode; 106 if (child != null && factorSymbol.VariableNames.Contains(child.VariableName)) { 107 parent.RemoveSubtree(i); 108 var factorTreeNode = (FactorVariableTreeNode)factorSymbol.CreateTreeNode(); 109 factorTreeNode.VariableName = child.VariableName; 110 factorTreeNode.Weights = 111 factorTreeNode.Symbol.GetVariableValues(factorTreeNode.VariableName).Select(_ => 1.0).ToArray(); // weight = 1.0 for each value 112 parent.InsertSubtree(i, factorTreeNode); 113 } 114 } 115 } 116 97 117 if (!SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)) throw new ArgumentException("The optimizer does not support the specified model structure."); 98 118 99 119 var interpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter(); 100 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, 120 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, 101 121 applyLinearScaling: false, maxIterations: maxIterations, 102 122 updateVariableWeights: false, updateConstantsInTree: true);
Note: See TracChangeset
for help on using the changeset viewer.