Changeset 16328 for branches/2966_interval_calculation
- Timestamp:
- 11/23/18 17:16:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/Intervalnterpreter.cs
r16326 r16328 10 10 using HeuristicLab.Problems.DataAnalysis.Symbolic; 11 11 12 namespace HeuristicLab.Algorithms.DataAnalysis. KnowledgeIntegration.Interpreter{12 namespace HeuristicLab.Algorithms.DataAnalysis.Symbolic { 13 13 [StorableClass] 14 14 [Item("SymbolicDataAnalysisIntervalArithmeticInterpreter", "Interpreter for interval arithmetic within symbolic regression.")] 15 public class IntervalInterpreter : ParameterizedNamedItem{ 15 public sealed class IntervalInterpreter : ParameterizedNamedItem, IStatefulItem { 16 16 17 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 17 18 public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter { … … 24 25 } 25 26 26 public void ClearState() { } 27 28 protected IntervalInterpreter(bool deserializing) : base(deserializing) { } 29 30 protected IntervalInterpreter(IntervalInterpreter original, 31 Cloner cloner) 27 private IntervalInterpreter(bool deserializing) : base(deserializing) { } 28 private IntervalInterpreter(IntervalInterpreter original, Cloner cloner) 32 29 : base(original, cloner) { } 33 30 … … 39 36 } 40 37 38 #region IStatefulItem Members 39 public void InitializeState() { 40 EvaluatedSolutions = 0; 41 } 42 public void ClearState() { } 43 #endregion 44 45 46 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IEnumerable<int> rows, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) { 47 intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 48 var state = PrepareInterpreterState(tree, rows); 49 var x = Evaluate(state, intervals); 50 51 return x; 52 } 53 54 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows, 55 Dictionary<string, Interval> customIntervals, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) { 56 intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 57 var state = PrepareInterpreterState(tree, rows, dataset, customIntervals); 58 var x = Evaluate(state, intervals); 59 60 return x; 61 } 62 63 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows, 64 out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) { 65 intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 66 var state = PrepareInterpreterState(tree, rows, dataset); 67 var x = Evaluate(state, intervals); 68 69 return x; 70 } 71 41 72 private readonly object syncRoot = new object(); 42 73 43 private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, 74 private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, 44 75 IEnumerable<int> rows, IDataset dataset = null, Dictionary<string, Interval> customIntervals = null) { 45 76 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode); 46 77 int necessaryArgStackSize = 0; 47 48 foreach (Instruction instr in code) {78 79 foreach (Instruction instr in code) { 49 80 if (instr.opCode == OpCodes.Variable) { 50 81 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; … … 54 85 if (customIntervals.ContainsKey(variableTreeNode.VariableName)) { 55 86 instr.data = customIntervals[variableTreeNode.VariableName]; 56 } else { 87 } 88 else { 57 89 foreach (var rowEnum in rows) { 58 90 values.Add(dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName)[rowEnum]); … … 60 92 instr.data = new Interval(values.Min(), values.Max()); 61 93 } 62 } else if (dataset != null) { 63 foreach (var rowEnum in rows) { 94 } 95 else if (dataset != null) { 96 foreach (var rowEnum in rows) { 64 97 values.Add(dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName)[rowEnum]); 65 98 } 66 99 instr.data = new Interval(values.Min(), values.Max()); 67 } else if (customIntervals != null) { 68 if (customIntervals.ContainsKey(variableTreeNode.VariableName)) { 100 } 101 else if (customIntervals != null) { 102 if (customIntervals.ContainsKey(variableTreeNode.VariableName)) { 69 103 instr.data = customIntervals[variableTreeNode.VariableName]; 70 104 } 71 } else { 105 } 106 else { 72 107 throw new Exception("No valid input for variables!"); 73 108 } … … 182 217 } 183 218 } 184 185 public void InitializeState() {186 EvaluatedSolutions = 0;187 }188 189 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IEnumerable<int> rows, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {190 intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();191 var state = PrepareInterpreterState(tree, rows);192 var x = Evaluate(state, intervals);193 194 return x;195 }196 197 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows,198 Dictionary<string, Interval> customIntervals, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {199 intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();200 var state = PrepareInterpreterState(tree, rows, dataset, customIntervals);201 var x = Evaluate(state, intervals);202 203 return x;204 }205 206 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows,207 out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {208 intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();209 var state = PrepareInterpreterState(tree, rows, dataset);210 var x = Evaluate(state, intervals);211 212 return x;213 }214 219 } 215 220 }
Note: See TracChangeset
for help on using the changeset viewer.