You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,I have found a problem in building the tree when dealing with some datasets, but I don't know why. When I run the initial code as following,
# Construct forest
forest = []
while len(forest) < num_trees:
# Select random subsets of points uniformly
ixs = np.random.choice(n, size=sample_size_range,
replace=False)
# Add sampled trees to forest
trees = [rrcf.RCTree(X[ix], index_labels=ix)
for ix in ixs]
forest.extend(trees)
the error happens ,and it display like this .
ValueError Traceback (most recent call last)
in
116 replace=False)
117 # Add sampled trees to forest
--> 118 trees = [rrcf.RCTree(X[ix], index_labels=ix)
119 for ix in ixs]
120 forest.extend(trees)
in (.0)
116 replace=False)
117 # Add sampled trees to forest
--> 118 trees = [rrcf.RCTree(X[ix], index_labels=ix)
119 for ix in ixs]
120 forest.extend(trees)
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in init(self, X, index_labels, precision, random_state)
104 # Create RRC Tree
105 S = np.ones(n, dtype=np.bool)
--> 106 self._mktree(X, S, N, I, parent=self)
107 # Remove parent of root
108 self.root.u = None
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
196 if S2.sum() > 1:
197 # Recursively construct tree on S2
--> 198 self._mktree(X, S2, N, I, parent=branch, side='r', depth=depth)
199 # Otherwise...
200 else:
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
174 if S1.sum() > 1:
175 # Recursively construct tree on S1
--> 176 self._mktree(X, S1, N, I, parent=branch, side='l', depth=depth)
177 # Otherwise...
178 else:
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
174 if S1.sum() > 1:
175 # Recursively construct tree on S1
--> 176 self._mktree(X, S1, N, I, parent=branch, side='l', depth=depth)
177 # Otherwise...
178 else:
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
174 if S1.sum() > 1:
175 # Recursively construct tree on S1
--> 176 self._mktree(X, S1, N, I, parent=branch, side='l', depth=depth)
177 # Otherwise...
178 else:
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
200 else:
201 # Create a leaf node from isolated point
--> 202 i = np.asscalar(np.flatnonzero(S2))
203 leaf = Leaf(i=i, d=depth, u=branch, x=X[i, :], n=N[i])
204 # Link leaf node to parent
<array_function internals> in asscalar(*args, **kwargs)
Hello, although the issue is already dated and the problem might have been solved by the author, I'd like to point out a possible hint for future users. Most probably the cause is that either S1 or S2 in the _cut() method is computed to be a False-only mask; in other words, either the left or right split resulting from the operation (X[:, q] <= p) is empty.
are both cast to the same type / dtype. I had the case where e.g. the samples used to initialize instances of RCTree had dtype np.float32 whereas p was of dtype np.float64. Similar discrepancies have been reported w.r.t. numpy broadcasting, refer to e.g. numpy issue #10982.
Hi,I have found a problem in building the tree when dealing with some datasets, but I don't know why. When I run the initial code as following,
# Construct forest
forest = []
while len(forest) < num_trees:
# Select random subsets of points uniformly
ixs = np.random.choice(n, size=sample_size_range,
replace=False)
# Add sampled trees to forest
trees = [rrcf.RCTree(X[ix], index_labels=ix)
for ix in ixs]
forest.extend(trees)
the error happens ,and it display like this .
ValueError Traceback (most recent call last)
in
116 replace=False)
117 # Add sampled trees to forest
--> 118 trees = [rrcf.RCTree(X[ix], index_labels=ix)
119 for ix in ixs]
120 forest.extend(trees)
in (.0)
116 replace=False)
117 # Add sampled trees to forest
--> 118 trees = [rrcf.RCTree(X[ix], index_labels=ix)
119 for ix in ixs]
120 forest.extend(trees)
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in init(self, X, index_labels, precision, random_state)
104 # Create RRC Tree
105 S = np.ones(n, dtype=np.bool)
--> 106 self._mktree(X, S, N, I, parent=self)
107 # Remove parent of root
108 self.root.u = None
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
196 if S2.sum() > 1:
197 # Recursively construct tree on S2
--> 198 self._mktree(X, S2, N, I, parent=branch, side='r', depth=depth)
199 # Otherwise...
200 else:
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
174 if S1.sum() > 1:
175 # Recursively construct tree on S1
--> 176 self._mktree(X, S1, N, I, parent=branch, side='l', depth=depth)
177 # Otherwise...
178 else:
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
174 if S1.sum() > 1:
175 # Recursively construct tree on S1
--> 176 self._mktree(X, S1, N, I, parent=branch, side='l', depth=depth)
177 # Otherwise...
178 else:
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
174 if S1.sum() > 1:
175 # Recursively construct tree on S1
--> 176 self._mktree(X, S1, N, I, parent=branch, side='l', depth=depth)
177 # Otherwise...
178 else:
~/anaconda3/lib/python3.8/site-packages/rrcf/rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
200 else:
201 # Create a leaf node from isolated point
--> 202 i = np.asscalar(np.flatnonzero(S2))
203 leaf = Leaf(i=i, d=depth, u=branch, x=X[i, :], n=N[i])
204 # Link leaf node to parent
<array_function internals> in asscalar(*args, **kwargs)
~/anaconda3/lib/python3.8/site-packages/numpy/lib/type_check.py in asscalar(a)
579 24
580 """
--> 581 return a.item()
582
583 #-----------------------------------------------------------------------------
ValueError: can only convert an array of size 1 to a Python scalar
However, when I try to run the X[ix] and build again ,it run.
The text was updated successfully, but these errors were encountered: