Skip to content

Commit 95502d9

Browse files
committed
Fix for issue #16
lambda got updated to lambda_val while fixing issues with numpy's structured array access; update this accordingly.
1 parent 96749f6 commit 95502d9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

hdbscan/plots.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ def get_plot_data(self, leaf_separation=1, log_size=False):
111111
cluster_y_coords = {root: 0.0}
112112

113113
for cluster in range(last_leaf, root - 1, -1):
114-
split = self._raw_tree[['child', 'lambda']]
114+
split = self._raw_tree[['child', 'lambda_val']]
115115
split = split[(self._raw_tree['parent'] == cluster) &
116116
(self._raw_tree['child_size'] > 1)]
117117
if len(split['child']) > 1:
118118
left_child, right_child = split['child']
119119
cluster_x_coords[cluster] = np.mean([cluster_x_coords[left_child],
120120
cluster_x_coords[right_child]])
121-
cluster_y_coords[left_child] = split['lambda'][0]
122-
cluster_y_coords[right_child] = split['lambda'][1]
121+
cluster_y_coords[left_child] = split['lambda_val'][0]
122+
cluster_y_coords[right_child] = split['lambda_val'][1]
123123

124124
# We use bars to plot the 'icicles', so we need to generate centers, tops,
125125
# bottoms and widths for each rectangle. We can go through each cluster
@@ -150,20 +150,20 @@ def get_plot_data(self, leaf_separation=1, log_size=False):
150150
cluster_bounds[c][CB_LEFT] = cluster_x_coords[c] * scaling - (current_size / 2.0)
151151
cluster_bounds[c][CB_RIGHT] = cluster_x_coords[c] * scaling + (current_size / 2.0)
152152
cluster_bounds[c][CB_BOTTOM] = cluster_y_coords[c]
153-
cluster_bounds[c][CB_TOP] = np.max(c_children['lambda'])
153+
cluster_bounds[c][CB_TOP] = np.max(c_children['lambda_val'])
154154

155-
for i in np.argsort(c_children['lambda']):
155+
for i in np.argsort(c_children['lambda_val']):
156156
row = c_children[i]
157-
if row['lambda'] != current_lambda:
157+
if row['lambda_val'] != current_lambda:
158158
bar_centers.append(cluster_x_coords[c] * scaling)
159-
bar_tops.append(row['lambda'] - current_lambda)
159+
bar_tops.append(row['lambda_val'] - current_lambda)
160160
bar_bottoms.append(current_lambda)
161161
bar_widths.append(current_size)
162162
if log_size:
163163
current_size = np.log(np.exp(current_size) - row['child_size'])
164164
else:
165165
current_size -= row['child_size']
166-
current_lambda = row['lambda']
166+
current_lambda = row['lambda_val']
167167

168168
# Finally we need the horizontal lines that occur at cluster splits.
169169
line_xs = []
@@ -349,15 +349,15 @@ def to_pandas(self):
349349
"""Return a pandas dataframe representation of the condensed tree.
350350
351351
Each row of the dataframe corresponds to an edge in the tree.
352-
The columns of the dataframe are `parent`, `child`, `lambda`
352+
The columns of the dataframe are `parent`, `child`, `lambda_val`
353353
and `child_size`.
354354
355355
The `parent` and `child` are the ids of the
356356
parent and child nodes in the tree. Node ids less than the number
357357
of points in the original dataset represent individual points, while
358358
ids greater than the number of points are clusters.
359359
360-
The `lambda` value is the value (1/distance) at which the `child`
360+
The `lambda_val` value is the value (1/distance) at which the `child`
361361
node leaves the cluster.
362362
363363
The `child_size` is the number of points in the `child` node.
@@ -389,7 +389,7 @@ def to_networkx(self):
389389

390390
result = DiGraph()
391391
for row in self._raw_tree:
392-
result.add_edge(row['parent'], row['child'], weight=row['lambda'])
392+
result.add_edge(row['parent'], row['child'], weight=row['lambda_val'])
393393

394394
set_node_attributes(result, 'size', dict(self._raw_tree[['child', 'child_size']]))
395395

0 commit comments

Comments
 (0)