[6732] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16057] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6732] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[7615] | 23 | using System.Collections.Generic;
|
---|
[6741] | 24 | using System.Linq;
|
---|
[6732] | 25 | using System.Reflection;
|
---|
| 26 | using System.Reflection.Emit;
|
---|
| 27 | using HeuristicLab.Common;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
[6740] | 29 | using HeuristicLab.Data;
|
---|
[6732] | 30 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[6740] | 31 | using HeuristicLab.Parameters;
|
---|
[6732] | 32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
| 35 | [StorableClass]
|
---|
| 36 | [Item("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.")]
|
---|
[8436] | 37 | public sealed class SymbolicDataAnalysisExpressionTreeILEmittingInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
|
---|
| 38 | private static readonly Type thisType = typeof(SymbolicDataAnalysisExpressionTreeILEmittingInterpreter);
|
---|
| 39 | internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns);
|
---|
[7842] | 40 |
|
---|
[8436] | 41 | #region method infos
|
---|
| 42 | private static MethodInfo listGetValue = typeof(IList<double>).GetProperty("Item", new Type[] { typeof(int) }).GetGetMethod();
|
---|
| 43 |
|
---|
[6732] | 44 | private static MethodInfo cos = typeof(Math).GetMethod("Cos", new Type[] { typeof(double) });
|
---|
| 45 | private static MethodInfo sin = typeof(Math).GetMethod("Sin", new Type[] { typeof(double) });
|
---|
| 46 | private static MethodInfo tan = typeof(Math).GetMethod("Tan", new Type[] { typeof(double) });
|
---|
| 47 | private static MethodInfo exp = typeof(Math).GetMethod("Exp", new Type[] { typeof(double) });
|
---|
| 48 | private static MethodInfo log = typeof(Math).GetMethod("Log", new Type[] { typeof(double) });
|
---|
| 49 | private static MethodInfo power = typeof(Math).GetMethod("Pow", new Type[] { typeof(double), typeof(double) });
|
---|
[6755] | 50 | private static MethodInfo round = typeof(Math).GetMethod("Round", new Type[] { typeof(double) });
|
---|
[7842] | 51 | private static MethodInfo sqrt = typeof(Math).GetMethod("Sqrt", new Type[] { typeof(double) });
|
---|
[6732] | 52 |
|
---|
[7842] | 53 | private static MethodInfo airyA = thisType.GetMethod("AiryA", new Type[] { typeof(double) });
|
---|
| 54 | private static MethodInfo airyB = thisType.GetMethod("AiryB", new Type[] { typeof(double) });
|
---|
| 55 | private static MethodInfo gamma = thisType.GetMethod("Gamma", new Type[] { typeof(double) });
|
---|
| 56 | private static MethodInfo psi = thisType.GetMethod("Psi", new Type[] { typeof(double) });
|
---|
| 57 | private static MethodInfo dawson = thisType.GetMethod("Dawson", new Type[] { typeof(double) });
|
---|
| 58 | private static MethodInfo expIntegralEi = thisType.GetMethod("ExpIntegralEi", new Type[] { typeof(double) });
|
---|
| 59 | private static MethodInfo sinIntegral = thisType.GetMethod("SinIntegral", new Type[] { typeof(double) });
|
---|
| 60 | private static MethodInfo cosIntegral = thisType.GetMethod("CosIntegral", new Type[] { typeof(double) });
|
---|
| 61 | private static MethodInfo hypSinIntegral = thisType.GetMethod("HypSinIntegral", new Type[] { typeof(double) });
|
---|
| 62 | private static MethodInfo hypCosIntegral = thisType.GetMethod("HypCosIntegral", new Type[] { typeof(double) });
|
---|
| 63 | private static MethodInfo fresnelCosIntegral = thisType.GetMethod("FresnelCosIntegral", new Type[] { typeof(double) });
|
---|
| 64 | private static MethodInfo fresnelSinIntegral = thisType.GetMethod("FresnelSinIntegral", new Type[] { typeof(double) });
|
---|
| 65 | private static MethodInfo norm = thisType.GetMethod("Norm", new Type[] { typeof(double) });
|
---|
| 66 | private static MethodInfo erf = thisType.GetMethod("Erf", new Type[] { typeof(double) });
|
---|
| 67 | private static MethodInfo bessel = thisType.GetMethod("Bessel", new Type[] { typeof(double) });
|
---|
[14826] | 68 | private static MethodInfo string_eq = typeof(string).GetMethod("Equals", new Type[] { typeof(string) });
|
---|
[8436] | 69 | #endregion
|
---|
[7842] | 70 |
|
---|
[6732] | 71 | private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
|
---|
[13248] | 72 | private const string CheckExpressionsWithIntervalArithmeticParameterDescription = "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.";
|
---|
[7615] | 73 | private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
|
---|
[7842] | 74 |
|
---|
[6732] | 75 | public override bool CanChangeName {
|
---|
| 76 | get { return false; }
|
---|
| 77 | }
|
---|
[7842] | 78 |
|
---|
[6732] | 79 | public override bool CanChangeDescription {
|
---|
| 80 | get { return false; }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | #region parameter properties
|
---|
[13248] | 84 | public IFixedValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {
|
---|
| 85 | get { return (IFixedValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
|
---|
[6732] | 86 | }
|
---|
[7615] | 87 |
|
---|
[13248] | 88 | public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter {
|
---|
| 89 | get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
|
---|
[7615] | 90 | }
|
---|
[6732] | 91 | #endregion
|
---|
| 92 |
|
---|
| 93 | #region properties
|
---|
[13248] | 94 | public bool CheckExpressionsWithIntervalArithmetic {
|
---|
| 95 | get { return CheckExpressionsWithIntervalArithmeticParameter.Value.Value; }
|
---|
| 96 | set { CheckExpressionsWithIntervalArithmeticParameter.Value.Value = value; }
|
---|
[6732] | 97 | }
|
---|
[13248] | 98 | public int EvaluatedSolutions {
|
---|
| 99 | get { return EvaluatedSolutionsParameter.Value.Value; }
|
---|
| 100 | set { EvaluatedSolutionsParameter.Value.Value = value; }
|
---|
[7615] | 101 | }
|
---|
[6732] | 102 | #endregion
|
---|
| 103 |
|
---|
| 104 | [StorableConstructor]
|
---|
[8436] | 105 | private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(bool deserializing) : base(deserializing) { }
|
---|
[7842] | 106 |
|
---|
[8436] | 107 | private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(SymbolicDataAnalysisExpressionTreeILEmittingInterpreter original, Cloner cloner) : base(original, cloner) { }
|
---|
[6732] | 108 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 109 | return new SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(this, cloner);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | public SymbolicDataAnalysisExpressionTreeILEmittingInterpreter()
|
---|
| 113 | : base("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.") {
|
---|
[13248] | 114 | Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName,
|
---|
| 115 | "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
|
---|
| 116 | Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
|
---|
[6732] | 117 | }
|
---|
| 118 |
|
---|
[13248] | 119 | public SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(string name, string description)
|
---|
| 120 | : base(name, description) {
|
---|
| 121 | Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName,
|
---|
| 122 | "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
|
---|
| 123 | Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[7615] | 126 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 127 | private void AfterDeserialization() {
|
---|
[13248] | 128 | var evaluatedSolutions = new IntValue(0);
|
---|
| 129 | var checkExpressionsWithIntervalArithmetic = new BoolValue(false);
|
---|
| 130 | if (Parameters.ContainsKey(EvaluatedSolutionsParameterName)) {
|
---|
| 131 | var evaluatedSolutionsParameter = (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName];
|
---|
| 132 | evaluatedSolutions = evaluatedSolutionsParameter.Value;
|
---|
| 133 | Parameters.Remove(EvaluatedSolutionsParameterName);
|
---|
| 134 | }
|
---|
| 135 | Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", evaluatedSolutions));
|
---|
| 136 | if (Parameters.ContainsKey(CheckExpressionsWithIntervalArithmeticParameterName)) {
|
---|
| 137 | var checkExpressionsWithIntervalArithmeticParameter = (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName];
|
---|
| 138 | Parameters.Remove(CheckExpressionsWithIntervalArithmeticParameterName);
|
---|
| 139 | checkExpressionsWithIntervalArithmetic = checkExpressionsWithIntervalArithmeticParameter.Value;
|
---|
| 140 | }
|
---|
| 141 | Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, checkExpressionsWithIntervalArithmetic));
|
---|
[7615] | 142 | }
|
---|
| 143 |
|
---|
| 144 | #region IStatefulItem
|
---|
| 145 | public void InitializeState() {
|
---|
[13248] | 146 | EvaluatedSolutions = 0;
|
---|
[7615] | 147 | }
|
---|
| 148 |
|
---|
| 149 | public void ClearState() {
|
---|
| 150 | }
|
---|
| 151 | #endregion
|
---|
| 152 |
|
---|
[13251] | 153 | private readonly object syncRoot = new object();
|
---|
[12509] | 154 | public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
|
---|
[13248] | 155 | if (CheckExpressionsWithIntervalArithmetic)
|
---|
[8436] | 156 | throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
|
---|
| 157 |
|
---|
[13251] | 158 | lock (syncRoot) {
|
---|
| 159 | EvaluatedSolutions++; // increment the evaluated solutions counter
|
---|
| 160 | }
|
---|
[8436] | 161 | var state = PrepareInterpreterState(tree, dataset);
|
---|
[6741] | 162 |
|
---|
[8436] | 163 | Type[] methodArgs = { typeof(int), typeof(IList<double>[]) };
|
---|
| 164 | DynamicMethod testFun = new DynamicMethod("TestFun", typeof(double), methodArgs, typeof(SymbolicDataAnalysisExpressionTreeILEmittingInterpreter).Module);
|
---|
[6741] | 165 |
|
---|
[8436] | 166 | ILGenerator il = testFun.GetILGenerator();
|
---|
| 167 | CompileInstructions(il, state, dataset);
|
---|
| 168 | il.Emit(System.Reflection.Emit.OpCodes.Conv_R8);
|
---|
| 169 | il.Emit(System.Reflection.Emit.OpCodes.Ret);
|
---|
| 170 | var function = (CompiledFunction)testFun.CreateDelegate(typeof(CompiledFunction));
|
---|
| 171 |
|
---|
| 172 | IList<double>[] columns = dataset.DoubleVariables.Select(v => dataset.GetReadOnlyDoubleValues(v)).ToArray();
|
---|
| 173 |
|
---|
| 174 | foreach (var row in rows) {
|
---|
| 175 | yield return function(row, columns);
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
[12509] | 179 | private InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, IDataset dataset) {
|
---|
[8436] | 180 | Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode);
|
---|
| 181 | Dictionary<string, int> doubleVariableNames = dataset.DoubleVariables.Select((x, i) => new { x, i }).ToDictionary(e => e.x, e => e.i);
|
---|
| 182 | int necessaryArgStackSize = 0;
|
---|
| 183 | foreach (Instruction instr in code) {
|
---|
[6732] | 184 | if (instr.opCode == OpCodes.Variable) {
|
---|
[8436] | 185 | var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
|
---|
[9828] | 186 | instr.data = doubleVariableNames[variableTreeNode.VariableName];
|
---|
[6732] | 187 | } else if (instr.opCode == OpCodes.LagVariable) {
|
---|
[8436] | 188 | var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
|
---|
[9828] | 189 | instr.data = doubleVariableNames[laggedVariableTreeNode.VariableName];
|
---|
[6732] | 190 | } else if (instr.opCode == OpCodes.VariableCondition) {
|
---|
[8436] | 191 | var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode;
|
---|
[9828] | 192 | instr.data = doubleVariableNames[variableConditionTreeNode.VariableName];
|
---|
[6732] | 193 | } else if (instr.opCode == OpCodes.Call) {
|
---|
| 194 | necessaryArgStackSize += instr.nArguments + 1;
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
[8436] | 197 | return new InterpreterState(code, necessaryArgStackSize);
|
---|
[6732] | 198 | }
|
---|
| 199 |
|
---|
[12509] | 200 | private void CompileInstructions(ILGenerator il, InterpreterState state, IDataset ds) {
|
---|
[6732] | 201 | Instruction currentInstr = state.NextInstruction();
|
---|
| 202 | int nArgs = currentInstr.nArguments;
|
---|
| 203 |
|
---|
| 204 | switch (currentInstr.opCode) {
|
---|
| 205 | case OpCodes.Add: {
|
---|
| 206 | if (nArgs > 0) {
|
---|
[6809] | 207 | CompileInstructions(il, state, ds);
|
---|
[6732] | 208 | }
|
---|
| 209 | for (int i = 1; i < nArgs; i++) {
|
---|
[6809] | 210 | CompileInstructions(il, state, ds);
|
---|
[6732] | 211 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 212 | }
|
---|
| 213 | return;
|
---|
| 214 | }
|
---|
| 215 | case OpCodes.Sub: {
|
---|
| 216 | if (nArgs == 1) {
|
---|
[6809] | 217 | CompileInstructions(il, state, ds);
|
---|
[6732] | 218 | il.Emit(System.Reflection.Emit.OpCodes.Neg);
|
---|
| 219 | return;
|
---|
| 220 | }
|
---|
| 221 | if (nArgs > 0) {
|
---|
[6809] | 222 | CompileInstructions(il, state, ds);
|
---|
[6732] | 223 | }
|
---|
| 224 | for (int i = 1; i < nArgs; i++) {
|
---|
[6809] | 225 | CompileInstructions(il, state, ds);
|
---|
[6732] | 226 | il.Emit(System.Reflection.Emit.OpCodes.Sub);
|
---|
| 227 | }
|
---|
| 228 | return;
|
---|
| 229 | }
|
---|
| 230 | case OpCodes.Mul: {
|
---|
| 231 | if (nArgs > 0) {
|
---|
[6809] | 232 | CompileInstructions(il, state, ds);
|
---|
[6732] | 233 | }
|
---|
| 234 | for (int i = 1; i < nArgs; i++) {
|
---|
[6809] | 235 | CompileInstructions(il, state, ds);
|
---|
[6732] | 236 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
| 237 | }
|
---|
| 238 | return;
|
---|
| 239 | }
|
---|
| 240 | case OpCodes.Div: {
|
---|
| 241 | if (nArgs == 1) {
|
---|
| 242 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0);
|
---|
[6809] | 243 | CompileInstructions(il, state, ds);
|
---|
[6732] | 244 | il.Emit(System.Reflection.Emit.OpCodes.Div);
|
---|
| 245 | return;
|
---|
| 246 | }
|
---|
| 247 | if (nArgs > 0) {
|
---|
[6809] | 248 | CompileInstructions(il, state, ds);
|
---|
[6732] | 249 | }
|
---|
| 250 | for (int i = 1; i < nArgs; i++) {
|
---|
[6809] | 251 | CompileInstructions(il, state, ds);
|
---|
[6732] | 252 | il.Emit(System.Reflection.Emit.OpCodes.Div);
|
---|
| 253 | }
|
---|
| 254 | return;
|
---|
| 255 | }
|
---|
| 256 | case OpCodes.Average: {
|
---|
[6809] | 257 | CompileInstructions(il, state, ds);
|
---|
[6732] | 258 | for (int i = 1; i < nArgs; i++) {
|
---|
[6809] | 259 | CompileInstructions(il, state, ds);
|
---|
[6732] | 260 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 261 | }
|
---|
[14809] | 262 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, (double)nArgs);
|
---|
[6732] | 263 | il.Emit(System.Reflection.Emit.OpCodes.Div);
|
---|
| 264 | return;
|
---|
| 265 | }
|
---|
| 266 | case OpCodes.Cos: {
|
---|
[6809] | 267 | CompileInstructions(il, state, ds);
|
---|
[6732] | 268 | il.Emit(System.Reflection.Emit.OpCodes.Call, cos);
|
---|
| 269 | return;
|
---|
| 270 | }
|
---|
| 271 | case OpCodes.Sin: {
|
---|
[6809] | 272 | CompileInstructions(il, state, ds);
|
---|
[6732] | 273 | il.Emit(System.Reflection.Emit.OpCodes.Call, sin);
|
---|
| 274 | return;
|
---|
| 275 | }
|
---|
| 276 | case OpCodes.Tan: {
|
---|
[6809] | 277 | CompileInstructions(il, state, ds);
|
---|
[6732] | 278 | il.Emit(System.Reflection.Emit.OpCodes.Call, tan);
|
---|
| 279 | return;
|
---|
| 280 | }
|
---|
| 281 | case OpCodes.Power: {
|
---|
[6809] | 282 | CompileInstructions(il, state, ds);
|
---|
| 283 | CompileInstructions(il, state, ds);
|
---|
[6755] | 284 | il.Emit(System.Reflection.Emit.OpCodes.Call, round);
|
---|
[6732] | 285 | il.Emit(System.Reflection.Emit.OpCodes.Call, power);
|
---|
| 286 | return;
|
---|
| 287 | }
|
---|
| 288 | case OpCodes.Root: {
|
---|
[6809] | 289 | CompileInstructions(il, state, ds);
|
---|
[6755] | 290 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // 1 / round(...)
|
---|
[6809] | 291 | CompileInstructions(il, state, ds);
|
---|
[6755] | 292 | il.Emit(System.Reflection.Emit.OpCodes.Call, round);
|
---|
| 293 | il.Emit(System.Reflection.Emit.OpCodes.Div);
|
---|
| 294 | il.Emit(System.Reflection.Emit.OpCodes.Call, power);
|
---|
| 295 | return;
|
---|
[6732] | 296 | }
|
---|
| 297 | case OpCodes.Exp: {
|
---|
[6809] | 298 | CompileInstructions(il, state, ds);
|
---|
[6732] | 299 | il.Emit(System.Reflection.Emit.OpCodes.Call, exp);
|
---|
| 300 | return;
|
---|
| 301 | }
|
---|
| 302 | case OpCodes.Log: {
|
---|
[6809] | 303 | CompileInstructions(il, state, ds);
|
---|
[6732] | 304 | il.Emit(System.Reflection.Emit.OpCodes.Call, log);
|
---|
| 305 | return;
|
---|
| 306 | }
|
---|
[7842] | 307 | case OpCodes.Square: {
|
---|
| 308 | CompileInstructions(il, state, ds);
|
---|
| 309 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0);
|
---|
| 310 | il.Emit(System.Reflection.Emit.OpCodes.Call, power);
|
---|
| 311 | return;
|
---|
| 312 | }
|
---|
| 313 | case OpCodes.SquareRoot: {
|
---|
| 314 | CompileInstructions(il, state, ds);
|
---|
| 315 | il.Emit(System.Reflection.Emit.OpCodes.Call, sqrt);
|
---|
| 316 | return;
|
---|
| 317 | }
|
---|
| 318 | case OpCodes.AiryA: {
|
---|
| 319 | CompileInstructions(il, state, ds);
|
---|
| 320 | il.Emit(System.Reflection.Emit.OpCodes.Call, airyA);
|
---|
| 321 | return;
|
---|
| 322 | }
|
---|
| 323 | case OpCodes.AiryB: {
|
---|
| 324 | CompileInstructions(il, state, ds);
|
---|
| 325 | il.Emit(System.Reflection.Emit.OpCodes.Call, airyB);
|
---|
| 326 | return;
|
---|
| 327 | }
|
---|
| 328 | case OpCodes.Bessel: {
|
---|
| 329 | CompileInstructions(il, state, ds);
|
---|
| 330 | il.Emit(System.Reflection.Emit.OpCodes.Call, bessel);
|
---|
| 331 | return;
|
---|
| 332 | }
|
---|
| 333 | case OpCodes.CosineIntegral: {
|
---|
| 334 | CompileInstructions(il, state, ds);
|
---|
| 335 | il.Emit(System.Reflection.Emit.OpCodes.Call, cosIntegral);
|
---|
| 336 | return;
|
---|
| 337 | }
|
---|
| 338 | case OpCodes.Dawson: {
|
---|
| 339 | CompileInstructions(il, state, ds);
|
---|
| 340 | il.Emit(System.Reflection.Emit.OpCodes.Call, dawson);
|
---|
| 341 | return;
|
---|
| 342 | }
|
---|
| 343 | case OpCodes.Erf: {
|
---|
| 344 | CompileInstructions(il, state, ds);
|
---|
| 345 | il.Emit(System.Reflection.Emit.OpCodes.Call, erf);
|
---|
| 346 | return;
|
---|
| 347 | }
|
---|
| 348 | case OpCodes.ExponentialIntegralEi: {
|
---|
| 349 | CompileInstructions(il, state, ds);
|
---|
| 350 | il.Emit(System.Reflection.Emit.OpCodes.Call, expIntegralEi);
|
---|
| 351 | return;
|
---|
| 352 | }
|
---|
| 353 | case OpCodes.FresnelCosineIntegral: {
|
---|
| 354 | CompileInstructions(il, state, ds);
|
---|
| 355 | il.Emit(System.Reflection.Emit.OpCodes.Call, fresnelCosIntegral);
|
---|
| 356 | return;
|
---|
| 357 | }
|
---|
| 358 | case OpCodes.FresnelSineIntegral: {
|
---|
| 359 | CompileInstructions(il, state, ds);
|
---|
| 360 | il.Emit(System.Reflection.Emit.OpCodes.Call, fresnelSinIntegral);
|
---|
| 361 | return;
|
---|
| 362 | }
|
---|
| 363 | case OpCodes.Gamma: {
|
---|
| 364 | CompileInstructions(il, state, ds);
|
---|
| 365 | il.Emit(System.Reflection.Emit.OpCodes.Call, gamma);
|
---|
| 366 | return;
|
---|
| 367 | }
|
---|
| 368 | case OpCodes.HyperbolicCosineIntegral: {
|
---|
| 369 | CompileInstructions(il, state, ds);
|
---|
| 370 | il.Emit(System.Reflection.Emit.OpCodes.Call, hypCosIntegral);
|
---|
| 371 | return;
|
---|
| 372 | }
|
---|
| 373 | case OpCodes.HyperbolicSineIntegral: {
|
---|
| 374 | CompileInstructions(il, state, ds);
|
---|
| 375 | il.Emit(System.Reflection.Emit.OpCodes.Call, hypSinIntegral);
|
---|
| 376 | return;
|
---|
| 377 | }
|
---|
| 378 | case OpCodes.Norm: {
|
---|
| 379 | CompileInstructions(il, state, ds);
|
---|
| 380 | il.Emit(System.Reflection.Emit.OpCodes.Call, norm);
|
---|
| 381 | return;
|
---|
| 382 | }
|
---|
| 383 | case OpCodes.Psi: {
|
---|
| 384 | CompileInstructions(il, state, ds);
|
---|
| 385 | il.Emit(System.Reflection.Emit.OpCodes.Call, psi);
|
---|
| 386 | return;
|
---|
| 387 | }
|
---|
| 388 | case OpCodes.SineIntegral: {
|
---|
| 389 | CompileInstructions(il, state, ds);
|
---|
| 390 | il.Emit(System.Reflection.Emit.OpCodes.Call, sinIntegral);
|
---|
| 391 | return;
|
---|
| 392 | }
|
---|
[6732] | 393 | case OpCodes.IfThenElse: {
|
---|
| 394 | Label end = il.DefineLabel();
|
---|
| 395 | Label c1 = il.DefineLabel();
|
---|
[6809] | 396 | CompileInstructions(il, state, ds);
|
---|
[6732] | 397 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
|
---|
| 398 | il.Emit(System.Reflection.Emit.OpCodes.Cgt);
|
---|
| 399 | il.Emit(System.Reflection.Emit.OpCodes.Brfalse, c1);
|
---|
[6809] | 400 | CompileInstructions(il, state, ds);
|
---|
[6732] | 401 | il.Emit(System.Reflection.Emit.OpCodes.Br, end);
|
---|
| 402 | il.MarkLabel(c1);
|
---|
[6809] | 403 | CompileInstructions(il, state, ds);
|
---|
[6732] | 404 | il.MarkLabel(end);
|
---|
| 405 | return;
|
---|
| 406 | }
|
---|
| 407 | case OpCodes.AND: {
|
---|
| 408 | Label falseBranch = il.DefineLabel();
|
---|
| 409 | Label end = il.DefineLabel();
|
---|
[6809] | 410 | CompileInstructions(il, state, ds);
|
---|
[6732] | 411 | for (int i = 1; i < nArgs; i++) {
|
---|
| 412 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
|
---|
| 413 | il.Emit(System.Reflection.Emit.OpCodes.Cgt);
|
---|
| 414 | il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch);
|
---|
[6809] | 415 | CompileInstructions(il, state, ds);
|
---|
[6732] | 416 | }
|
---|
| 417 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
|
---|
| 418 | il.Emit(System.Reflection.Emit.OpCodes.Cgt);
|
---|
| 419 | il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch);
|
---|
| 420 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // 1
|
---|
| 421 | il.Emit(System.Reflection.Emit.OpCodes.Br, end);
|
---|
| 422 | il.MarkLabel(falseBranch);
|
---|
| 423 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // -1
|
---|
| 424 | il.Emit(System.Reflection.Emit.OpCodes.Neg);
|
---|
| 425 | il.MarkLabel(end);
|
---|
| 426 | return;
|
---|
| 427 | }
|
---|
| 428 | case OpCodes.OR: {
|
---|
| 429 | Label trueBranch = il.DefineLabel();
|
---|
| 430 | Label end = il.DefineLabel();
|
---|
| 431 | Label resultBranch = il.DefineLabel();
|
---|
[6809] | 432 | CompileInstructions(il, state, ds);
|
---|
[6732] | 433 | for (int i = 1; i < nArgs; i++) {
|
---|
| 434 | Label nextArgBranch = il.DefineLabel();
|
---|
| 435 | // complex definition because of special properties of NaN
|
---|
| 436 | il.Emit(System.Reflection.Emit.OpCodes.Dup);
|
---|
| 437 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // <= 0
|
---|
| 438 | il.Emit(System.Reflection.Emit.OpCodes.Ble, nextArgBranch);
|
---|
| 439 | il.Emit(System.Reflection.Emit.OpCodes.Br, resultBranch);
|
---|
| 440 | il.MarkLabel(nextArgBranch);
|
---|
| 441 | il.Emit(System.Reflection.Emit.OpCodes.Pop);
|
---|
[6809] | 442 | CompileInstructions(il, state, ds);
|
---|
[6732] | 443 | }
|
---|
| 444 | il.MarkLabel(resultBranch);
|
---|
| 445 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
|
---|
| 446 | il.Emit(System.Reflection.Emit.OpCodes.Cgt);
|
---|
| 447 | il.Emit(System.Reflection.Emit.OpCodes.Brtrue, trueBranch);
|
---|
| 448 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // -1
|
---|
| 449 | il.Emit(System.Reflection.Emit.OpCodes.Neg);
|
---|
| 450 | il.Emit(System.Reflection.Emit.OpCodes.Br, end);
|
---|
| 451 | il.MarkLabel(trueBranch);
|
---|
| 452 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // 1
|
---|
| 453 | il.MarkLabel(end);
|
---|
| 454 | return;
|
---|
| 455 | }
|
---|
| 456 | case OpCodes.NOT: {
|
---|
[6809] | 457 | CompileInstructions(il, state, ds);
|
---|
[6732] | 458 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
|
---|
| 459 | il.Emit(System.Reflection.Emit.OpCodes.Cgt);
|
---|
[14809] | 460 | il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
|
---|
[6732] | 461 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2
|
---|
| 462 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
| 463 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // - 1
|
---|
| 464 | il.Emit(System.Reflection.Emit.OpCodes.Sub);
|
---|
| 465 | il.Emit(System.Reflection.Emit.OpCodes.Neg); // * -1
|
---|
| 466 | return;
|
---|
| 467 | }
|
---|
[10791] | 468 | case OpCodes.XOR: {
|
---|
| 469 | CompileInstructions(il, state, ds);
|
---|
| 470 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0);
|
---|
| 471 | il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0
|
---|
| 472 |
|
---|
| 473 | for (int i = 1; i < nArgs; i++) {
|
---|
| 474 | CompileInstructions(il, state, ds);
|
---|
| 475 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0);
|
---|
| 476 | il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0
|
---|
| 477 | il.Emit(System.Reflection.Emit.OpCodes.Xor);
|
---|
| 478 | }
|
---|
[14809] | 479 | il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
|
---|
| 480 |
|
---|
[10791] | 481 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2
|
---|
| 482 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
| 483 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // - 1
|
---|
| 484 | il.Emit(System.Reflection.Emit.OpCodes.Sub);
|
---|
| 485 | return;
|
---|
| 486 | }
|
---|
[6732] | 487 | case OpCodes.GT: {
|
---|
[6809] | 488 | CompileInstructions(il, state, ds);
|
---|
| 489 | CompileInstructions(il, state, ds);
|
---|
| 490 |
|
---|
[6732] | 491 | il.Emit(System.Reflection.Emit.OpCodes.Cgt); // 1 (>) / 0 (otherwise)
|
---|
[14809] | 492 | il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
|
---|
[6732] | 493 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2
|
---|
| 494 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
| 495 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // - 1
|
---|
| 496 | il.Emit(System.Reflection.Emit.OpCodes.Sub);
|
---|
| 497 | return;
|
---|
| 498 | }
|
---|
| 499 | case OpCodes.LT: {
|
---|
[6809] | 500 | CompileInstructions(il, state, ds);
|
---|
| 501 | CompileInstructions(il, state, ds);
|
---|
[6732] | 502 | il.Emit(System.Reflection.Emit.OpCodes.Clt);
|
---|
[14809] | 503 | il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
|
---|
[6732] | 504 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2
|
---|
| 505 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
| 506 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // - 1
|
---|
| 507 | il.Emit(System.Reflection.Emit.OpCodes.Sub);
|
---|
| 508 | return;
|
---|
| 509 | }
|
---|
| 510 | case OpCodes.TimeLag: {
|
---|
[6809] | 511 | LaggedTreeNode laggedTreeNode = (LaggedTreeNode)currentInstr.dynamicNode;
|
---|
| 512 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // row -= lag
|
---|
| 513 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, laggedTreeNode.Lag);
|
---|
| 514 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 515 | il.Emit(System.Reflection.Emit.OpCodes.Starg, 0);
|
---|
[6849] | 516 | var prevLaggedContext = state.InLaggedContext;
|
---|
| 517 | state.InLaggedContext = true;
|
---|
[6809] | 518 | CompileInstructions(il, state, ds);
|
---|
| 519 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // row += lag
|
---|
| 520 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, laggedTreeNode.Lag);
|
---|
| 521 | il.Emit(System.Reflection.Emit.OpCodes.Sub);
|
---|
| 522 | il.Emit(System.Reflection.Emit.OpCodes.Starg, 0);
|
---|
[6849] | 523 | state.InLaggedContext = prevLaggedContext;
|
---|
[6809] | 524 | return;
|
---|
[6732] | 525 | }
|
---|
| 526 | case OpCodes.Integral: {
|
---|
[6809] | 527 | int savedPc = state.ProgramCounter;
|
---|
| 528 | LaggedTreeNode laggedTreeNode = (LaggedTreeNode)currentInstr.dynamicNode;
|
---|
| 529 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // row -= lag
|
---|
| 530 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, laggedTreeNode.Lag);
|
---|
| 531 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 532 | il.Emit(System.Reflection.Emit.OpCodes.Starg, 0);
|
---|
[6849] | 533 | var prevLaggedContext = state.InLaggedContext;
|
---|
| 534 | state.InLaggedContext = true;
|
---|
[6809] | 535 | CompileInstructions(il, state, ds);
|
---|
| 536 | for (int l = laggedTreeNode.Lag; l < 0; l++) {
|
---|
| 537 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // row += lag
|
---|
| 538 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_1);
|
---|
| 539 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 540 | il.Emit(System.Reflection.Emit.OpCodes.Starg, 0);
|
---|
| 541 | state.ProgramCounter = savedPc;
|
---|
| 542 | CompileInstructions(il, state, ds);
|
---|
| 543 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 544 | }
|
---|
[6849] | 545 | state.InLaggedContext = prevLaggedContext;
|
---|
[6809] | 546 | return;
|
---|
[6732] | 547 | }
|
---|
| 548 |
|
---|
| 549 | //mkommend: derivate calculation taken from:
|
---|
| 550 | //http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
|
---|
| 551 | //one sided smooth differentiatior, N = 4
|
---|
| 552 | // y' = 1/8h (f_i + 2f_i-1, -2 f_i-3 - f_i-4)
|
---|
| 553 | case OpCodes.Derivative: {
|
---|
[6809] | 554 | int savedPc = state.ProgramCounter;
|
---|
| 555 | CompileInstructions(il, state, ds);
|
---|
| 556 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // row --
|
---|
| 557 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_M1);
|
---|
| 558 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 559 | il.Emit(System.Reflection.Emit.OpCodes.Starg, 0);
|
---|
| 560 | state.ProgramCounter = savedPc;
|
---|
[6849] | 561 | var prevLaggedContext = state.InLaggedContext;
|
---|
| 562 | state.InLaggedContext = true;
|
---|
[6809] | 563 | CompileInstructions(il, state, ds);
|
---|
| 564 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // f_0 + 2 * f_1
|
---|
| 565 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
| 566 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 567 |
|
---|
| 568 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // row -=2
|
---|
| 569 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_2);
|
---|
| 570 | il.Emit(System.Reflection.Emit.OpCodes.Sub);
|
---|
| 571 | il.Emit(System.Reflection.Emit.OpCodes.Starg, 0);
|
---|
| 572 | state.ProgramCounter = savedPc;
|
---|
| 573 | CompileInstructions(il, state, ds);
|
---|
| 574 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // f_0 + 2 * f_1 - 2 * f_3
|
---|
| 575 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
| 576 | il.Emit(System.Reflection.Emit.OpCodes.Sub);
|
---|
| 577 |
|
---|
| 578 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // row --
|
---|
| 579 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_M1);
|
---|
| 580 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 581 | il.Emit(System.Reflection.Emit.OpCodes.Starg, 0);
|
---|
| 582 | state.ProgramCounter = savedPc;
|
---|
| 583 | CompileInstructions(il, state, ds);
|
---|
| 584 | il.Emit(System.Reflection.Emit.OpCodes.Sub); // f_0 + 2 * f_1 - 2 * f_3 - f_4
|
---|
| 585 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 8.0); // / 8
|
---|
| 586 | il.Emit(System.Reflection.Emit.OpCodes.Div);
|
---|
| 587 |
|
---|
| 588 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // row +=4
|
---|
| 589 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_4);
|
---|
| 590 | il.Emit(System.Reflection.Emit.OpCodes.Add);
|
---|
| 591 | il.Emit(System.Reflection.Emit.OpCodes.Starg, 0);
|
---|
[6849] | 592 | state.InLaggedContext = prevLaggedContext;
|
---|
[6809] | 593 | return;
|
---|
[6732] | 594 | }
|
---|
| 595 | case OpCodes.Call: {
|
---|
[7842] | 596 | throw new NotSupportedException(
|
---|
| 597 | "Automatically defined functions are not supported by the SymbolicDataAnalysisTreeILEmittingInterpreter. Either turn of ADFs or change the interpeter.");
|
---|
[6732] | 598 | }
|
---|
| 599 | case OpCodes.Arg: {
|
---|
[7842] | 600 | throw new NotSupportedException(
|
---|
| 601 | "Automatically defined functions are not supported by the SymbolicDataAnalysisTreeILEmittingInterpreter. Either turn of ADFs or change the interpeter.");
|
---|
[6732] | 602 | }
|
---|
| 603 | case OpCodes.Variable: {
|
---|
[6741] | 604 | VariableTreeNode varNode = (VariableTreeNode)currentInstr.dynamicNode;
|
---|
[8798] | 605 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array
|
---|
[9828] | 606 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.data);
|
---|
[8798] | 607 | // load correct column of the current variable
|
---|
| 608 | il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
|
---|
| 609 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
|
---|
[6849] | 610 | if (!state.InLaggedContext) {
|
---|
| 611 | il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue);
|
---|
| 612 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.Weight); // load weight
|
---|
| 613 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
| 614 | } else {
|
---|
| 615 | var nanResult = il.DefineLabel();
|
---|
| 616 | var normalResult = il.DefineLabel();
|
---|
| 617 | il.Emit(System.Reflection.Emit.OpCodes.Dup);
|
---|
| 618 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0);
|
---|
| 619 | il.Emit(System.Reflection.Emit.OpCodes.Blt, nanResult);
|
---|
| 620 | il.Emit(System.Reflection.Emit.OpCodes.Dup);
|
---|
| 621 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, ds.Rows);
|
---|
| 622 | il.Emit(System.Reflection.Emit.OpCodes.Bge, nanResult);
|
---|
| 623 | il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue);
|
---|
| 624 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.Weight); // load weight
|
---|
| 625 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
| 626 | il.Emit(System.Reflection.Emit.OpCodes.Br, normalResult);
|
---|
| 627 | il.MarkLabel(nanResult);
|
---|
| 628 | il.Emit(System.Reflection.Emit.OpCodes.Pop); // rowIndex
|
---|
[8798] | 629 | il.Emit(System.Reflection.Emit.OpCodes.Pop); // column reference
|
---|
[6849] | 630 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, double.NaN);
|
---|
| 631 | il.MarkLabel(normalResult);
|
---|
| 632 | }
|
---|
[6732] | 633 | return;
|
---|
| 634 | }
|
---|
| 635 | case OpCodes.LagVariable: {
|
---|
[6809] | 636 | var nanResult = il.DefineLabel();
|
---|
| 637 | var normalResult = il.DefineLabel();
|
---|
[6770] | 638 | LaggedVariableTreeNode varNode = (LaggedVariableTreeNode)currentInstr.dynamicNode;
|
---|
[8798] | 639 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array
|
---|
[9828] | 640 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.data);
|
---|
[8798] | 641 | // load correct column of the current variable
|
---|
| 642 | il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
|
---|
[6770] | 643 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, varNode.Lag); // lag
|
---|
[6849] | 644 | il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex
|
---|
| 645 | il.Emit(System.Reflection.Emit.OpCodes.Add); // actualRowIndex = rowIndex + sampleOffset
|
---|
[6809] | 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);
|
---|
[6770] | 652 | il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue);
|
---|
| 653 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.Weight); // load weight
|
---|
| 654 | il.Emit(System.Reflection.Emit.OpCodes.Mul);
|
---|
[6809] | 655 | il.Emit(System.Reflection.Emit.OpCodes.Br, normalResult);
|
---|
| 656 | il.MarkLabel(nanResult);
|
---|
[8798] | 657 | il.Emit(System.Reflection.Emit.OpCodes.Pop); // sample index
|
---|
| 658 | il.Emit(System.Reflection.Emit.OpCodes.Pop); // column reference
|
---|
[6809] | 659 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, double.NaN);
|
---|
| 660 | il.MarkLabel(normalResult);
|
---|
[6770] | 661 | return;
|
---|
[6732] | 662 | }
|
---|
| 663 | case OpCodes.Constant: {
|
---|
| 664 | ConstantTreeNode constNode = (ConstantTreeNode)currentInstr.dynamicNode;
|
---|
| 665 | il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value);
|
---|
| 666 | return;
|
---|
| 667 | }
|
---|
| 668 |
|
---|
| 669 | //mkommend: this symbol uses the logistic function f(x) = 1 / (1 + e^(-alpha * x) )
|
---|
| 670 | //to determine the relative amounts of the true and false branch see http://en.wikipedia.org/wiki/Logistic_function
|
---|
| 671 | case OpCodes.VariableCondition: {
|
---|
[7842] | 672 | throw new NotSupportedException("Interpretation of symbol " + currentInstr.dynamicNode.Symbol.Name +
|
---|
| 673 | " is not supported by the SymbolicDataAnalysisTreeILEmittingInterpreter");
|
---|
[6732] | 674 | }
|
---|
[7842] | 675 | default:
|
---|
| 676 | throw new NotSupportedException("Interpretation of symbol " + currentInstr.dynamicNode.Symbol.Name +
|
---|
| 677 | " is not supported by the SymbolicDataAnalysisTreeILEmittingInterpreter");
|
---|
[6732] | 678 | }
|
---|
| 679 | }
|
---|
| 680 |
|
---|
[7842] | 681 | public static double AiryA(double x) {
|
---|
| 682 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 683 | double ai, aip, bi, bip;
|
---|
| 684 | alglib.airy(x, out ai, out aip, out bi, out bip);
|
---|
| 685 | return ai;
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | public static double AiryB(double x) {
|
---|
| 689 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 690 | double ai, aip, bi, bip;
|
---|
| 691 | alglib.airy(x, out ai, out aip, out bi, out bip);
|
---|
| 692 | return bi;
|
---|
| 693 | }
|
---|
| 694 | public static double Dawson(double x) {
|
---|
| 695 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 696 | return alglib.dawsonintegral(x);
|
---|
| 697 | }
|
---|
| 698 |
|
---|
| 699 | public static double Gamma(double x) {
|
---|
| 700 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 701 | return alglib.gammafunction(x);
|
---|
| 702 | }
|
---|
| 703 |
|
---|
| 704 | public static double Psi(double x) {
|
---|
| 705 | if (double.IsNaN(x)) return double.NaN;
|
---|
[8430] | 706 | else if (x <= 0 && (Math.Floor(x) - x).IsAlmost(0)) return double.NaN;
|
---|
[7842] | 707 | return alglib.psi(x);
|
---|
| 708 | }
|
---|
| 709 |
|
---|
| 710 | public static double ExpIntegralEi(double x) {
|
---|
| 711 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 712 | return alglib.exponentialintegralei(x);
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | public static double SinIntegral(double x) {
|
---|
| 716 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 717 | double si, ci;
|
---|
| 718 | alglib.sinecosineintegrals(x, out si, out ci);
|
---|
| 719 | return si;
|
---|
| 720 | }
|
---|
| 721 |
|
---|
| 722 | public static double CosIntegral(double x) {
|
---|
| 723 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 724 | double si, ci;
|
---|
| 725 | alglib.sinecosineintegrals(x, out si, out ci);
|
---|
| 726 | return ci;
|
---|
| 727 | }
|
---|
| 728 |
|
---|
| 729 | public static double HypSinIntegral(double x) {
|
---|
| 730 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 731 | double shi, chi;
|
---|
| 732 | alglib.hyperbolicsinecosineintegrals(x, out shi, out chi);
|
---|
[8430] | 733 | return shi;
|
---|
[7842] | 734 | }
|
---|
| 735 |
|
---|
| 736 | public static double HypCosIntegral(double x) {
|
---|
| 737 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 738 | double shi, chi;
|
---|
| 739 | alglib.hyperbolicsinecosineintegrals(x, out shi, out chi);
|
---|
| 740 | return chi;
|
---|
| 741 | }
|
---|
| 742 |
|
---|
| 743 | public static double FresnelCosIntegral(double x) {
|
---|
| 744 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 745 | double c = 0, s = 0;
|
---|
| 746 | alglib.fresnelintegral(x, ref c, ref s);
|
---|
| 747 | return c;
|
---|
| 748 | }
|
---|
| 749 |
|
---|
| 750 | public static double FresnelSinIntegral(double x) {
|
---|
| 751 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 752 | double c = 0, s = 0;
|
---|
| 753 | alglib.fresnelintegral(x, ref c, ref s);
|
---|
| 754 | return s;
|
---|
| 755 | }
|
---|
| 756 |
|
---|
| 757 | public static double Norm(double x) {
|
---|
| 758 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 759 | return alglib.normaldistribution(x);
|
---|
| 760 | }
|
---|
| 761 |
|
---|
| 762 | public static double Erf(double x) {
|
---|
| 763 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 764 | return alglib.errorfunction(x);
|
---|
| 765 | }
|
---|
| 766 |
|
---|
| 767 | public static double Bessel(double x) {
|
---|
| 768 | if (double.IsNaN(x)) return double.NaN;
|
---|
| 769 | return alglib.besseli0(x);
|
---|
| 770 | }
|
---|
[6732] | 771 | }
|
---|
| 772 | }
|
---|