- Timestamp:
- 08/09/16 15:34:33 (8 years ago)
- Location:
- branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs
r14243 r14249 53 53 constant.MaxValue = 20; 54 54 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 55 var factorVariableSymbol = new BinaryFactorVariable(); 55 var binFactorVariableSymbol = new BinaryFactorVariable(); 56 var factorVariableSymbol = new FactorVariable(); 56 57 57 var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol, factorVariableSymbol};58 var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol, binFactorVariableSymbol, factorVariableSymbol}; 58 59 var functionSymbols = new List<Symbol>() { add, sub, mul, div }; 59 60 -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs
r14243 r14249 115 115 constant.MaxValue = 20; 116 116 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 117 var factorVariable = new BinaryFactorVariable(); 117 var binFactorVariable = new BinaryFactorVariable(); 118 var factorVariable = new FactorVariable(); 118 119 var laggedVariable = new LaggedVariable(); 119 120 laggedVariable.InitialFrequency = 0.0; … … 124 125 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, square, pow, sqrt, root, exp, 125 126 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral, 126 @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, factorVariable, laggedVariable,autoregressiveVariable, variableCondition };127 @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition }; 127 128 var unaryFunctionSymbols = new List<Symbol>() { square, sqrt, sin, cos, tan, log, exp, not, timeLag, integral, derivative, 128 129 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral … … 131 132 var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, variableCondition }; 132 133 var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or, xor }; 133 var terminalSymbols = new List<Symbol>() { variableSymbol, factorVariable, constant, laggedVariable, autoregressiveVariable };134 var terminalSymbols = new List<Symbol>() { variableSymbol, binFactorVariable, factorVariable, constant, laggedVariable, autoregressiveVariable }; 134 135 135 136 foreach (var symb in allSymbols) -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
r14243 r14249 104 104 constant.MaxValue = 20; 105 105 var variableSymbol = new Variable(); 106 var factorVariable = new BinaryFactorVariable(); 106 var binFactorVariable = new BinaryFactorVariable(); 107 var factorVariable = new FactorVariable(); 107 108 var laggedVariable = new LaggedVariable(); 108 109 var autoregressiveVariable = new AutoregressiveTargetVariable(); … … 115 116 var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, 116 117 fresnelCosineIntegral,fresnelSineIntegral,gamma,hypCosineIntegral,hypSineIntegral,norm, psi, sineIntegral}); 117 var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variableSymbol, factorVariable });118 var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variableSymbol, binFactorVariable, factorVariable }); 118 119 var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, specialFunctions, terminalSymbols }); 119 120 … … 123 124 var comparisonSymbols = new GroupSymbol(ComparisonsName, new List<ISymbol> { gt, lt }); 124 125 var booleanOperationSymbols = new GroupSymbol(BooleanOperatorsName, new List<ISymbol> { and, or, not, xor }); 125 var conditionalSymbols = new GroupSymbol(ConditionalSymbolsName, new List<ISymbol> { conditionSymbols, comparisonSymbols, booleanOperationSymbols }); // TODO: factorVariableBool?126 var conditionalSymbols = new GroupSymbol(ConditionalSymbolsName, new List<ISymbol> { conditionSymbols, comparisonSymbols, booleanOperationSymbols }); 126 127 127 128 var timeSeriesSymbols = new GroupSymbol(TimeSeriesSymbolsName, new List<ISymbol> { timeLag, integral, derivative, laggedVariable, autoregressiveVariable }); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r14238 r14249 199 199 <Compile Include="Symbols\AiryB.cs" /> 200 200 <Compile Include="Symbols\Bessel.cs" /> 201 <Compile Include="Symbols\BinaryFactorVariable.cs" /> 202 <Compile Include="Symbols\BinaryFactorVariableTreeNode.cs" /> 203 <Compile Include="Symbols\FactorVariableTreeNode.cs" /> 201 204 <Compile Include="Symbols\FactorVariable.cs" /> 202 <Compile Include="Symbols\FactorVariableTreeNode.cs" />203 205 <Compile Include="Symbols\VariableBase.cs" /> 204 206 <Compile Include="Symbols\VariableTreeNodeBase.cs" /> -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r14243 r14249 84 84 public const byte Bessel = 44; 85 85 public const byte FactorVariable = 46; 86 public const byte BinaryFactorVariable = 47; 87 86 88 87 89 private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { … … 132 134 { typeof(Erf), OpCodes.Erf}, 133 135 { typeof(Bessel), OpCodes.Bessel}, 134 { typeof(BinaryFactorVariable), OpCodes.FactorVariable } 136 { typeof(FactorVariable), OpCodes.FactorVariable }, 137 { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable } 135 138 }; 136 139 -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r14243 r14249 66 66 private static MethodInfo erf = thisType.GetMethod("Erf", new Type[] { typeof(double) }); 67 67 private static MethodInfo bessel = thisType.GetMethod("Bessel", new Type[] { typeof(double) }); 68 private static MethodInfo string_eq = typeof(string).GetMethod("Equals", new Type[] { typeof(string)});68 private static MethodInfo string_eq = typeof(string).GetMethod("Equals", new Type[] { typeof(string) }); 69 69 #endregion 70 70 … … 628 628 return; 629 629 } 630 case OpCodes.FactorVariable: { 631 BinaryFactorVariableTreeNode varNode = currentInstr.dynamicNode as BinaryFactorVariableTreeNode; 632 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array 633 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.data); 634 // load correct column of the current variable 635 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref); 636 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex 637 if (!state.InLaggedContext) { 638 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 639 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.VariableValue); 640 il.Emit(System.Reflection.Emit.OpCodes.Call, string_eq); 641 throw new NotSupportedException(); 642 // TODO: convert bool to 1 / 0? 643 } else { 644 var nanResult = il.DefineLabel(); 645 var normalResult = il.DefineLabel(); 646 il.Emit(System.Reflection.Emit.OpCodes.Dup); 647 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); 648 il.Emit(System.Reflection.Emit.OpCodes.Blt, nanResult); 649 il.Emit(System.Reflection.Emit.OpCodes.Dup); 650 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, ds.Rows); 651 il.Emit(System.Reflection.Emit.OpCodes.Bge, nanResult); 652 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 653 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.VariableValue); 654 il.Emit(System.Reflection.Emit.OpCodes.Call, string_eq); 655 throw new NotSupportedException(); 656 // TODO: convert bool to 1 / 0? 657 il.Emit(System.Reflection.Emit.OpCodes.Br, normalResult); 658 il.MarkLabel(nanResult); 659 il.Emit(System.Reflection.Emit.OpCodes.Pop); // rowIndex 660 il.Emit(System.Reflection.Emit.OpCodes.Pop); // column reference 661 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, double.NaN); 662 il.MarkLabel(normalResult); 663 } 664 return; 630 case OpCodes.FactorVariable: 631 case OpCodes.BinaryFactorVariable: { 632 throw new NotSupportedException(); 665 633 } 666 634 case OpCodes.LagVariable: { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r14243 r14249 146 146 } else if (instr.opCode == OpCodes.FactorVariable) { 147 147 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 148 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 148 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 149 149 } else if (instr.opCode == OpCodes.LagVariable) { 150 150 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; … … 459 459 return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight; 460 460 } 461 case OpCodes. FactorVariable: {461 case OpCodes.BinaryFactorVariable: { 462 462 if (row < 0 || row >= dataset.Rows) return double.NaN; 463 463 var factorVarTreeNode = currentInstr.dynamicNode as BinaryFactorVariableTreeNode; 464 464 return ((IList<string>)currentInstr.data)[row] == factorVarTreeNode.VariableValue ? factorVarTreeNode.Weight : 0; 465 } 466 case OpCodes.FactorVariable: { 467 if (row < 0 || row >= dataset.Rows) return double.NaN; 468 var factorVarTreeNode = currentInstr.dynamicNode as FactorVariableTreeNode; 469 return factorVarTreeNode.GetValue(((IList<string>)currentInstr.data)[row]); 465 470 } 466 471 case OpCodes.LagVariable: { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r14243 r14249 148 148 instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight; 149 149 } 150 } else if (instr.opCode == OpCodes.BinaryFactorVariable) { 151 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 152 else { 153 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 154 instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? factorTreeNode.Weight : 0; 155 } 150 156 } else if (instr.opCode == OpCodes.FactorVariable) { 151 157 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 152 158 else { 153 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;154 instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? factorTreeNode.Weight : 0;159 var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode; 160 instr.value = factorTreeNode.GetValue(((IList<string>)instr.data)[row]); 155 161 } 156 162 } else if (instr.opCode == OpCodes.LagVariable) { … … 398 404 } 399 405 break; 406 case OpCodes.BinaryFactorVariable: { 407 var factorVariableTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 408 instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName); 409 } 410 break; 400 411 case OpCodes.FactorVariable: { 401 var factorVariableTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;412 var factorVariableTreeNode = instr.dynamicNode as FactorVariableTreeNode; 402 413 instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName); 403 414 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
r14243 r14249 183 183 } 184 184 private bool IsVariableBase(ISymbolicExpressionTreeNode node) { 185 return node .Symbol is VariableBase;185 return node is VariableTreeNodeBase; 186 186 } 187 187 private bool IsConstant(ISymbolicExpressionTreeNode node) { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r14243 r14249 226 226 .ToDictionary(varName => varName, varName => ds.GetStringValues(varName).Distinct().ToList()); 227 227 } 228 } foreach (var factorSymbol in grammar.Symbols.OfType<FactorVariable>()) { 229 if (!factorSymbol.Fixed) { 230 factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<string>(x)); 231 factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<string>(x)); 232 factorSymbol.VariableValues = factorSymbol.VariableNames 233 .ToDictionary(varName => varName, varName => ds.GetStringValues(varName).Distinct().ToList()); 234 } 228 235 } 229 236 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs
r14185 r14249 73 73 } 74 74 75 p ublicSymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)75 protected SymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator) 76 76 : base(problemData, evaluator, solutionCreator) { 77 77 Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.")); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r14243 r14249 43 43 //optimization: constant nodes return always the same value 44 44 ConstantTreeNode constantNode = node as ConstantTreeNode; 45 BinaryFactorVariableTreeNode factorNode = node as BinaryFactorVariableTreeNode; 45 BinaryFactorVariableTreeNode binaryFactorNode = node as BinaryFactorVariableTreeNode; 46 FactorVariableTreeNode factorNode = node as FactorVariableTreeNode; 46 47 if (constantNode != null) { 47 48 yield return constantNode.Value; 48 } else if ( factorNode != null) {49 } else if (binaryFactorNode != null) { 49 50 // valid replacements are either all off or all on 50 51 yield return 0; 51 52 yield return 1; 53 } else if (factorNode != null) { 54 foreach (var w in factorNode.Weights) yield return w; 55 yield return 0.0; 52 56 } else { 53 57 var rootSymbol = new ProgramRootSymbol().CreateTreeNode(); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/BinaryFactorVariable.cs
r14243 r14249 32 32 public class BinaryFactorVariable : VariableBase { 33 33 34 private Dictionary<string, List<string>> variableValues;34 private readonly Dictionary<string, List<string>> variableValues; 35 35 36 36 [Storable] … … 63 63 64 64 public override ISymbolicExpressionTreeNode CreateTreeNode() { 65 return new FactorVariableTreeNode(this);65 return new BinaryFactorVariableTreeNode(this); 66 66 } 67 67 -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/BinaryFactorVariableTreeNode.cs
r14243 r14249 44 44 variableValue = original.variableValue; 45 45 } 46 protected BinaryFactorVariableTreeNode() { }47 46 public BinaryFactorVariableTreeNode(BinaryFactorVariable variableSymbol) : base(variableSymbol) { } 48 47
Note: See TracChangeset
for help on using the changeset viewer.