Skip to content

Commit

Permalink
fixed bug in the case of regression: it's all about the difference be…
Browse files Browse the repository at this point in the history
…tween `a[indices] += 1` and `np.add.at(a,indices,1)`

and the trick of using `np.bincount`, which is faster than `ufunc.at`.

See: ml31415/numpy-groupies#1 and numpy/numpy#5922
  • Loading branch information
Kevin Keraudren committed Feb 25, 2016
1 parent 462107b commit 21116f0
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 2 deletions.
Binary file added fern_AxisAligned_regression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fern_Conic_regression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fern_Linear_regression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fern_Parabola_regression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions randomferns.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ def fit( self, points, responses ):
self.tests = np.array( self.test_class.generate_all( points, self.depth ) )
if self.regression:
self.target_dim = responses.shape[1]
self.data = np.ones( (2**self.depth, self.target_dim), dtype='float64' )
self.data = np.zeros( (2**self.depth, self.target_dim), dtype='float64' )
bins = self.apply_tests(points)
bincount = np.bincount(bins, minlength=self.data.shape[0])
self.data[self.apply_tests(points)] += responses
for dim in range(self.target_dim):
self.data[:,dim] += np.bincount(bins, weights=responses[:,dim], minlength=self.data.shape[0])
self.data[bincount>0] /= bincount[bincount>0][...,np.newaxis]
else:
self.n_classes = responses.max() + 1
Expand Down
Binary file added randomferns_AxisAligned_regression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added randomferns_Conic_regression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added randomferns_Linear_regression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added randomferns_Parabola_regression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 21116f0

Please sign in to comment.