Changeset 16378


Ignore:
Timestamp:
12/13/18 14:39:56 (5 months ago)
Author:
bburlacu
Message:

#2958: Batch and Native interpreter: keep a cached reference to the dataset so we can detect when it changes.

Location:
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs

    r16360 r16378  
    3636      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
    3737    }
    38 
    3938
    4039    [StorableConstructor]
     
    175174    }
    176175
     176    private readonly object syncRoot = new object();
     177
    177178    [ThreadStatic]
    178179    private Dictionary<string, double[]> cachedData;
    179180
     181    [ThreadStatic]
     182    private IDataset dataset;
     183
    180184    private void InitCache(IDataset dataset) {
     185      this.dataset = dataset;
    181186      cachedData = new Dictionary<string, double[]>();
    182187      foreach (var v in dataset.DoubleVariables) {
     
    187192    public void InitializeState() {
    188193      cachedData = null;
     194      dataset = null;
    189195      EvaluatedSolutions = 0;
    190196    }
    191197
    192198    private double[] GetValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) {
     199      if (cachedData == null || this.dataset != dataset) {
     200        InitCache(dataset);
     201      }
     202
    193203      var code = Compile(tree, dataset, OpCodes.MapSymbolToOpCode);
    194204      var remainingRows = rows.Length % BATCHSIZE;
    195205      var roundedTotal = rows.Length - remainingRows;
    196206
    197       // TODO: evaluated solutions are not counted
    198 
    199207      var result = new double[rows.Length];
    200208
     
    209217      }
    210218
     219      // when evaluation took place without any error, we can increment the counter
     220      lock (syncRoot) {
     221        EvaluatedSolutions++;
     222      }
     223
    211224      return result;
    212225    }
    213226
    214227    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) {
    215       if (cachedData == null) {
    216         InitCache(dataset);
    217       }
    218228      return GetValues(tree, dataset, rows);
    219229    }
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs

    r16277 r16378  
    5959    protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(bool deserializing) : base(deserializing) { }
    6060
    61 
    6261    protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(SymbolicDataAnalysisExpressionTreeNativeInterpreter original, Cloner cloner) : base(original, cloner) {
    6362    }
     
    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;
    122127      cachedData = new Dictionary<string, GCHandle>();
    123128      foreach (var v in dataset.DoubleVariables) {
     
    135140        cachedData = null;
    136141      }
     142      dataset = null;
    137143      EvaluatedSolutions = 0;
    138144    }
Note: See TracChangeset for help on using the changeset viewer.