- Timestamp:
- 10/07/16 11:00:55 (8 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14236,14314-14315,14322
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Algorithms.DataAnalysis merged: 14236,14314-14315,14322
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r14308 r14327 36 36 public sealed class NearestNeighbourModel : ClassificationModel, INearestNeighbourModel { 37 37 38 private readonly object kdTreeLockObject = new object(); 38 39 private alglib.nearestneighbor.kdtree kdTree; 39 40 public alglib.nearestneighbor.kdtree KDTree { … … 47 48 } 48 49 } 50 49 51 50 52 public override IEnumerable<string> VariablesUsedForPrediction { … … 200 202 x[column] = inputData[row, column]; 201 203 } 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 204 int numNeighbours; 205 lock (kdTreeLockObject) { // gkronber: the following calls change the kdTree data structure 206 numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false); 207 alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists); 208 alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours); 209 } 205 210 206 211 double distanceWeightedValue = 0.0; 207 212 double distsSum = 0.0; 208 for (int i = 0; i < actNeighbours; i++) {213 for (int i = 0; i < numNeighbours; i++) { 209 214 distanceWeightedValue += neighbours[i, columns] / dists[i]; 210 215 distsSum += 1.0 / dists[i]; … … 233 238 x[column] = inputData[row, column]; 234 239 } 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 240 int numNeighbours; 241 lock (kdTreeLockObject) { 242 // gkronber: the following calls change the kdTree data structure 243 numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false); 244 alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists); 245 alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours); 246 } 239 247 Array.Clear(y, 0, y.Length); 240 for (int i = 0; i < actNeighbours; i++) {248 for (int i = 0; i < numNeighbours; i++) { 241 249 int classValue = (int)Math.Round(neighbours[i, columns]); 242 250 y[classValue]++;
Note: See TracChangeset
for help on using the changeset viewer.