Skip to content

Commit

Permalink
Fix bug in MIMIC algorithm
Browse files Browse the repository at this point in the history
Fix infinite loop issue identified in #17
  • Loading branch information
gkhayes committed Feb 14, 2019
1 parent 7971ab3 commit fc7c8cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions mlrose/opt_probs.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def eval_node_probs(self):

# Convert minimum spanning tree to depth first tree with node 0 as root
dft = depth_first_tree(csr_matrix(mst.toarray()), 0, directed=False)
dft = dft.toarray()
dft = np.round(dft.toarray(), 10)

# Determine parent of each node
parent = np.argmin(dft[:, 1:], axis=0)
Expand Down Expand Up @@ -347,8 +347,14 @@ def find_sample_order(self):
while len(sample_order) < self.length:
inds = []

for i in last:
inds += list(np.where(parent == i)[0] + 1)
# If last nodes list is empty, select random node than has not
# previously been selected
if len(last) == 0:
inds = [np.random.choice(list(set(np.arange(self.length)) -
set(sample_order)))]
else:
for i in last:
inds += list(np.where(parent == i)[0] + 1)

sample_order += last
last = inds
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def readme():


setup(name='mlrose',
version='1.0.0',
version='1.0.1',
description="MLROSe: Machine Learning, Randomized Optimization and"
+ " Search",
long_description=readme(),
Expand Down

0 comments on commit fc7c8cd

Please sign in to comment.