Changeset 14238 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
- Timestamp:
- 08/05/16 17:34:16 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
r14237 r14238 182 182 return node.Symbol is Variable; 183 183 } 184 184 private bool IsVariableBase(ISymbolicExpressionTreeNode node) { 185 return node.Symbol is VariableBase; 186 } 185 187 private bool IsConstant(ISymbolicExpressionTreeNode node) { 186 188 return node.Symbol is Constant; … … 203 205 /// <returns></returns> 204 206 public ISymbolicExpressionTreeNode GetSimplifiedTree(ISymbolicExpressionTreeNode original) { 205 if (IsConstant(original) || IsVariable (original)) {207 if (IsConstant(original) || IsVariableBase(original)) { 206 208 return (ISymbolicExpressionTreeNode)original.Clone(); 207 209 } else if (IsAddition(original)) { … … 718 720 } if (IsConstant(a) && !((ConstantTreeNode)a).Value.IsAlmost(1.0)) { 719 721 return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a))); 720 } else if (IsVariable (a) && IsConstant(b)) {722 } else if (IsVariableBase(a) && IsConstant(b)) { 721 723 // merge constant values into variable weights 722 724 var constB = ((ConstantTreeNode)b).Value; 723 ((VariableTreeNode )a).Weight /= constB;725 ((VariableTreeNodeBase)a).Weight /= constB; 724 726 return a; 725 } else if (IsVariable (a) && IsVariable(b) && AreSameVariable(a, b)) {727 } else if (IsVariableBase(a) && IsVariableBase(b) && AreSameVariable(a, b)) { 726 728 // cancel variables 727 729 var aVar = a as VariableTreeNode; … … 835 837 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNodeBase>() 836 838 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 838 841 select g; 839 842 var unchangedSubtrees = subtrees.Where(t => !(t is VariableTreeNodeBase)); … … 861 864 // $ * 1.0 => $ 862 865 return a; 863 } else if (IsConstant(b) && IsVariable (a)) {866 } else if (IsConstant(b) && IsVariableBase(a)) { 864 867 // multiply constants into variables weights 865 ((VariableTreeNode )a).Weight *= ((ConstantTreeNode)b).Value;868 ((VariableTreeNodeBase)a).Weight *= ((ConstantTreeNode)b).Value; 866 869 return a; 867 870 } else if (IsConstant(b) && IsAddition(a)) { … … 944 947 return aVar.VariableName == bVar.VariableName; 945 948 } 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 946 956 return false; 947 957 } … … 951 961 var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees); 952 962 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>() 954 964 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 955 965 group node by node.VariableName + lag into g 956 966 orderby g.Count() 957 967 select g; 958 var constantProduct = (from node in subtrees.OfType<VariableTreeNode >()968 var constantProduct = (from node in subtrees.OfType<VariableTreeNodeBase>() 959 969 select node.Weight) 960 970 .Concat(from node in subtrees.OfType<ConstantTreeNode>() … … 964 974 965 975 var unchangedSubtrees = from tree in subtrees 966 where !(tree is VariableTreeNode )976 where !(tree is VariableTreeNodeBase) 967 977 where !(tree is ConstantTreeNode) 968 978 select tree; … … 1000 1010 if (IsConstant(x)) { 1001 1011 ((ConstantTreeNode)x).Value *= -1; 1002 } else if (IsVariable (x)) {1003 var variableTree = (VariableTreeNode )x;1012 } else if (IsVariableBase(x)) { 1013 var variableTree = (VariableTreeNodeBase)x; 1004 1014 variableTree.Weight *= -1.0; 1005 1015 } else if (IsAddition(x)) {
Note: See TracChangeset
for help on using the changeset viewer.