Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.