Skip to content

Commit

Permalink
Merge pull request #26 from openforcefield/inverting-matri
Browse files Browse the repository at this point in the history
flipping sign of matrix to match expected
  • Loading branch information
hannahbrucemacdonald authored Oct 30, 2020
2 parents 18e28c4 + 3da3270 commit 13129d8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
6 changes: 3 additions & 3 deletions arsenic/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ def form_edge_matrix(g, label, step=None, action=None, node_label=None):
for a, b in g.edges:
i = node_name_to_index[a]
j = node_name_to_index[b]
matrix[i, j] = g.edges[a, b][label]
matrix[j, i] = g.edges[a, b][label]
if action == 'symmetrize':
matrix[j, i] = matrix[i, j]
matrix[i, j] = matrix[j, i]
elif action == 'antisymmetrize':
matrix[j, i] = -matrix[i, j]
matrix[i, j] = -matrix[j, i]
elif action is None:
pass
else:
Expand Down
32 changes: 28 additions & 4 deletions arsenic/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_mle_easy(input_absolutes=[-14., -13., -9.]):
edges = [(0, 1), (0, 2), (2, 1)]
for a, b in edges:
noise = np.random.uniform(low=-1., high=1.)
diff = input_absolutes[a] - input_absolutes[b] + noise
diff = input_absolutes[b] - input_absolutes[a] + noise
g.add_edge(a, b, f_ij=diff, f_dij=0.5+np.abs(noise))

output_absolutes, C = stats.mle(g, factor='f_ij', node_factor='f_i')
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_mle_hard(input_absolutes=[-14., -13., -9.]):
edges = [(0, 1), (0, 2), (2, 1)]
for a, b in edges:
noise = np.random.uniform(low=-1., high=1.)
diff = input_absolutes[a] - input_absolutes[b] + noise
diff = input_absolutes[b] - input_absolutes[a] + noise
g.add_edge(a, b, f_ij=diff, f_dij=0.5+np.abs(noise))

output_absolutes, C = stats.mle(g, factor='f_ij', node_factor='f_i')
Expand All @@ -74,8 +74,8 @@ def test_mle_relative(input_absolutes=[-14., -13., -9.]):
# Don't assign any absolute values
edges = [(0, 1), (0, 2), (2, 1)]
for a, b in edges:
noise = np.random.uniform(low=-1., high=1.)
diff = input_absolutes[a] - input_absolutes[b] + noise
noise = np.random.uniform(low=-0.5, high=0.5)
diff = input_absolutes[b] - input_absolutes[a] + noise
g.add_edge(a, b, f_ij=diff, f_dij=0.5+np.abs(noise))

output_absolutes, C = stats.mle(g, factor='f_ij', node_factor='f_i')
Expand All @@ -89,3 +89,27 @@ def test_mle_relative(input_absolutes=[-14., -13., -9.]):
assert np.abs(true_diff - mle_diff) < 1., f"Relative\
difference from MLE: {mle_diff} is too far from the\
input difference, {true_diff}"


def test_correlation_positive():
""" Test that the absolute DG plots have the correct signs, and statistics within reasonable agreement to the example data in `arsenic/data/example.csv`
"""
from arsenic import plotting, stats, wrangle
import os
print(os.system('pwd'))
import numpy as np
fe = wrangle.FEMap('arsenic/data/example.csv')

x_data = np.asarray([node[1]['exp_DG'] for node in fe.graph.nodes(data=True)])
y_data = np.asarray([node[1]['calc_DG'] for node in fe.graph.nodes(data=True)])
xerr = np.asarray([node[1]['exp_dDG'] for node in fe.graph.nodes(data=True)])
yerr = np.asarray([node[1]['calc_dDG'] for node in fe.graph.nodes(data=True)])

s = stats.bootstrap_statistic(x_data, y_data, xerr, yerr, statistic='rho')
assert 0 < s['mle'] < 1, 'Correlation must be positive for this data'

for stat in ['R2','rho']:
s = stats.bootstrap_statistic(x_data, y_data, xerr, yerr, statistic=stat)
# all of the statistics for this example is between 0.61 and 0.84
assert 0.5 < s['mle'] < 0.9, f"Correlation must be positive for this data. {stat} is {s['mle']}"
9 changes: 7 additions & 2 deletions devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ dependencies:
- pytest-cov
- codecov
- networkx
- numpy
- matplotlib
- seaborn
- plotly
- scikit-learn

# Pip-only installs
#- pip:
# - codecov
#- pip:
# - codecov

2 changes: 1 addition & 1 deletion devtools/travis-ci/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else
MINICONDA=Miniconda3-latest-Linux-x86_64.sh
fi
MINICONDA_HOME=$HOME/miniconda
MINICONDA_MD5=$(curl -s https://repo.continuum.io/miniconda/ | grep -A3 $MINICONDA | sed -n '4p' | sed -n 's/ *<td>\(.*\)<\/td> */\1/p')
MINICONDA_MD5=$(wget -qO- https://repo.anaconda.com/miniconda/ | grep -A3 $MINICONDA | sed -n '4p' | sed -n 's/ *<td>\(.*\)<\/td> */\1/p')
wget -q https://repo.continuum.io/miniconda/$MINICONDA
if [[ $MINICONDA_MD5 != $(md5sum $MINICONDA | cut -d ' ' -f 1) ]]; then
echo "Miniconda MD5 mismatch"
Expand Down

0 comments on commit 13129d8

Please sign in to comment.