Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/05/16 11:58:52 (8 years ago)
Author:
gkronber
Message:

#2653: added synchronization in NearestNeighbourModel and made some related changes to GradientBoostedTreesModelSurrogate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r14235 r14236  
    200200          x[column] = inputData[row, column];
    201201        }
    202         int actNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false);
    203         alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists);
    204         alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours); // gkronber: this call changes the kdTree data structure
     202        int numNeighbours;
     203        lock (kdTree) { // gkronber: the following calls change the kdTree data structure
     204          numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false);
     205          alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists);
     206          alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours);
     207        }
    205208
    206209        double distanceWeightedValue = 0.0;
    207210        double distsSum = 0.0;
    208         for (int i = 0; i < actNeighbours; i++) {
     211        for (int i = 0; i < numNeighbours; i++) {
    209212          distanceWeightedValue += neighbours[i, columns] / dists[i];
    210213          distsSum += 1.0 / dists[i];
     
    233236          x[column] = inputData[row, column];
    234237        }
    235         int actNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false);
    236         alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists);
    237         alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours);
    238 
     238        int numNeighbours;
     239        lock (kdTree) {
     240          // gkronber: the following calls change the kdTree data structure
     241          numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false);
     242          alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists);
     243          alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours);
     244        }
    239245        Array.Clear(y, 0, y.Length);
    240         for (int i = 0; i < actNeighbours; i++) {
     246        for (int i = 0; i < numNeighbours; i++) {
    241247          int classValue = (int)Math.Round(neighbours[i, columns]);
    242248          y[classValue]++;
Note: See TracChangeset for help on using the changeset viewer.