- Timestamp:
- 08/05/16 17:34:16 (8 years ago)
- Location:
- branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs
r14232 r14238 167 167 if (aggregateLaggedVariables) { 168 168 tree.Root.ForEachNodePrefix(node => { 169 if (node.Symbol is Variable) { 170 var varNode = node as VariableTreeNode; 171 IncReferenceCount(references, varNode.VariableName); 172 } else if (node.Symbol is VariableCondition) { 173 var varCondNode = node as VariableConditionTreeNode; 174 IncReferenceCount(references, varCondNode.VariableName); 175 } else if (node.Symbol is FactorVariable) { 169 if (node is IVariableTreeNode) { 176 170 var factorNode = node as FactorVariableTreeNode; 177 if ( aggregateFactorVariables) {178 IncReferenceCount(references, factorNode.VariableName );171 if (factorNode != null && !aggregateFactorVariables) { 172 IncReferenceCount(references, factorNode.VariableName + "=" + factorNode.VariableValue); 179 173 } else { 180 IncReferenceCount(references, factorNode.ToString()); 174 var varNode = node as IVariableTreeNode; 175 IncReferenceCount(references, varNode.VariableName); 181 176 } 182 177 } … … 189 184 190 185 private static void GetVariableReferences(Dictionary<string, int> references, ISymbolicExpressionTreeNode node, int currentLag, bool aggregateFactorVariables) { 191 if (node.Symbol is LaggedVariable) { 192 var laggedVarNode = node as LaggedVariableTreeNode; 193 IncReferenceCount(references, laggedVarNode.VariableName, currentLag + laggedVarNode.Lag); 194 } else if (node.Symbol is Variable) { 195 var varNode = node as VariableTreeNode; 196 IncReferenceCount(references, varNode.VariableName, currentLag); 197 } else if (node.Symbol is FactorVariable) { 198 var factorNode = node as FactorVariableTreeNode; 199 if (aggregateFactorVariables) { 200 IncReferenceCount(references, factorNode.VariableName, currentLag); 186 if (node is IVariableTreeNode) { 187 var laggedVarTreeNode = node as LaggedVariableTreeNode; 188 var factorVarTreeNode = node as FactorVariableTreeNode; 189 var varConditionTreeNode = node as VariableConditionTreeNode; 190 if (laggedVarTreeNode != null) { 191 IncReferenceCount(references, laggedVarTreeNode.VariableName, currentLag + laggedVarTreeNode.Lag); 192 } else if (factorVarTreeNode != null) { 193 if (aggregateFactorVariables) { 194 IncReferenceCount(references, factorVarTreeNode.VariableName, currentLag); 195 } else { 196 IncReferenceCount(references, factorVarTreeNode.VariableName + "=" + factorVarTreeNode.VariableValue, currentLag); 197 } 198 } else if (varConditionTreeNode != null) { 199 IncReferenceCount(references, varConditionTreeNode.VariableName, currentLag); 200 GetVariableReferences(references, node.GetSubtree(0), currentLag, aggregateFactorVariables); 201 GetVariableReferences(references, node.GetSubtree(1), currentLag, aggregateFactorVariables); 201 202 } else { 202 IncReferenceCount(references, factorNode.ToString(), currentLag); 203 } 204 } else if (node.Symbol is VariableCondition) { 205 var varCondNode = node as VariableConditionTreeNode; 206 IncReferenceCount(references, varCondNode.VariableName, currentLag); 207 GetVariableReferences(references, node.GetSubtree(0), currentLag, aggregateFactorVariables); 208 GetVariableReferences(references, node.GetSubtree(1), currentLag, aggregateFactorVariables); 203 var varNode = node as IVariableTreeNode; 204 IncReferenceCount(references, varNode.VariableName, currentLag); 205 } 209 206 } else if (node.Symbol is Integral) { 210 207 var laggedNode = node as LaggedTreeNode; -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r14237 r14238 140 140 <Compile Include="Importer\Token.cs" /> 141 141 <Compile Include="Interfaces\IModelBacktransformator.cs" /> 142 <Compile Include="Interfaces\IVariableSymbol.cs" /> 142 143 <Compile Include="Interpreter\SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs" /> 143 144 <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" /> -
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)) { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs
r14185 r14238 63 63 var variables = 64 64 SymbolicExpressionTree.IterateNodesPrefix() 65 .OfType< VariableTreeNode>()65 .OfType<IVariableTreeNode>() 66 66 .Select(x => x.VariableName) 67 67 .Distinct(); 68 var variableConditions = SymbolicExpressionTree.IterateNodesPrefix()69 .OfType<VariableConditionTreeNode>().Select(x => x.VariableName).Distinct();70 68 71 return variables. Union(variableConditions).OrderBy(x => x);69 return variables.OrderBy(x => x); 72 70 } 73 71 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r14232 r14238 213 213 grammar.MaximumFunctionArguments = MaximumFunctionArguments.Value; 214 214 grammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value; 215 foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable >()) {215 foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableBase>()) { 216 216 if (!varSymbol.Fixed) { 217 217 varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<double>(x)); … … 225 225 factorSymbol.VariableValues = factorSymbol.VariableNames 226 226 .ToDictionary(varName => varName, varName => ds.GetStringValues(varName).Distinct().ToList()); 227 }228 }229 foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) {230 if (!varSymbol.Fixed) {231 varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<double>(x));232 varSymbol.VariableNames = problemData.AllowedInputVariables;233 227 } 234 228 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Variable.cs
r14237 r14238 39 39 } 40 40 public Variable() : base("Variable", "Represents a variable value.") { } 41 public Variable(string name, string description) : base(name, description) { } 41 42 42 43 public override ISymbolicExpressionTreeNode CreateTreeNode() { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableBase.cs
r14237 r14238 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableClass] 29 public abstract class VariableBase : Symbol {29 public abstract class VariableBase : Symbol, IVariableSymbol { 30 30 #region Properties 31 31 [Storable] -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableCondition.cs
r14185 r14238 30 30 [StorableClass] 31 31 [Item("Variable Condition", "Represents a condition that tests a given variable against a specified threshold.")] 32 public sealed class VariableCondition : Symbol {32 public sealed class VariableCondition : Symbol, IVariableSymbol { 33 33 #region properties 34 34 [Storable] -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableConditionTreeNode.cs
r14185 r14238 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 30 30 [StorableClass] 31 public sealed class VariableConditionTreeNode : SymbolicExpressionTreeNode {31 public sealed class VariableConditionTreeNode : SymbolicExpressionTreeNode, IVariableTreeNode { 32 32 #region properties 33 33 public new VariableCondition Symbol { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNodeBase.cs
r14237 r14238 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableClass] 29 public abstract class VariableTreeNodeBase : SymbolicExpressionTreeTerminalNode {29 public abstract class VariableTreeNodeBase : SymbolicExpressionTreeTerminalNode, IVariableTreeNode { 30 30 public new VariableBase Symbol { 31 31 get { return (VariableBase)base.Symbol; }
Note: See TracChangeset
for help on using the changeset viewer.