Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/05/16 17:34:16 (8 years ago)
Author:
gkronber
Message:

#2650:

  • added weight for FactorVariable (necessary for LR)
  • introduced VariableBase and VariableTreeNodeBase and IVariableSymbol
  • support for factors in LR
  • extended variable impacts in solution view
  • fixed ERC view for regression
  • support for FactorVariable in simplifier
  • improved support for FactorVariable in constants optimizer
  • multiple related changes and small fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs

    r14237 r14238  
    182182      return node.Symbol is Variable;
    183183    }
    184 
     184    private bool IsVariableBase(ISymbolicExpressionTreeNode node) {
     185      return node.Symbol is VariableBase;
     186    }
    185187    private bool IsConstant(ISymbolicExpressionTreeNode node) {
    186188      return node.Symbol is Constant;
     
    203205    /// <returns></returns>
    204206    public ISymbolicExpressionTreeNode GetSimplifiedTree(ISymbolicExpressionTreeNode original) {
    205       if (IsConstant(original) || IsVariable(original)) {
     207      if (IsConstant(original) || IsVariableBase(original)) {
    206208        return (ISymbolicExpressionTreeNode)original.Clone();
    207209      } else if (IsAddition(original)) {
     
    718720      } if (IsConstant(a) && !((ConstantTreeNode)a).Value.IsAlmost(1.0)) {
    719721        return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a)));
    720       } else if (IsVariable(a) && IsConstant(b)) {
     722      } else if (IsVariableBase(a) && IsConstant(b)) {
    721723        // merge constant values into variable weights
    722724        var constB = ((ConstantTreeNode)b).Value;
    723         ((VariableTreeNode)a).Weight /= constB;
     725        ((VariableTreeNodeBase)a).Weight /= constB;
    724726        return a;
    725       } else if (IsVariable(a) && IsVariable(b) && AreSameVariable(a, b)) {
     727      } else if (IsVariableBase(a) && IsVariableBase(b) && AreSameVariable(a, b)) {
    726728        // cancel variables
    727729        var aVar = a as VariableTreeNode;
     
    835837      var groupedVarNodes = from node in subtrees.OfType<VariableTreeNodeBase>()
    836838                            let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0
    837                             group node by node.VariableName + lag into g
     839                            let cat = (node is FactorVariableTreeNode) ? ((FactorVariableTreeNode)node).VariableValue : string.Empty
     840                            group node by node.VariableName + cat + lag into g
    838841                            select g;
    839842      var unchangedSubtrees = subtrees.Where(t => !(t is VariableTreeNodeBase));
     
    861864        // $ * 1.0 => $
    862865        return a;
    863       } else if (IsConstant(b) && IsVariable(a)) {
     866      } else if (IsConstant(b) && IsVariableBase(a)) {
    864867        // multiply constants into variables weights
    865         ((VariableTreeNode)a).Weight *= ((ConstantTreeNode)b).Value;
     868        ((VariableTreeNodeBase)a).Weight *= ((ConstantTreeNode)b).Value;
    866869        return a;
    867870      } else if (IsConstant(b) && IsAddition(a)) {
     
    944947        return aVar.VariableName == bVar.VariableName;
    945948      }
     949      var aFactor = a as FactorVariableTreeNode;
     950      var bFactor = b as FactorVariableTreeNode;
     951      if (aFactor != null && bFactor != null) {
     952        return aFactor.VariableName == bFactor.VariableName &&
     953          aFactor.VariableValue == bFactor.VariableValue;
     954      }
     955
    946956      return false;
    947957    }
     
    951961      var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees);
    952962      while (prod.Subtrees.Any()) prod.RemoveSubtree(0);
    953       var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>()
     963      var groupedVarNodes = from node in subtrees.OfType<VariableTreeNodeBase>()
    954964                            let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0
    955965                            group node by node.VariableName + lag into g
    956966                            orderby g.Count()
    957967                            select g;
    958       var constantProduct = (from node in subtrees.OfType<VariableTreeNode>()
     968      var constantProduct = (from node in subtrees.OfType<VariableTreeNodeBase>()
    959969                             select node.Weight)
    960970                            .Concat(from node in subtrees.OfType<ConstantTreeNode>()
     
    964974
    965975      var unchangedSubtrees = from tree in subtrees
    966                               where !(tree is VariableTreeNode)
     976                              where !(tree is VariableTreeNodeBase)
    967977                              where !(tree is ConstantTreeNode)
    968978                              select tree;
     
    10001010      if (IsConstant(x)) {
    10011011        ((ConstantTreeNode)x).Value *= -1;
    1002       } else if (IsVariable(x)) {
    1003         var variableTree = (VariableTreeNode)x;
     1012      } else if (IsVariableBase(x)) {
     1013        var variableTree = (VariableTreeNodeBase)x;
    10041014        variableTree.Weight *= -1.0;
    10051015      } else if (IsAddition(x)) {
Note: See TracChangeset for help on using the changeset viewer.