From a7341662a365a3a3ccd04e944f980bcb46d8fccc Mon Sep 17 00:00:00 2001 From: GaelVaroquaux Date: Sun, 19 Feb 2012 17:47:41 +0100 Subject: [PATCH] Cosmit --- sklearn/cluster/hierarchical.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sklearn/cluster/hierarchical.py b/sklearn/cluster/hierarchical.py index 8bcccd3acd293..9c15fa95615b9 100644 --- a/sklearn/cluster/hierarchical.py +++ b/sklearn/cluster/hierarchical.py @@ -114,11 +114,12 @@ def ward_tree(X, connectivity=None, n_components=None, copy=True): coord_col = np.array(coord_col, dtype=np.int) # build moments as a list - moments = [np.zeros(n_nodes), np.zeros((n_nodes, n_features))] - moments[0][:n_samples] = 1 - moments[1][:n_samples] = X + moments_1 = np.zeros(n_nodes) + moments_1[:n_samples] = 1 + moments_2 = np.zeros((n_nodes, n_features)) + moments_2[:n_samples] = X inertia = np.empty(len(coord_row), dtype=np.float) - _hierarchical.compute_ward_dist(moments[0], moments[1], + _hierarchical.compute_ward_dist(moments_1, moments_2, coord_row, coord_col, inertia) inertia = zip(inertia, coord_row, coord_col) heapify(inertia) @@ -143,8 +144,8 @@ def ward_tree(X, connectivity=None, n_components=None, copy=True): used_node[i] = used_node[j] = False # update the moments - moments[0][k] = moments[0][i] + moments[0][j] - moments[1][k] = moments[1][i] + moments[1][j] + moments_1[k] = moments_1[i] + moments_1[j] + moments_2[k] = moments_2[i] + moments_2[j] # update the structure matrix A and the inertia matrix coord_col = [] @@ -165,7 +166,7 @@ def ward_tree(X, connectivity=None, n_components=None, copy=True): coord_row.fill(k) ini = np.empty(len(coord_row), dtype=np.float) - _hierarchical.compute_ward_dist(moments[0], moments[1], + _hierarchical.compute_ward_dist(moments_1, moments_2, coord_row, coord_col, ini) for tupl in itertools.izip(ini, coord_row, coord_col): heappush(inertia, tupl)