Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14390 for trunk


Ignore:
Timestamp:
11/15/16 20:09:41 (8 years ago)
Author:
gkronber
Message:

#2697:

  • renaming of folder "Transformation" to "Converters" to distinguish between transformations for variables (from data preprocessing) and classes for transformation of trees.
  • renamed SymbolicDataAnalysisExpressionTreeSimplifier -> TreeSimplifier
  • Implemented a converter to create a linar model as a symbolic expression tree
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  
    8181      int nRows = inputMatrix.GetLength(0);
    8282      int nFeatures = inputMatrix.GetLength(1) - 1;
    83       double[] coefficients = new double[nFeatures + 1]; // last coefficient is for the constant
     83      double[] coefficients;
    8484
    8585      int retVal = 1;
     
    9191      alglib.lrunpack(lm, out coefficients, out nFeatures);
    9292
    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]);
    11195
    11296      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  
    5353      //check inputVariables used in the symbolic regression model
    5454      var usedVariables =
    55         Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<VariableTreeNode>().Select(
    56           node => node.VariableName).Distinct();
     55        Content.Model.VariablesUsedForPrediction;
    5756      foreach (var variable in usedVariables) {
    5857        problemData.InputVariables.SetItemCheckedState(
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r14378 r14390  
    158158      double[] constants;
    159159
    160       TreeToAutoDiffTermTransformator.ParametricFunction func;
    161       TreeToAutoDiffTermTransformator.ParametricFunctionGradient func_grad;
    162       if (!TreeToAutoDiffTermTransformator.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))
    163163        throw new NotSupportedException("Could not optimize constants of symbolic expression tree due to not supported symbols used in the tree.");
    164164      if (variableNames.Length == 0) return 0.0;
     
    231231    }
    232232
    233     private static alglib.ndimensional_pfunc CreatePFunc(TreeToAutoDiffTermTransformator.ParametricFunction func) {
     233    private static alglib.ndimensional_pfunc CreatePFunc(TreeToAutoDiffTermConverter.ParametricFunction func) {
    234234      return (double[] c, double[] x, ref double fx, object o) => {
    235235        fx = func(c, x);
     
    237237    }
    238238
    239     private static alglib.ndimensional_pgrad CreatePGrad(TreeToAutoDiffTermTransformator.ParametricFunctionGradient func_grad) {
     239    private static alglib.ndimensional_pgrad CreatePGrad(TreeToAutoDiffTermConverter.ParametricFunctionGradient func_grad) {
    240240      return (double[] c, double[] x, ref double fx, double[] grad, object o) => {
    241241        var tupel = func_grad(c, x);
     
    246246
    247247    public static bool CanOptimizeConstants(ISymbolicExpressionTree tree) {
    248       return TreeToAutoDiffTermTransformator.IsCompatible(tree);
     248      return TreeToAutoDiffTermConverter.IsCompatible(tree);
    249249    }
    250250  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r14185 r14390  
    259259
    260260    private void btnSimplify_Click(object sender, EventArgs e) {
    261       var simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
     261      var simplifier = new TreeSimplifier();
    262262      var simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree);
    263263      UpdateModel(simplifiedExpressionTree);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs

    r14389 r14390  
    3030  /// Simplifier for symbolic expressions
    3131  /// </summary>
    32   public class SymbolicDataAnalysisExpressionTreeSimplifier {
     32  public class TreeSimplifier {
    3333    private Addition addSymbol = new Addition();
    3434    private Subtraction subSymbol = new Subtraction();
     
    716716        // fold constants
    717717        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)) {
    719720        return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a)));
    720721      } else if (IsVariable(a) && IsConstant(b)) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs

    r14389 r14390  
    2727
    2828namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    29   public class TreeToAutoDiffTermTransformator {
     29  public class TreeToAutoDiffTermConverter {
    3030    public delegate double ParametricFunction(double[] vars, double[] @params);
    3131    public delegate Tuple<double[], double> ParametricFunctionGradient(double[] vars, double[] @params);
     
    6060
    6161      // use a transformator object which holds the state (variable list, parameter list, ...) for recursive transformation of the tree
    62       var transformator = new TreeToAutoDiffTermTransformator(makeVariableWeightsVariable);
     62      var transformator = new TreeToAutoDiffTermConverter(makeVariableWeightsVariable);
    6363      AutoDiff.Term term;
    6464      var success = transformator.TryTransformToAutoDiff(tree.Root.GetSubtree(0), out term);
     
    8888    private readonly bool makeVariableWeightsVariable;
    8989
    90     private TreeToAutoDiffTermTransformator(bool makeVariableWeightsVariable) {
     90    private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable) {
    9191      this.makeVariableWeightsVariable = makeVariableWeightsVariable;
    9292      this.variableNames = new List<string>();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r14185 r14390  
    5151      while (dividend > 0) {
    5252        int modulo = (dividend - 1) % 26;
    53         columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
     53        columnName = System.Convert.ToChar(65 + modulo).ToString() + columnName;
    5454        dividend = (int)((dividend - modulo) / 26);
    5555      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r14378 r14390  
    137137      <SubType>Code</SubType>
    138138    </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" />
    139143    <Compile Include="Formatters\InfixExpressionFormatter.cs" />
    140144    <Compile Include="Formatters\SymbolicDataAnalysisExpressionMathematicaFormatter.cs" />
     
    242246    <Compile Include="Symbols\VariableConditionTreeNode.cs" />
    243247    <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" />
    248250    <Compile Include="TreeMatching\SymbolicExpressionTreeBottomUpSimilarityCalculator.cs" />
    249251    <Compile Include="TreeMatching\SymbolicExpressionTreeCanonicalSorter.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs

    r14185 r14390  
    3737    }
    3838
    39     private readonly SymbolicDataAnalysisExpressionTreeSimplifier simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
     39    private readonly TreeSimplifier simplifier = new TreeSimplifier();
    4040
    4141    [StorableConstructor]
Note: See TracChangeset for help on using the changeset viewer.