Skip to content

Commit

Permalink
Merge pull request #2 from vmarkovtsev/patch-1
Browse files Browse the repository at this point in the history
Simplify the chain comparisons
  • Loading branch information
obachem authored Jan 27, 2017
2 parents 6cf35aa + cb4ecb1 commit db085da
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions kmc2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,10 @@ def kmc2(X, k, chain_length=200, afkmc2=True, random_state=None, weights=None):
# Markov chain
for j in range(q_cand.shape[0]):
cand_prob = p_cand[j]/q_cand[j]
if j == 0 or curr_prob == 0.0:
# Init new chain
if j == 0 or curr_prob == 0.0 or cand_prob/curr_prob > rand_a[j]:
# Init new chain Metropolis-Hastings step
curr_ind = j
curr_prob = cand_prob
else:
# Metropolis-Hastings step
if cand_prob/curr_prob > rand_a[j]:
curr_ind = j
curr_prob = cand_prob
rel_row = X[cand_ind[curr_ind], :]
centers[i+1, :] = rel_row.todense().flatten() if sparse else rel_row
return centers

0 comments on commit db085da

Please sign in to comment.