Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13030


Ignore:
Timestamp:
10/19/15 13:54:15 (9 years ago)
Author:
gkronber
Message:

#2490: fixed problem with thread-safety in RegressionTreeModel using a different (local) caching tactic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs

    r12868 r13030  
    2323using System;
    2424using System.Collections.Generic;
     25using System.Collections.ObjectModel;
    2526using System.Globalization;
    2627using System.Linq;
     
    5253      public int RightIdx { get; private set; }
    5354
    54       internal IList<double> Data { get; set; } // only necessary to improve efficiency of evaluation
    55 
    5655      // necessary because the default implementation of GetHashCode for structs in .NET would only return the hashcode of val here
    5756      public override int GetHashCode() {
     
    8281    [Storable]
    8382    // to prevent storing the references to data caches in nodes
    84     // seemingly it is bad (performance-wise) to persist tuples (tuples are used as keys in a dictionary) TODO
     83    // TODO seemingly it is bad (performance-wise) to persist tuples (tuples are used as keys in a dictionary)
    8584    private Tuple<string, double, int, int>[] SerializedTree {
    8685      get { return tree.Select(t => Tuple.Create(t.VarName, t.Val, t.LeftIdx, t.RightIdx)).ToArray(); }
     
    104103    }
    105104
    106     private static double GetPredictionForRow(TreeNode[] t, int nodeIdx, int row) {
     105    private static double GetPredictionForRow(TreeNode[] t, ReadOnlyCollection<double>[] columnCache, int nodeIdx, int row) {
    107106      while (nodeIdx != -1) {
    108107        var node = t[nodeIdx];
     
    110109          return node.Val;
    111110
    112         if (node.Data[row] <= node.Val)
     111        if (columnCache[nodeIdx][row] <= node.Val)
    113112          nodeIdx = node.LeftIdx;
    114113        else
     
    124123    public IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) {
    125124      // lookup columns for variableNames in one pass over the tree to speed up evaluation later on
     125      ReadOnlyCollection<double>[] columnCache = new ReadOnlyCollection<double>[tree.Length];
     126
    126127      for (int i = 0; i < tree.Length; i++) {
    127128        if (tree[i].VarName != TreeNode.NO_VARIABLE) {
    128           tree[i].Data = ds.GetReadOnlyDoubleValues(tree[i].VarName);
     129          columnCache[i] = ds.GetReadOnlyDoubleValues(tree[i].VarName);
    129130        }
    130131      }
    131       return rows.Select(r => GetPredictionForRow(tree, 0, r));
     132      return rows.Select(r => GetPredictionForRow(tree, columnCache, 0, r));
    132133    }
    133134
Note: See TracChangeset for help on using the changeset viewer.