Changeset 16899 for branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
- Timestamp:
- 05/06/19 14:20:06 (5 years ago)
- Location:
- branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 16737,16740,16758,16762,16764,16768,16802,16822,16839,16858,16868
- Property svn:mergeinfo changed
-
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r16722 r16899 69 69 #endregion 70 70 71 public Interval GetSymbolicEx ressionTreeInterval(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) {71 public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) { 72 72 var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); 73 return GetSymbolicEx ressionTreeInterval(tree, variableRanges);74 } 75 76 public Interval GetSymbolicEx ressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset,77 out Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, IEnumerable<int> rows = null) {73 return GetSymbolicExpressionTreeInterval(tree, variableRanges); 74 } 75 76 public Interval GetSymbolicExpressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, 77 out IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, IEnumerable<int> rows = null) { 78 78 var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); 79 return GetSymbolicEx ressionTreeIntervals(tree, variableRanges, out nodeIntervals);80 } 81 82 public Interval GetSymbolicEx ressionTreeInterval(ISymbolicExpressionTree tree,Dictionary<string, Interval> variableRanges) {79 return GetSymbolicExpressionTreeIntervals(tree, variableRanges, out nodeIntervals); 80 } 81 82 public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IDictionary<string, Interval> variableRanges) { 83 83 lock (syncRoot) { 84 84 EvaluatedSolutions++; … … 96 96 97 97 98 public Interval GetSymbolicEx ressionTreeIntervals(ISymbolicExpressionTree tree,99 Dictionary<string, Interval> variableRanges, outDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals) {98 public Interval GetSymbolicExpressionTreeIntervals(ISymbolicExpressionTree tree, 99 IDictionary<string, Interval> variableRanges, out IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals) { 100 100 lock (syncRoot) { 101 101 EvaluatedSolutions++; … … 108 108 // fix incorrect intervals if necessary (could occur because of numerical errors) 109 109 nodeIntervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 110 foreach (var kvp in intervals) {110 foreach (var kvp in intervals) { 111 111 var interval = kvp.Value; 112 112 if (interval.IsInfiniteOrUndefined || interval.LowerBound <= interval.UpperBound) … … 124 124 125 125 126 private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, Dictionary<string, Interval> variableRanges) {126 private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, IDictionary<string, Interval> variableRanges) { 127 127 if (variableRanges == null) 128 128 throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges)); … … 133 133 } 134 134 135 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCode s.MapSymbolToOpCode);136 foreach (Instruction instr in code.Where(i => i.opCode == OpCode s.Variable)) {135 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCode.MapSymbolToOpCode); 136 foreach (Instruction instr in code.Where(i => i.opCode == OpCode.Variable)) { 137 137 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 138 138 instr.data = variableRanges[variableTreeNode.VariableName]; … … 141 141 } 142 142 143 private Interval Evaluate(Instruction[] instructions, ref int instructionCounter, Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null) {143 private Interval Evaluate(Instruction[] instructions, ref int instructionCounter, IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null) { 144 144 Instruction currentInstr = instructions[instructionCounter]; 145 145 //Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side … … 150 150 switch (currentInstr.opCode) { 151 151 //Variables, Constants, ... 152 case OpCode s.Variable: {152 case OpCode.Variable: { 153 153 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; 154 154 var weightInterval = new Interval(variableTreeNode.Weight, variableTreeNode.Weight); … … 158 158 break; 159 159 } 160 case OpCode s.Constant: {160 case OpCode.Constant: { 161 161 var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode; 162 162 result = new Interval(constTreeNode.Value, constTreeNode.Value); … … 164 164 } 165 165 //Elementary arithmetic rules 166 case OpCode s.Add: {166 case OpCode.Add: { 167 167 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 168 168 for (int i = 1; i < currentInstr.nArguments; i++) { … … 172 172 break; 173 173 } 174 case OpCode s.Sub: {174 case OpCode.Sub: { 175 175 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 176 176 if (currentInstr.nArguments == 1) … … 183 183 break; 184 184 } 185 case OpCode s.Mul: {185 case OpCode.Mul: { 186 186 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 187 187 for (int i = 1; i < currentInstr.nArguments; i++) { … … 191 191 break; 192 192 } 193 case OpCode s.Div: {193 case OpCode.Div: { 194 194 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 195 195 if (currentInstr.nArguments == 1) … … 203 203 } 204 204 //Trigonometric functions 205 case OpCode s.Sin: {205 case OpCode.Sin: { 206 206 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 207 207 result = Interval.Sine(argumentInterval); 208 208 break; 209 209 } 210 case OpCode s.Cos: {210 case OpCode.Cos: { 211 211 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 212 212 result = Interval.Cosine(argumentInterval); 213 213 break; 214 214 } 215 case OpCode s.Tan: {215 case OpCode.Tan: { 216 216 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 217 217 result = Interval.Tangens(argumentInterval); 218 218 break; 219 219 } 220 case OpCode.Tanh: { 221 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 222 result = Interval.HyperbolicTangent(argumentInterval); 223 break; 224 } 220 225 //Exponential functions 221 case OpCode s.Log: {226 case OpCode.Log: { 222 227 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 223 228 result = Interval.Logarithm(argumentInterval); 224 229 break; 225 230 } 226 case OpCode s.Exp: {231 case OpCode.Exp: { 227 232 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 228 233 result = Interval.Exponential(argumentInterval); 229 234 break; 230 235 } 231 case OpCode s.Power: {236 case OpCode.Power: { 232 237 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 233 238 for (int i = 1; i < currentInstr.nArguments; i++) { … … 237 242 break; 238 243 } 239 case OpCode s.Square: {244 case OpCode.Square: { 240 245 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 241 246 result = Interval.Square(argumentInterval); 242 247 break; 243 248 } 244 case OpCode s.Root: {249 case OpCode.Root: { 245 250 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 246 251 for (int i = 1; i < currentInstr.nArguments; i++) { … … 250 255 break; 251 256 } 252 case OpCode s.SquareRoot: {257 case OpCode.SquareRoot: { 253 258 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 254 259 result = Interval.SquareRoot(argumentInterval);
Note: See TracChangeset
for help on using the changeset viewer.