Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/13/19 09:30:18 (6 years ago)
Author:
gkronber
Message:

#2974: merged r16478:16672 from trunk:HeuristicLab.Problems.DataAnalysis.Symbolic to branch:HeuristicLab.Problems.DataAnalysis.Symbolic

Location:
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/BatchOperations.cs

    r16356 r16676  
    6969        a[i] = Math.Tan(b[i]);
    7070    }
     71    public static void Tanh(double[] a, double[] b) {
     72      for (int i = 0; i < BATCHSIZE; ++i)
     73        a[i] = Math.Tanh(b[i]);
     74    }
    7175
    7276    public static void Pow(double[] a, double[] b) {
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/InterpreterState.cs

    r15583 r16676  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r16407 r16676  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HEAL.Attic;
    3030using HeuristicLab.Parameters;
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    33   [StorableClass]
     33  [StorableType("DE6C1E1E-D7C1-4070-847E-63B68562B10C")]
    3434  [Item("IntervalInterpreter", "Intperter for calculation of intervals of symbolic models.")]
    3535  public sealed class IntervalInterpreter : ParameterizedNamedItem, IStatefulItem {
     
    4747
    4848    [StorableConstructor]
    49     private IntervalInterpreter(bool deserializing) : base(deserializing) { }
     49    private IntervalInterpreter(StorableConstructorFlag _) : base(_) { }
    5050    private IntervalInterpreter(IntervalInterpreter original, Cloner cloner)
    5151        : base(original, cloner) { }
     
    8888      var outputInterval = Evaluate(instructions, ref instructionCount);
    8989
    90       return outputInterval;
     90      // because of numerical errors the bounds might be incorrect
     91      if (outputInterval.LowerBound <= outputInterval.UpperBound)
     92        return outputInterval;
     93      else
     94        return new Interval(outputInterval.UpperBound, outputInterval.LowerBound);
    9195    }
    9296
     
    102106      var outputInterval = Evaluate(instructions, ref instructionCount, intervals);
    103107
    104       nodeIntervals = intervals;
    105 
    106       return outputInterval;
     108      // fix incorrect intervals if necessary (could occur because of numerical errors)
     109      nodeIntervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
     110      foreach(var kvp in intervals) {
     111        var interval = kvp.Value;
     112        if (interval.IsInfiniteOrUndefined || interval.LowerBound <= interval.UpperBound)
     113          nodeIntervals.Add(kvp.Key, interval);
     114        else
     115          nodeIntervals.Add(kvp.Key, new Interval(interval.UpperBound, interval.LowerBound));
     116      }
     117
     118      // because of numerical errors the bounds might be incorrect
     119      if (outputInterval.IsInfiniteOrUndefined || outputInterval.LowerBound <= outputInterval.UpperBound)
     120        return outputInterval;
     121      else
     122        return new Interval(outputInterval.UpperBound, outputInterval.LowerBound);
    107123    }
    108124
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r16360 r16676  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    9090    public const byte CubeRoot = 51;
    9191
     92    public const byte Tanh = 52;
     93
    9294
    9395    private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
     
    99101      { typeof(Cosine), OpCodes.Cos },
    100102      { typeof(Tangent), OpCodes.Tan },
     103      { typeof (HyperbolicTangent), OpCodes.Tanh},
    101104      { typeof(Logarithm), OpCodes.Log },
    102105      { typeof(Exponential), OpCodes.Exp },
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs

    r16360 r16676  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3131using HeuristicLab.Parameters;
    32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HEAL.Attic;
    3333
    3434namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    35   [StorableClass]
     35  [StorableType("DFA06F28-E224-4D93-9907-69792D24D1F9")]
    3636  [Item("SymbolicDataAnalysisExpressionCompiledTreeInterpreter", "Interpreter that converts the tree into a Linq.Expression then compiles it.")]
    3737  public sealed class SymbolicDataAnalysisExpressionCompiledTreeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
     
    4545    private static readonly MethodInfo Cos = typeof(Math).GetMethod("Cos", new[] { typeof(double) });
    4646    private static readonly MethodInfo Tan = typeof(Math).GetMethod("Tan", new[] { typeof(double) });
     47    private static readonly MethodInfo Tanh = typeof(Math).GetMethod("Tanh", new[] { typeof(double) });
    4748    private static readonly MethodInfo Sqrt = typeof(Math).GetMethod("Sqrt", new[] { typeof(double) });
    4849    private static readonly MethodInfo Floor = typeof(Math).GetMethod("Floor", new[] { typeof(double) });
     
    9899
    99100    [StorableConstructor]
    100     private SymbolicDataAnalysisExpressionCompiledTreeInterpreter(bool deserializing)
    101       : base(deserializing) {
     101    private SymbolicDataAnalysisExpressionCompiledTreeInterpreter(StorableConstructorFlag _) : base(_) {
    102102    }
    103103
     
    223223            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
    224224            return Expression.Call(Tan, arg);
     225          }
     226        case OpCodes.Tanh: {
     227            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
     228            return Expression.Call(Tanh, arg);
    225229          }
    226230        case OpCodes.Square: {
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs

    r16378 r16676  
    88using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    99using HeuristicLab.Parameters;
    10 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     10using HEAL.Attic;
    1111
    1212using static HeuristicLab.Problems.DataAnalysis.Symbolic.BatchOperations;
     
    1414namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    1515  [Item("SymbolicDataAnalysisExpressionTreeBatchInterpreter", "An interpreter that uses batching and vectorization techniques to achieve faster performance.")]
    16   [StorableClass]
     16  [StorableType("BEB15146-BB95-4838-83AC-6838543F017B")]
    1717  public class SymbolicDataAnalysisExpressionTreeBatchInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
    1818    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
     
    3838
    3939    [StorableConstructor]
    40     protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(bool deserializing) : base(deserializing) { }
     40    protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(StorableConstructorFlag _) : base(_) { }
    4141    protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(SymbolicDataAnalysisExpressionTreeBatchInterpreter original, Cloner cloner) : base(original, cloner) {
    4242    }
     
    159159              break;
    160160            }
    161 
     161          case OpCodes.Tanh: {
     162              Tanh(instr.buf, code[c].buf);
     163              break;
     164            }
    162165          case OpCodes.Absolute: {
    163166              Absolute(instr.buf, code[c].buf);
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r16360 r16676  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3131using HeuristicLab.Parameters;
    32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HEAL.Attic;
    3333
    3434namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    35   [StorableClass]
     35  [StorableType("426718E3-2A57-4CA4-98A1-65EDD0B0BDBF")]
    3636  [Item("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.")]
    3737  public sealed class SymbolicDataAnalysisExpressionTreeILEmittingInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
     
    4545    private static MethodInfo sin = typeof(Math).GetMethod("Sin", new Type[] { typeof(double) });
    4646    private static MethodInfo tan = typeof(Math).GetMethod("Tan", new Type[] { typeof(double) });
     47    private static MethodInfo tanh = typeof(Math).GetMethod("Tanh", new Type[] { typeof(double) });
    4748    private static MethodInfo exp = typeof(Math).GetMethod("Exp", new Type[] { typeof(double) });
    4849    private static MethodInfo log = typeof(Math).GetMethod("Log", new Type[] { typeof(double) });
     
    104105
    105106    [StorableConstructor]
    106     private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(bool deserializing) : base(deserializing) { }
     107    private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(StorableConstructorFlag _) : base(_) { }
    107108
    108109    private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(SymbolicDataAnalysisExpressionTreeILEmittingInterpreter original, Cloner cloner) : base(original, cloner) { }
     
    285286            return;
    286287          }
     288        case OpCodes.Tanh: {
     289            CompileInstructions(il, state, ds);
     290            il.Emit(System.Reflection.Emit.OpCodes.Call, tanh);
     291            return;
     292          }
    287293        case OpCodes.Power: {
    288294            CompileInstructions(il, state, ds);
     
    425431            Label c1 = il.DefineLabel();
    426432            CompileInstructions(il, state, ds);
    427             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     433            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    428434            il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    429435            il.Emit(System.Reflection.Emit.OpCodes.Brfalse, c1);
     
    440446            CompileInstructions(il, state, ds);
    441447            for (int i = 1; i < nArgs; i++) {
    442               il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     448              il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    443449              il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    444450              il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch);
    445451              CompileInstructions(il, state, ds);
    446452            }
    447             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     453            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    448454            il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    449455            il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch);
     
    465471              // complex definition because of special properties of NaN 
    466472              il.Emit(System.Reflection.Emit.OpCodes.Dup);
    467               il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // <= 0       
     473              il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // <= 0       
    468474              il.Emit(System.Reflection.Emit.OpCodes.Ble, nextArgBranch);
    469475              il.Emit(System.Reflection.Emit.OpCodes.Br, resultBranch);
     
    473479            }
    474480            il.MarkLabel(resultBranch);
    475             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     481            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    476482            il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    477483            il.Emit(System.Reflection.Emit.OpCodes.Brtrue, trueBranch);
     
    486492        case OpCodes.NOT: {
    487493            CompileInstructions(il, state, ds);
    488             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     494            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    489495            il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    490496            il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
     
    498504        case OpCodes.XOR: {
    499505            CompileInstructions(il, state, ds);
    500             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0);
     506            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0);
    501507            il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0
    502508
    503509            for (int i = 1; i < nArgs; i++) {
    504510              CompileInstructions(il, state, ds);
    505               il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0);
     511              il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0);
    506512              il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0
    507513              il.Emit(System.Reflection.Emit.OpCodes.Xor);
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r16360 r16676  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    2827using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2928using HeuristicLab.Parameters;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HEAL.Attic;
    3130
    3231namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    33   [StorableClass]
     32  [StorableType("FB94F333-B32A-44FB-A561-CBDE76693D20")]
    3433  [Item("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.")]
    3534  public class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem,
     
    7069
    7170    [StorableConstructor]
    72     protected SymbolicDataAnalysisExpressionTreeInterpreter(bool deserializing) : base(deserializing) { }
     71    protected SymbolicDataAnalysisExpressionTreeInterpreter(StorableConstructorFlag _) : base(_) { }
    7372
    7473    protected SymbolicDataAnalysisExpressionTreeInterpreter(SymbolicDataAnalysisExpressionTreeInterpreter original,
     
    206205            return Math.Abs(Evaluate(dataset, ref row, state));
    207206          }
     207        case OpCodes.Tanh: {
     208            return Math.Tanh(Evaluate(dataset, ref row, state));
     209          }
    208210        case OpCodes.Cos: {
    209211            return Math.Cos(Evaluate(dataset, ref row, state));
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r16360 r16676  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2929using HeuristicLab.Parameters;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HEAL.Attic;
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    33   [StorableClass]
     33  [StorableType("EF325166-E03A-44C4-83CE-7F07B836285E")]
    3434  [Item("SymbolicDataAnalysisExpressionTreeLinearInterpreter", "Fast linear (non-recursive) interpreter for symbolic expression trees. Does not support ADFs.")]
    3535  public sealed class SymbolicDataAnalysisExpressionTreeLinearInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
     
    7070
    7171    [StorableConstructor]
    72     private SymbolicDataAnalysisExpressionTreeLinearInterpreter(bool deserializing)
    73       : base(deserializing) {
     72    private SymbolicDataAnalysisExpressionTreeLinearInterpreter(StorableConstructorFlag _) : base(_) {
    7473      interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter();
    7574    }
     
    227226        } else if (instr.opCode == OpCodes.Absolute) {
    228227          instr.value = Math.Abs(code[instr.childIndex].value);
     228        } else if (instr.opCode == OpCodes.Tanh) {
     229          instr.value = Math.Tanh(code[instr.childIndex].value);
    229230        } else if (instr.opCode == OpCodes.Cos) {
    230231          instr.value = Math.Cos(code[instr.childIndex].value);
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs

    r16379 r16676  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2929using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3030using HeuristicLab.Parameters;
    31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HEAL.Attic;
    3232
    3333namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    34   [StorableClass]
     34  [StorableType("91723319-8F15-4D33-B277-40AC7C7CF9AE")]
    3535  [Item("SymbolicDataAnalysisExpressionTreeNativeInterpreter", "An interpreter that wraps a native dll")]
    3636  public class SymbolicDataAnalysisExpressionTreeNativeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
     
    5757
    5858    [StorableConstructor]
    59     protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(bool deserializing) : base(deserializing) { }
     59    protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(StorableConstructorFlag _) : base(_) { }
    6060
    6161    protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(SymbolicDataAnalysisExpressionTreeNativeInterpreter original, Cloner cloner) : base(original, cloner) {
Note: See TracChangeset for help on using the changeset viewer.