Skip to content

Commit

Permalink
Cosmit
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelVaroquaux committed Feb 19, 2012
1 parent a2108ea commit a734166
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions sklearn/cluster/hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = []
Expand All @@ -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)
Expand Down

0 comments on commit a734166

Please sign in to comment.