Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/07/19 12:29:27 (6 years ago)
Author:
gkronber
Message:

#2866: merged r16364:16653 from trunk to branch to prepare for trunk reintegration (resolving conflicts in the project file)

Location:
branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/InterpreterState.cs

    r15583 r16654  
    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/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r16375 r16654  
    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/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs

    r16360 r16654  
    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 {
     
    9898
    9999    [StorableConstructor]
    100     private SymbolicDataAnalysisExpressionCompiledTreeInterpreter(bool deserializing)
    101       : base(deserializing) {
     100    private SymbolicDataAnalysisExpressionCompiledTreeInterpreter(StorableConstructorFlag _) : base(_) {
    102101    }
    103102
  • branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs

    r16531 r16654  
    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";
     
    3737    }
    3838
    39 
    4039    [StorableConstructor]
    41     protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(bool deserializing) : base(deserializing) { }
     40    protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(StorableConstructorFlag _) : base(_) { }
    4241    protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(SymbolicDataAnalysisExpressionTreeBatchInterpreter original, Cloner cloner) : base(original, cloner) {
    4342    }
     
    178177    }
    179178
     179    private readonly object syncRoot = new object();
     180
    180181    [ThreadStatic]
    181182    private Dictionary<string, double[]> cachedData;
    182183
     184    [ThreadStatic]
     185    private IDataset dataset;
     186
    183187    private void InitCache(IDataset dataset) {
     188      this.dataset = dataset;
    184189      cachedData = new Dictionary<string, double[]>();
    185190      foreach (var v in dataset.DoubleVariables) {
     
    190195    public void InitializeState() {
    191196      cachedData = null;
     197      dataset = null;
    192198      EvaluatedSolutions = 0;
    193199    }
    194200
    195201    private double[] GetValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) {
     202      if (cachedData == null || this.dataset != dataset) {
     203        InitCache(dataset);
     204      }
     205
    196206      var code = Compile(tree, dataset, OpCodes.MapSymbolToOpCode);
    197207      var remainingRows = rows.Length % BATCHSIZE;
    198208      var roundedTotal = rows.Length - remainingRows;
    199209
    200       // TODO: evaluated solutions are not counted
    201 
    202210      var result = new double[rows.Length];
    203211
     
    212220      }
    213221
     222      // when evaluation took place without any error, we can increment the counter
     223      lock (syncRoot) {
     224        EvaluatedSolutions++;
     225      }
     226
    214227      return result;
    215228    }
    216229
    217230    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) {
    218       if (cachedData == null) {
    219         InitCache(dataset);
    220       }
    221231      return GetValues(tree, dataset, rows);
    222232    }
  • branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r16360 r16654  
    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 {
     
    104104
    105105    [StorableConstructor]
    106     private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(bool deserializing) : base(deserializing) { }
     106    private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(StorableConstructorFlag _) : base(_) { }
    107107
    108108    private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(SymbolicDataAnalysisExpressionTreeILEmittingInterpreter original, Cloner cloner) : base(original, cloner) { }
     
    425425            Label c1 = il.DefineLabel();
    426426            CompileInstructions(il, state, ds);
    427             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     427            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    428428            il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    429429            il.Emit(System.Reflection.Emit.OpCodes.Brfalse, c1);
     
    440440            CompileInstructions(il, state, ds);
    441441            for (int i = 1; i < nArgs; i++) {
    442               il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     442              il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    443443              il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    444444              il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch);
    445445              CompileInstructions(il, state, ds);
    446446            }
    447             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     447            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    448448            il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    449449            il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch);
     
    465465              // complex definition because of special properties of NaN 
    466466              il.Emit(System.Reflection.Emit.OpCodes.Dup);
    467               il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // <= 0       
     467              il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // <= 0       
    468468              il.Emit(System.Reflection.Emit.OpCodes.Ble, nextArgBranch);
    469469              il.Emit(System.Reflection.Emit.OpCodes.Br, resultBranch);
     
    473473            }
    474474            il.MarkLabel(resultBranch);
    475             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     475            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    476476            il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    477477            il.Emit(System.Reflection.Emit.OpCodes.Brtrue, trueBranch);
     
    486486        case OpCodes.NOT: {
    487487            CompileInstructions(il, state, ds);
    488             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
     488            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0
    489489            il.Emit(System.Reflection.Emit.OpCodes.Cgt);
    490490            il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
     
    498498        case OpCodes.XOR: {
    499499            CompileInstructions(il, state, ds);
    500             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0);
     500            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0);
    501501            il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0
    502502
    503503            for (int i = 1; i < nArgs; i++) {
    504504              CompileInstructions(il, state, ds);
    505               il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0);
     505              il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0);
    506506              il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0
    507507              il.Emit(System.Reflection.Emit.OpCodes.Xor);
  • branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r16375 r16654  
    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,
  • branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r16375 r16654  
    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    }
  • branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs

    r16277 r16654  
    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) { }
    60 
     59    protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(StorableConstructorFlag _) : base(_) { }
    6160
    6261    protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(SymbolicDataAnalysisExpressionTreeNativeInterpreter original, Cloner cloner) : base(original, cloner) {
     
    9998    private static Dictionary<string, GCHandle> cachedData;
    10099
     100    [ThreadStatic]
     101    private IDataset dataset;
     102
    101103    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
    102104      if (!rows.Any()) return Enumerable.Empty<double>();
    103105
    104       lock (syncRoot) {
    105         EvaluatedSolutions++; // increment the evaluated solutions counter
    106       }
    107 
    108       if (cachedData == null) {
     106      if (cachedData == null || this.dataset != dataset) {
    109107        InitCache(dataset);
    110108      }
     
    116114
    117115      NativeWrapper.GetValuesVectorized(code, code.Length, rowsArray, rowsArray.Length, result);
     116
     117      // when evaluation took place without any error, we can increment the counter
     118      lock (syncRoot) {
     119        EvaluatedSolutions++;
     120      }
     121
    118122      return result;
    119123    }
    120124
    121125    private void InitCache(IDataset dataset) {
     126      this.dataset = dataset;
     127
     128      // free handles to old data
     129      if (cachedData != null) {
     130        foreach (var gch in cachedData.Values) {
     131          gch.Free();
     132        }
     133        cachedData = null;
     134      }
     135
     136      // cache new data
    122137      cachedData = new Dictionary<string, GCHandle>();
    123138      foreach (var v in dataset.DoubleVariables) {
     
    135150        cachedData = null;
    136151      }
     152      dataset = null;
    137153      EvaluatedSolutions = 0;
    138154    }
Note: See TracChangeset for help on using the changeset viewer.