- Timestamp:
- 11/18/15 13:50:15 (9 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisExpressionTreeInterpreter.cs
r12509 r13248 73 73 } 74 74 75 private readonly object syncRoot = new object(); 75 76 public IEnumerable<IEnumerable<double>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) { 76 if (CheckExpressionsWithIntervalArithmetic .Value)77 if (CheckExpressionsWithIntervalArithmetic) 77 78 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); 78 79 if (targetVariableCache == null || targetVariableCache.GetLength(0) < dataset.Rows) … … 82 83 83 84 string targetVariable = TargetVariable; 84 lock ( EvaluatedSolutions) {85 EvaluatedSolutions .Value++; // increment the evaluated solutions counter85 lock (syncRoot) { 86 EvaluatedSolutions++; // increment the evaluated solutions counter 86 87 } 87 88 var state = PrepareInterpreterState(tree, dataset, targetVariableCache, TargetVariable); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r13241 r13248 138 138 <Compile Include="Importer\Token.cs" /> 139 139 <Compile Include="Interfaces\IModelBacktransformator.cs" /> 140 <Compile Include="Interpreter\SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs" /> 140 141 <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" /> 141 142 <Compile Include="SymbolicDataAnalysisModelComplexityCalculator.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionTreeInterpreter.cs
r12509 r13248 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 25 … … 28 27 public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem, IStatefulItem { 29 28 IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows); 30 IntValueEvaluatedSolutions { get; set; }29 int EvaluatedSolutions { get; set; } 31 30 } 32 31 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r12509 r13248 69 69 70 70 private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic"; 71 private const string CheckExpressionsWithIntervalArithmeticParameterDescription = "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression."; 71 72 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 72 73 … … 80 81 81 82 #region parameter properties 82 83 public IValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter { 84 get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; } 85 } 86 87 public IValueParameter<IntValue> EvaluatedSolutionsParameter { 88 get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; } 89 } 90 83 public IFixedValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter { 84 get { return (IFixedValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; } 85 } 86 87 public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter { 88 get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; } 89 } 91 90 #endregion 92 91 93 92 #region properties 94 95 public BoolValue CheckExpressionsWithIntervalArithmetic { 96 get { return CheckExpressionsWithIntervalArithmeticParameter.Value; } 97 set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; } 98 } 99 100 public IntValue EvaluatedSolutions { 101 get { return EvaluatedSolutionsParameter.Value; } 102 set { EvaluatedSolutionsParameter.Value = value; } 103 } 104 93 public bool CheckExpressionsWithIntervalArithmetic { 94 get { return CheckExpressionsWithIntervalArithmeticParameter.Value.Value; } 95 set { CheckExpressionsWithIntervalArithmeticParameter.Value.Value = value; } 96 } 97 public int EvaluatedSolutions { 98 get { return EvaluatedSolutionsParameter.Value.Value; } 99 set { EvaluatedSolutionsParameter.Value.Value = value; } 100 } 105 101 #endregion 106 107 102 108 103 [StorableConstructor] … … 116 111 public SymbolicDataAnalysisExpressionTreeILEmittingInterpreter() 117 112 : base("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.") { 118 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 119 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 113 Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, 114 "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 115 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 116 } 117 118 public SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(string name, string description) 119 : base(name, description) { 120 Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, 121 "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 122 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 120 123 } 121 124 122 125 [StorableHook(HookType.AfterDeserialization)] 123 126 private void AfterDeserialization() { 124 if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName)) 125 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 127 var evaluatedSolutions = new IntValue(0); 128 var checkExpressionsWithIntervalArithmetic = new BoolValue(false); 129 if (Parameters.ContainsKey(EvaluatedSolutionsParameterName)) { 130 var evaluatedSolutionsParameter = (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; 131 evaluatedSolutions = evaluatedSolutionsParameter.Value; 132 Parameters.Remove(EvaluatedSolutionsParameterName); 133 } 134 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", evaluatedSolutions)); 135 if (Parameters.ContainsKey(CheckExpressionsWithIntervalArithmeticParameterName)) { 136 var checkExpressionsWithIntervalArithmeticParameter = (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; 137 Parameters.Remove(CheckExpressionsWithIntervalArithmeticParameterName); 138 checkExpressionsWithIntervalArithmetic = checkExpressionsWithIntervalArithmeticParameter.Value; 139 } 140 Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, checkExpressionsWithIntervalArithmetic)); 126 141 } 127 142 128 143 #region IStatefulItem 129 130 144 public void InitializeState() { 131 EvaluatedSolutions .Value= 0;145 EvaluatedSolutions = 0; 132 146 } 133 147 134 148 public void ClearState() { 135 EvaluatedSolutions.Value = 0; 136 } 137 149 } 138 150 #endregion 139 151 140 152 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 141 if (CheckExpressionsWithIntervalArithmetic .Value)153 if (CheckExpressionsWithIntervalArithmetic) 142 154 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); 143 155 144 EvaluatedSolutions .Value++; // increment the evaluated solutions counter156 EvaluatedSolutions++; // increment the evaluated solutions counter 145 157 var state = PrepareInterpreterState(tree, dataset); 146 158 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r12509 r13248 32 32 [StorableClass] 33 33 [Item("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.")] 34 public class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter { 34 public class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem, 35 ISymbolicDataAnalysisExpressionTreeInterpreter { 35 36 private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic"; 37 private const string CheckExpressionsWithIntervalArithmeticParameterDescription = "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression."; 36 38 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 37 39 38 public override bool CanChangeName { get { return false; } } 39 public override bool CanChangeDescription { get { return false; } } 40 public override bool CanChangeName { 41 get { return false; } 42 } 43 44 public override bool CanChangeDescription { 45 get { return false; } 46 } 40 47 41 48 #region parameter properties 42 public I ValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {43 get { return (I ValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }44 } 45 46 public I ValueParameter<IntValue> EvaluatedSolutionsParameter {47 get { return (I ValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }49 public IFixedValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter { 50 get { return (IFixedValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; } 51 } 52 53 public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter { 54 get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; } 48 55 } 49 56 #endregion 50 57 51 58 #region properties 52 public BoolValueCheckExpressionsWithIntervalArithmetic {53 get { return CheckExpressionsWithIntervalArithmeticParameter.Value ; }54 set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }55 } 56 57 public IntValueEvaluatedSolutions {58 get { return EvaluatedSolutionsParameter.Value ; }59 set { EvaluatedSolutionsParameter.Value = value; }59 public bool CheckExpressionsWithIntervalArithmetic { 60 get { return CheckExpressionsWithIntervalArithmeticParameter.Value.Value; } 61 set { CheckExpressionsWithIntervalArithmeticParameter.Value.Value = value; } 62 } 63 64 public int EvaluatedSolutions { 65 get { return EvaluatedSolutionsParameter.Value.Value; } 66 set { EvaluatedSolutionsParameter.Value.Value = value; } 60 67 } 61 68 #endregion … … 63 70 [StorableConstructor] 64 71 protected SymbolicDataAnalysisExpressionTreeInterpreter(bool deserializing) : base(deserializing) { } 65 protected SymbolicDataAnalysisExpressionTreeInterpreter(SymbolicDataAnalysisExpressionTreeInterpreter original, Cloner cloner) : base(original, cloner) { } 72 73 protected SymbolicDataAnalysisExpressionTreeInterpreter(SymbolicDataAnalysisExpressionTreeInterpreter original, 74 Cloner cloner) : base(original, cloner) { } 75 66 76 public override IDeepCloneable Clone(Cloner cloner) { 67 77 return new SymbolicDataAnalysisExpressionTreeInterpreter(this, cloner); … … 70 80 public SymbolicDataAnalysisExpressionTreeInterpreter() 71 81 : base("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.") { 72 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));73 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));82 Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 83 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 74 84 } 75 85 76 86 protected SymbolicDataAnalysisExpressionTreeInterpreter(string name, string description) 77 87 : base(name, description) { 78 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));79 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));88 Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 89 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 80 90 } 81 91 82 92 [StorableHook(HookType.AfterDeserialization)] 83 93 private void AfterDeserialization() { 84 if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName)) 85 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 94 var evaluatedSolutions = new IntValue(0); 95 var checkExpressionsWithIntervalArithmetic = new BoolValue(false); 96 if (Parameters.ContainsKey(EvaluatedSolutionsParameterName)) { 97 var evaluatedSolutionsParameter = (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; 98 evaluatedSolutions = evaluatedSolutionsParameter.Value; 99 Parameters.Remove(EvaluatedSolutionsParameterName); 100 } 101 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", evaluatedSolutions)); 102 if (Parameters.ContainsKey(CheckExpressionsWithIntervalArithmeticParameterName)) { 103 var checkExpressionsWithIntervalArithmeticParameter = (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; 104 Parameters.Remove(CheckExpressionsWithIntervalArithmeticParameterName); 105 checkExpressionsWithIntervalArithmetic = checkExpressionsWithIntervalArithmeticParameter.Value; 106 } 107 Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, checkExpressionsWithIntervalArithmetic)); 86 108 } 87 109 88 110 #region IStatefulItem 89 111 public void InitializeState() { 90 EvaluatedSolutions.Value = 0; 91 } 92 93 public void ClearState() { 94 } 112 EvaluatedSolutions = 0; 113 } 114 115 public void ClearState() { } 95 116 #endregion 96 117 97 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 98 if (CheckExpressionsWithIntervalArithmetic.Value) 118 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, 119 IEnumerable<int> rows) { 120 if (CheckExpressionsWithIntervalArithmetic) { 99 121 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); 100 101 lock (EvaluatedSolutions) { 102 EvaluatedSolutions.Value++; // increment the evaluated solutions counter 122 } 123 124 lock (EvaluatedSolutionsParameter.Value) { 125 EvaluatedSolutions++; // increment the evaluated solutions counter 103 126 } 104 127 var state = PrepareInterpreterState(tree, dataset); … … 131 154 } 132 155 133 134 156 public virtual double Evaluate(IDataset dataset, ref int row, InterpreterState state) { 135 157 Instruction currentInstr = state.NextInstruction(); … … 147 169 s -= Evaluate(dataset, ref row, state); 148 170 } 149 if (currentInstr.nArguments == 1) s = -s;171 if (currentInstr.nArguments == 1) { s = -s; } 150 172 return s; 151 173 } … … 162 184 p /= Evaluate(dataset, ref row, state); 163 185 } 164 if (currentInstr.nArguments == 1) p = 1.0 / p;186 if (currentInstr.nArguments == 1) { p = 1.0 / p; } 165 187 return p; 166 188 } … … 205 227 case OpCodes.Gamma: { 206 228 var x = Evaluate(dataset, ref row, state); 207 if (double.IsNaN(x)) return double.NaN; 208 else return alglib.gammafunction(x); 229 if (double.IsNaN(x)) { return double.NaN; } else { return alglib.gammafunction(x); } 209 230 } 210 231 case OpCodes.Psi: { … … 216 237 case OpCodes.Dawson: { 217 238 var x = Evaluate(dataset, ref row, state); 218 if (double.IsNaN(x)) return double.NaN;239 if (double.IsNaN(x)) { return double.NaN; } 219 240 return alglib.dawsonintegral(x); 220 241 } 221 242 case OpCodes.ExponentialIntegralEi: { 222 243 var x = Evaluate(dataset, ref row, state); 223 if (double.IsNaN(x)) return double.NaN;244 if (double.IsNaN(x)) { return double.NaN; } 224 245 return alglib.exponentialintegralei(x); 225 246 } … … 349 370 int positiveSignals = 0; 350 371 for (int i = 0; i < currentInstr.nArguments; i++) { 351 if (Evaluate(dataset, ref row, state) > 0.0) positiveSignals++;372 if (Evaluate(dataset, ref row, state) > 0.0) { positiveSignals++; } 352 373 } 353 374 return positiveSignals % 2 != 0 ? 1.0 : -1.0; … … 356 377 double x = Evaluate(dataset, ref row, state); 357 378 double y = Evaluate(dataset, ref row, state); 358 if (x > y) return 1.0; 359 else return -1.0; 379 if (x > y) { return 1.0; } else { return -1.0; } 360 380 } 361 381 case OpCodes.LT: { 362 382 double x = Evaluate(dataset, ref row, state); 363 383 double y = Evaluate(dataset, ref row, state); 364 if (x < y) return 1.0; 365 else return -1.0; 384 if (x < y) { return 1.0; } else { return -1.0; } 366 385 } 367 386 case OpCodes.TimeLag: { … … 437 456 var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode; 438 457 int actualRow = row + laggedVariableTreeNode.Lag; 439 if (actualRow < 0 || actualRow >= dataset.Rows) return double.NaN;458 if (actualRow < 0 || actualRow >= dataset.Rows) { return double.NaN; } 440 459 return ((IList<double>)currentInstr.data)[actualRow] * laggedVariableTreeNode.Weight; 441 460 } … … 459 478 return trueBranch * p + falseBranch * (1 - p); 460 479 } 461 default: throw new NotSupportedException(); 480 default: 481 throw new NotSupportedException(); 462 482 } 463 483 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r12509 r13248 35 35 public sealed class SymbolicDataAnalysisExpressionTreeLinearInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter { 36 36 private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic"; 37 private const string CheckExpressionsWithIntervalArithmeticParameterDescription = "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression."; 37 38 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 38 39 … … 48 49 49 50 #region parameter properties 50 public I ValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {51 get { return (I ValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }52 } 53 54 public I ValueParameter<IntValue> EvaluatedSolutionsParameter {55 get { return (I ValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }51 public IFixedValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter { 52 get { return (IFixedValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; } 53 } 54 55 public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter { 56 get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; } 56 57 } 57 58 #endregion 58 59 59 60 #region properties 60 public BoolValueCheckExpressionsWithIntervalArithmetic {61 get { return CheckExpressionsWithIntervalArithmeticParameter.Value ; }62 set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }63 } 64 public IntValueEvaluatedSolutions {65 get { return EvaluatedSolutionsParameter.Value ; }66 set { EvaluatedSolutionsParameter.Value = value; }61 public bool CheckExpressionsWithIntervalArithmetic { 62 get { return CheckExpressionsWithIntervalArithmeticParameter.Value.Value; } 63 set { CheckExpressionsWithIntervalArithmeticParameter.Value.Value = value; } 64 } 65 public int EvaluatedSolutions { 66 get { return EvaluatedSolutionsParameter.Value.Value; } 67 set { EvaluatedSolutionsParameter.Value.Value = value; } 67 68 } 68 69 #endregion … … 84 85 public SymbolicDataAnalysisExpressionTreeLinearInterpreter() 85 86 : base("SymbolicDataAnalysisExpressionTreeLinearInterpreter", "Linear (non-recursive) interpreter for symbolic expression trees (does not support ADFs).") { 86 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 87 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 87 Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, new BoolValue(false))); 88 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 89 interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 90 } 91 92 public SymbolicDataAnalysisExpressionTreeLinearInterpreter(string name, string description) 93 : base(name, description) { 94 Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, new BoolValue(false))); 95 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 88 96 interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 89 97 } … … 91 99 [StorableHook(HookType.AfterDeserialization)] 92 100 private void AfterDeserialization() { 93 if (interpreter == null) interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 101 var evaluatedSolutions = new IntValue(0); 102 var checkExpressionsWithIntervalArithmetic = new BoolValue(false); 103 if (Parameters.ContainsKey(EvaluatedSolutionsParameterName)) { 104 var evaluatedSolutionsParameter = (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; 105 evaluatedSolutions = evaluatedSolutionsParameter.Value; 106 Parameters.Remove(EvaluatedSolutionsParameterName); 107 } 108 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", evaluatedSolutions)); 109 if (Parameters.ContainsKey(CheckExpressionsWithIntervalArithmeticParameterName)) { 110 var checkExpressionsWithIntervalArithmeticParameter = (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; 111 Parameters.Remove(CheckExpressionsWithIntervalArithmeticParameterName); 112 checkExpressionsWithIntervalArithmetic = checkExpressionsWithIntervalArithmeticParameter.Value; 113 } 114 Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, checkExpressionsWithIntervalArithmetic)); 94 115 } 95 116 96 117 #region IStatefulItem 97 118 public void InitializeState() { 98 EvaluatedSolutions .Value= 0;119 EvaluatedSolutions = 0; 99 120 } 100 121 … … 103 124 104 125 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 105 if (CheckExpressionsWithIntervalArithmetic .Value)126 if (CheckExpressionsWithIntervalArithmetic) 106 127 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); 107 128 108 lock (EvaluatedSolutions ) {109 EvaluatedSolutions .Value++; // increment the evaluated solutions counter129 lock (EvaluatedSolutionsParameter.Value) { 130 EvaluatedSolutions++; // increment the evaluated solutions counter 110 131 } 111 132
Note: See TracChangeset
for help on using the changeset viewer.