Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/01/21 13:40:55 (3 years ago)
Author:
chaider
Message:

#3140

  • some more refactoring
  • added possibility to set value of num nodes in infix parser
  • changed displaying style of number
Location:
branches/3140_NumberSymbol/HeuristicLab.Algorithms.DataAnalysis/3.4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/3140_NumberSymbol/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs

    r17180 r18100  
    417417      var addNode = new Addition().CreateTreeNode();
    418418      var mulNode = new Multiplication().CreateTreeNode();
    419       var scaleNode = (ConstantTreeNode)new Constant().CreateTreeNode(); // all models are scaled using the same nu
     419      var scaleNode = (NumberTreeNode)new Number().CreateTreeNode(); // all models are scaled using the same nu
    420420      scaleNode.Value = nu;
    421421
  • branches/3140_NumberSymbol/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs

    r17180 r18100  
    230230      var startSy = new StartSymbol();
    231231      var varCondSy = new VariableCondition() { IgnoreSlope = true };
    232       var constSy = new Constant();
     232      var numSy = new Number();
    233233
    234234      var startNode = startSy.CreateTreeNode();
    235       startNode.AddSubtree(CreateSymbolicRegressionTreeRecursive(tree, 0, varCondSy, constSy));
     235      startNode.AddSubtree(CreateSymbolicRegressionTreeRecursive(tree, 0, varCondSy, numSy));
    236236      var rootNode = rootSy.CreateTreeNode();
    237237      rootNode.AddSubtree(startNode);
     
    239239    }
    240240
    241     private ISymbolicExpressionTreeNode CreateSymbolicRegressionTreeRecursive(TreeNode[] treeNodes, int nodeIdx, VariableCondition varCondSy, Constant constSy) {
     241    private ISymbolicExpressionTreeNode CreateSymbolicRegressionTreeRecursive(TreeNode[] treeNodes, int nodeIdx, VariableCondition varCondSy, Number constSy) {
    242242      var curNode = treeNodes[nodeIdx];
    243243      if (curNode.VarName == TreeNode.NO_VARIABLE) {
    244         var node = (ConstantTreeNode)constSy.CreateTreeNode();
     244        var node = (NumberTreeNode)constSy.CreateTreeNode();
    245245        node.Value = curNode.Val;
    246246        return node;
  • branches/3140_NumberSymbol/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs

    r17180 r18100  
    123123      : base() {
    124124      Problem = new RegressionProblem();
    125       Parameters.Add(new FixedValueParameter<StringValue>(ModelStructureParameterName, "The function for which the parameters must be fit (only numeric constants are tuned).", new StringValue("1.0 * x*x + 0.0")));
     125      Parameters.Add(new FixedValueParameter<StringValue>(ModelStructureParameterName, "The function for which the parameters must be fit (only numeric constants are tuned).", new StringValue("<num> * x*x + 0.0")));
    126126      Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "The maximum number of iterations for constants optimization.", new IntValue(200)));
    127127      Parameters.Add(new FixedValueParameter<IntValue>(RestartsParameterName, "The number of independent random restarts (>0)", new IntValue(10)));
     
    267267      // initialize constants randomly
    268268      if (rand != null) {
    269         foreach (var node in tree.IterateNodesPrefix().OfType<ConstantTreeNode>()) {
     269        foreach (var node in tree.IterateNodesPrefix().OfType<NumberTreeNode>()) {
    270270          double f = Math.Exp(NormalDistributedRandom.NextDouble(rand, 0, 1));
    271271          double s = rand.NextDouble() < 0.5 ? -1 : 1;
  • branches/3140_NumberSymbol/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs

    r17931 r18100  
    220220      }
    221221
    222       var constSy = new Constant();
     222      var numSy = new Number();
    223223      var varCondSy = new VariableCondition() { IgnoreSlope = true };
    224224
    225       var node = CreateRegressionTreeRec(rf.innerobj.trees, offset, offset + 1, constSy, varCondSy);
     225      var node = CreateRegressionTreeRec(rf.innerobj.trees, offset, offset + 1, numSy, varCondSy);
    226226
    227227      var startNode = new StartSymbol().CreateTreeNode();
     
    232232    }
    233233
    234     private ISymbolicExpressionTreeNode CreateRegressionTreeRec(double[] trees, int offset, int k, Constant constSy, VariableCondition varCondSy) {
     234    private ISymbolicExpressionTreeNode CreateRegressionTreeRec(double[] trees, int offset, int k, Number numSy, VariableCondition varCondSy) {
    235235
    236236      // alglib source for evaluation of one tree (dfprocessinternal)
     
    262262
    263263      if ((double)(trees[k]) == (double)(-1)) {
    264         var constNode = (ConstantTreeNode)constSy.CreateTreeNode();
    265         constNode.Value = trees[k + 1];
    266         return constNode;
     264        var numNode = (NumberTreeNode)numSy.CreateTreeNode();
     265        numNode.Value = trees[k + 1];
     266        return numNode;
    267267      } else {
    268268        var condNode = (VariableConditionTreeNode)varCondSy.CreateTreeNode();
     
    271271        condNode.Slope = double.PositiveInfinity;
    272272
    273         var left = CreateRegressionTreeRec(trees, offset, k + 3, constSy, varCondSy);
    274         var right = CreateRegressionTreeRec(trees, offset, offset + (int)Math.Round(trees[k + 2]), constSy, varCondSy);
     273        var left = CreateRegressionTreeRec(trees, offset, k + 3, numSy, varCondSy);
     274        var right = CreateRegressionTreeRec(trees, offset, offset + (int)Math.Round(trees[k + 2]), numSy, varCondSy);
    275275
    276276        condNode.AddSubtree(left); // not 100% correct because interpreter uses: if(x <= thres) left() else right() and RF uses if(x < thres) left() else right() (see above)
  • branches/3140_NumberSymbol/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelAlglib_3_7.cs

    r17931 r18100  
    220220      }
    221221
    222       var constSy = new Constant();
     222      var numSy = new Number();
    223223      var varCondSy = new VariableCondition() { IgnoreSlope = true };
    224224
    225       var node = CreateRegressionTreeRec(rf.innerobj.trees, offset, offset + 1, constSy, varCondSy);
     225      var node = CreateRegressionTreeRec(rf.innerobj.trees, offset, offset + 1, numSy, varCondSy);
    226226
    227227      var startNode = new StartSymbol().CreateTreeNode();
     
    232232    }
    233233
    234     private ISymbolicExpressionTreeNode CreateRegressionTreeRec(double[] trees, int offset, int k, Constant constSy, VariableCondition varCondSy) {
     234    private ISymbolicExpressionTreeNode CreateRegressionTreeRec(double[] trees, int offset, int k, Number constSy, VariableCondition varCondSy) {
    235235
    236236      // alglib source for evaluation of one tree (dfprocessinternal)
     
    262262
    263263      if ((double)(trees[k]) == (double)(-1)) {
    264         var constNode = (ConstantTreeNode)constSy.CreateTreeNode();
    265         constNode.Value = trees[k + 1];
    266         return constNode;
     264        var numNode = (NumberTreeNode)constSy.CreateTreeNode();
     265        numNode.Value = trees[k + 1];
     266        return numNode;
    267267      } else {
    268268        var condNode = (VariableConditionTreeNode)varCondSy.CreateTreeNode();
  • branches/3140_NumberSymbol/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelFull.cs

    r17931 r18100  
    199199      }
    200200
    201       var constSy = new Constant();
     201      var numSy = new Number();
    202202      var varCondSy = new VariableCondition() { IgnoreSlope = true };
    203203
    204       var node = CreateRegressionTreeRec(rf.innerobj.trees, offset, offset + 1, constSy, varCondSy);
     204      var node = CreateRegressionTreeRec(rf.innerobj.trees, offset, offset + 1, numSy, varCondSy);
    205205
    206206      var startNode = new StartSymbol().CreateTreeNode();
     
    211211    }
    212212
    213     private ISymbolicExpressionTreeNode CreateRegressionTreeRec(double[] trees, int offset, int k, Constant constSy, VariableCondition varCondSy) {
     213    private ISymbolicExpressionTreeNode CreateRegressionTreeRec(double[] trees, int offset, int k, Number constSy, VariableCondition varCondSy) {
    214214
    215215      // alglib source for evaluation of one tree (dfprocessinternal)
     
    241241
    242242      if ((double)(trees[k]) == (double)(-1)) {
    243         var constNode = (ConstantTreeNode)constSy.CreateTreeNode();
    244         constNode.Value = trees[k + 1];
    245         return constNode;
     243        var numNode = (NumberTreeNode)constSy.CreateTreeNode();
     244        numNode.Value = trees[k + 1];
     245        return numNode;
    246246      } else {
    247247        var condNode = (VariableConditionTreeNode)varCondSy.CreateTreeNode();
Note: See TracChangeset for help on using the changeset viewer.