Skip to content

Commit

Permalink
remove spurious test case and typo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoslicki committed Feb 23, 2018
1 parent 0500903 commit 94df739
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions code/reasoningtool/MarkovLearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
config = DefaultConfigurable(**DEFAULT_CONFIGURABLE)

# state space is a tuple (relationship_type, node_label), first order markov chain


def initialize_Markov_chain(connection, config):
"""
This initializes an empty Markov chain and returns the transition matrix and state space
Expand Down Expand Up @@ -62,6 +64,8 @@ def initialize_Markov_chain(connection, config):
#state_space, quad_to_matrix_index = initialize_Markov_chain(connection, config)

# Run this on each training example, then normalize


def train(state_space, quad_to_matrix_index, obs_dict, type='ML'):
"""
This function will train a Markov chain given a set of observations
Expand Down Expand Up @@ -103,6 +107,7 @@ def train(state_space, quad_to_matrix_index, obs_dict, type='ML'):

#trained = train(state_space, quad_to_matrix_index, paths_dict, type='L')


def path_probability(trans_mat, quad_to_matrix_index, path):
"""
Computes the probability of a given path
Expand All @@ -125,6 +130,7 @@ def path_probability(trans_mat, quad_to_matrix_index, path):

#path_probability(trained, quad_to_matrix_index, paths_dict[omim][1][0])


def trained_MC():
"""
Trains the Markov chain using known information
Expand All @@ -148,6 +154,7 @@ def trained_MC():
trained = train(state_space, quad_to_matrix_index, paths_dict, type='L')
return trained, quad_to_matrix_index


def test():
paths_dict = dict()
omim = "test"
Expand All @@ -174,7 +181,10 @@ def test():
trained = train(state_space, quad_to_matrix_index, paths_dict, type='L')
# This can get messed up if you change the priors
#print(path_probability(trained, quad_to_matrix_index, paths_dict[omim][1][0]))
assert np.abs(path_probability(trained, quad_to_matrix_index, paths_dict[omim][1][0]) - 0.851746) < .01

# Something is odd with this assertion, why should it be < .01?
#assert np.abs(path_probability(trained, quad_to_matrix_index, paths_dict[omim][1][0]) - 0.851746) < .01

trained = train(state_space, quad_to_matrix_index, paths_dict, type='ML')
# This should always == 1
assert path_probability(trained, quad_to_matrix_index, paths_dict[omim][1][0]) == 1.0
assert path_probability(trained, quad_to_matrix_index, paths_dict[omim][1][0]) == 1.0
2 changes: 1 addition & 1 deletion code/reasoningtool/Q1Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def get_results_object_model(doid, paths_dict, omim_to_genetic_cond, q1_doid_to_

omim_dict['path'] = path_list
else:
print(to_print)
#print(to_print)
if probs:
if omim in probs:
omim_dict['conf'] = probs[omim]
Expand Down

0 comments on commit 94df739

Please sign in to comment.