Skip to content

Commit

Permalink
Round scipy.stats output when writing to log file
Browse files Browse the repository at this point in the history
These numbers are not fully deterministic, so need to be chopped for
 stability.
  • Loading branch information
biologyguy committed Jan 13, 2018
1 parent ab65714 commit 78a9bda
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions rdmcl/rdmcl.py
Expand Up @@ -553,12 +553,14 @@ def create_rbh_cliques(self, log_file=None):
total_kde = scipy.stats.gaussian_kde(outer_scores.raw_score, bw_method='silverman')
log_file.write("""\
\t\t\tOuter KDE: {'shape': %s, 'covariance': %s, 'inv_cov': %s, '_norm_factor': %s}
""" % (total_kde.dataset.shape, total_kde.covariance[0][0], total_kde.inv_cov[0][0], total_kde._norm_factor))
""" % (total_kde.dataset.shape, round(total_kde.covariance[0][0], 12),
round(total_kde.inv_cov[0][0], 12), round(total_kde._norm_factor, 12)))

clique_kde = scipy.stats.gaussian_kde(clique_scores.raw_score, bw_method='silverman')
log_file.write("""\
\t\t\tClique KDE: {'shape': %s, 'covariance': %s, 'inv_cov': %s, '_norm_factor': %s}
""" % (clique_kde.dataset.shape, clique_kde.covariance[0][0], clique_kde.inv_cov[0][0], clique_kde._norm_factor))
""" % (clique_kde.dataset.shape, round(clique_kde.covariance[0][0], 12),
round(clique_kde.inv_cov[0][0], 12), round(clique_kde._norm_factor, 12)))

clique_resample = clique_kde.resample(10000)[0] # ToDo: figure out how to control this with r_seed!
clique95 = [np.percentile(clique_resample, 2.5), np.percentile(clique_resample, 97.5)]
Expand Down
16 changes: 8 additions & 8 deletions rdmcl/tests/test_rdmcl.py
Expand Up @@ -477,10 +477,10 @@ def test_rbhc_fail_integration(hf):
assert cliques[0] == cluster
assert """Test for KDE separation:
\t\t\t['BOL-PanxαF', 'Lcr-PanxαI', 'Lcr-PanxαL', 'Mle-Panxα11', 'Mle-Panxα4']
\t\t\tOuter KDE: {'shape': (1, 5), 'covariance': 0.03207031769228259, 'inv_cov': 31.18148094431381,\
'_norm_factor': 2.2444584476034053}
\t\t\tClique KDE: {'shape': (1, 10), 'covariance': 0.0196599709780622, 'inv_cov': 50.86477498445248,\
'_norm_factor': 3.514644232193886}""" in log_file.read(), print(log_file.read())
\t\t\tOuter KDE: {'shape': (1, 5), 'covariance': 0.032070317692, 'inv_cov': 31.181480944314,\
'_norm_factor': 2.244458447603}
\t\t\tClique KDE: {'shape': (1, 10), 'covariance': 0.019659970978, 'inv_cov': 50.864774984452,\
'_norm_factor': 3.514644232194}""" in log_file.read(), print(log_file.read())
assert "FAIL" in log_file.read()


Expand All @@ -497,10 +497,10 @@ def test_rbhc_multi_clique_pass(hf):

assert """Test for KDE separation:
\t\t\t['BOL-PanxαF', 'Lcr-PanxαI', 'Mle-Panxα4']
\t\t\tOuter KDE: {'shape': (1, 9), 'covariance': 0.024741531460431374, 'inv_cov': 40.41786991234878,\
'_norm_factor': 3.5485075430233506}
\t\t\tClique KDE: {'shape': (1, 3), 'covariance': 9.93711384680704e-05, 'inv_cov': 10063.284122696416,\
'_norm_factor': 0.07496202701783479}
\t\t\tOuter KDE: {'shape': (1, 9), 'covariance': 0.02474153146, 'inv_cov': 40.417869912349,\
'_norm_factor': 3.548507543023}
\t\t\tClique KDE: {'shape': (1, 3), 'covariance': 9.9371138e-05, 'inv_cov': 10063.284122696416,\
'_norm_factor': 0.074962027018}
""" in log_file.read(), print(log_file.read())

assert """Cliques identified and spun off:
Expand Down

0 comments on commit 78a9bda

Please sign in to comment.