Changeset 14390
- Timestamp:
- 11/15/16 20:09:41 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 added
- 2 deleted
- 7 edited
- 2 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r14185 r14390 81 81 int nRows = inputMatrix.GetLength(0); 82 82 int nFeatures = inputMatrix.GetLength(1) - 1; 83 double[] coefficients = new double[nFeatures + 1]; // last coefficient is for the constant83 double[] coefficients; 84 84 85 85 int retVal = 1; … … 91 91 alglib.lrunpack(lm, out coefficients, out nFeatures); 92 92 93 ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode()); 94 ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode(); 95 tree.Root.AddSubtree(startNode); 96 ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode(); 97 startNode.AddSubtree(addition); 98 99 int col = 0; 100 foreach (string column in allowedInputVariables) { 101 VariableTreeNode vNode = (VariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable().CreateTreeNode(); 102 vNode.VariableName = column; 103 vNode.Weight = coefficients[col]; 104 addition.AddSubtree(vNode); 105 col++; 106 } 107 108 ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode(); 109 cNode.Value = coefficients[coefficients.Length - 1]; 110 addition.AddSubtree(cNode); 93 var tree = LinearModelToTreeConverter.CreateTree(allowedInputVariables.ToArray(), 94 coefficients.Take(nFeatures).ToArray(), @const: coefficients[nFeatures]); 111 95 112 96 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), (IRegressionProblemData)problemData.Clone()); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs
r14185 r14390 53 53 //check inputVariables used in the symbolic regression model 54 54 var usedVariables = 55 Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<VariableTreeNode>().Select( 56 node => node.VariableName).Distinct(); 55 Content.Model.VariablesUsedForPrediction; 57 56 foreach (var variable in usedVariables) { 58 57 problemData.InputVariables.SetItemCheckedState( -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r14378 r14390 158 158 double[] constants; 159 159 160 TreeToAutoDiffTerm Transformator.ParametricFunction func;161 TreeToAutoDiffTerm Transformator.ParametricFunctionGradient func_grad;162 if (!TreeToAutoDiffTerm Transformator.TryTransformToAutoDiff(tree, updateVariableWeights, out variableNames, out lags, out constants, out func, out func_grad))160 TreeToAutoDiffTermConverter.ParametricFunction func; 161 TreeToAutoDiffTermConverter.ParametricFunctionGradient func_grad; 162 if (!TreeToAutoDiffTermConverter.TryTransformToAutoDiff(tree, updateVariableWeights, out variableNames, out lags, out constants, out func, out func_grad)) 163 163 throw new NotSupportedException("Could not optimize constants of symbolic expression tree due to not supported symbols used in the tree."); 164 164 if (variableNames.Length == 0) return 0.0; … … 231 231 } 232 232 233 private static alglib.ndimensional_pfunc CreatePFunc(TreeToAutoDiffTerm Transformator.ParametricFunction func) {233 private static alglib.ndimensional_pfunc CreatePFunc(TreeToAutoDiffTermConverter.ParametricFunction func) { 234 234 return (double[] c, double[] x, ref double fx, object o) => { 235 235 fx = func(c, x); … … 237 237 } 238 238 239 private static alglib.ndimensional_pgrad CreatePGrad(TreeToAutoDiffTerm Transformator.ParametricFunctionGradient func_grad) {239 private static alglib.ndimensional_pgrad CreatePGrad(TreeToAutoDiffTermConverter.ParametricFunctionGradient func_grad) { 240 240 return (double[] c, double[] x, ref double fx, double[] grad, object o) => { 241 241 var tupel = func_grad(c, x); … … 246 246 247 247 public static bool CanOptimizeConstants(ISymbolicExpressionTree tree) { 248 return TreeToAutoDiffTerm Transformator.IsCompatible(tree);248 return TreeToAutoDiffTermConverter.IsCompatible(tree); 249 249 } 250 250 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r14185 r14390 259 259 260 260 private void btnSimplify_Click(object sender, EventArgs e) { 261 var simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();261 var simplifier = new TreeSimplifier(); 262 262 var simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree); 263 263 UpdateModel(simplifiedExpressionTree); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs
r14389 r14390 30 30 /// Simplifier for symbolic expressions 31 31 /// </summary> 32 public class SymbolicDataAnalysisExpressionTreeSimplifier {32 public class TreeSimplifier { 33 33 private Addition addSymbol = new Addition(); 34 34 private Subtraction subSymbol = new Subtraction(); … … 716 716 // fold constants 717 717 return MakeConstant(((ConstantTreeNode)a).Value / ((ConstantTreeNode)b).Value); 718 } if (IsConstant(a) && !((ConstantTreeNode)a).Value.IsAlmost(1.0)) { 718 } 719 if (IsConstant(a) && !((ConstantTreeNode)a).Value.IsAlmost(1.0)) { 719 720 return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a))); 720 721 } else if (IsVariable(a) && IsConstant(b)) { -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
r14389 r14390 27 27 28 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 29 public class TreeToAutoDiffTerm Transformator {29 public class TreeToAutoDiffTermConverter { 30 30 public delegate double ParametricFunction(double[] vars, double[] @params); 31 31 public delegate Tuple<double[], double> ParametricFunctionGradient(double[] vars, double[] @params); … … 60 60 61 61 // use a transformator object which holds the state (variable list, parameter list, ...) for recursive transformation of the tree 62 var transformator = new TreeToAutoDiffTerm Transformator(makeVariableWeightsVariable);62 var transformator = new TreeToAutoDiffTermConverter(makeVariableWeightsVariable); 63 63 AutoDiff.Term term; 64 64 var success = transformator.TryTransformToAutoDiff(tree.Root.GetSubtree(0), out term); … … 88 88 private readonly bool makeVariableWeightsVariable; 89 89 90 private TreeToAutoDiffTerm Transformator(bool makeVariableWeightsVariable) {90 private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable) { 91 91 this.makeVariableWeightsVariable = makeVariableWeightsVariable; 92 92 this.variableNames = new List<string>(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r14185 r14390 51 51 while (dividend > 0) { 52 52 int modulo = (dividend - 1) % 26; 53 columnName = Convert.ToChar(65 + modulo).ToString() + columnName;53 columnName = System.Convert.ToChar(65 + modulo).ToString() + columnName; 54 54 dividend = (int)((dividend - modulo) / 26); 55 55 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r14378 r14390 137 137 <SubType>Code</SubType> 138 138 </Compile> 139 <Compile Include="Converters\Convert.cs" /> 140 <Compile Include="Converters\LinearModelToTreeConverter.cs" /> 141 <Compile Include="Converters\TreeSimplifier.cs" /> 142 <Compile Include="Converters\TreeToAutoDiffTermConverter.cs" /> 139 143 <Compile Include="Formatters\InfixExpressionFormatter.cs" /> 140 144 <Compile Include="Formatters\SymbolicDataAnalysisExpressionMathematicaFormatter.cs" /> … … 242 246 <Compile Include="Symbols\VariableConditionTreeNode.cs" /> 243 247 <Compile Include="Symbols\VariableTreeNode.cs" /> 244 <Compile Include="Transformation\SymbolicDataAnalysisExpressionTreeSimplifier.cs" /> 245 <Compile Include="Transformation\SymbolicExpressionTreeBacktransformator.cs" /> 246 <Compile Include="Transformation\TreeToAutoDiffTermTransformator.cs" /> 247 <Compile Include="Transformation\TransformationToSymbolicTreeMapper.cs" /> 248 <Compile Include="Transformations\SymbolicExpressionTreeBacktransformator.cs" /> 249 <Compile Include="Transformations\TransformationToSymbolicTreeMapper.cs" /> 248 250 <Compile Include="TreeMatching\SymbolicExpressionTreeBottomUpSimilarityCalculator.cs" /> 249 251 <Compile Include="TreeMatching\SymbolicExpressionTreeCanonicalSorter.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs
r14185 r14390 37 37 } 38 38 39 private readonly SymbolicDataAnalysisExpressionTreeSimplifier simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();39 private readonly TreeSimplifier simplifier = new TreeSimplifier(); 40 40 41 41 [StorableConstructor]
Note: See TracChangeset
for help on using the changeset viewer.