Skip to content

Commit

Permalink
Merge pull request #147 from kyleabeauchamp/minor
Browse files Browse the repository at this point in the history
Added W_nk property and updated a test for n_eff_samples
  • Loading branch information
kyleabeauchamp committed Jan 5, 2015
2 parents 22f2110 + 84c42f6 commit c6f3091
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions pymbar/mbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ def __init__(self, u_kn, N_k, maximum_iterations=10000, relative_tolerance=1.0e-
print "MBAR initialization complete."
return

@property
def W_nk(self):
"""Retrieve the weight matrix W_nk from the MBAR algorithm.
Necessary because they are stored internally as log weights.
Returns
-------
weights : np.ndarray, float, shape=(N, K)
NxK matrix of weights in the MBAR covariance and averaging formulas
"""
return np.exp(self.Log_W_nk)


#=========================================================================
def getWeights(self):
Expand All @@ -288,7 +302,7 @@ def getWeights(self):
"""

return np.exp(self.Log_W_nk)
return self.W_nk

#=========================================================================
def computeEffectiveSampleNumber(self, verbose = False):
Expand Down Expand Up @@ -340,7 +354,6 @@ def computeEffectiveSampleNumber(self, verbose = False):
for k in range(self.K):
w = np.exp(self.Log_W_nk[:,k])
N_eff[k] = 1/np.sum(w**2)

if verbose:
print "Effective number of sample in state %d is %10.3f" % (k,N_eff[k])
print "Efficiency for state %d is %d/%d = %10.4f" % (k,N_eff[k],len(w),N_eff[k]/len(w))
Expand Down
4 changes: 2 additions & 2 deletions pymbar/tests/test_mbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def test_mbar_computeEffectiveSampleNumber():
# one mathematical effective sample numbers should be between N_k and sum_k N_k
N_eff = mbar.computeEffectiveSampleNumber()
sumN = np.sum(N_k)
for k in range(len(N_eff)):
eq(np.bool(N_eff[k] > N_k[k] and N_eff[k] < sumN),True)
assert all(N_eff > N_k)
assert all(N_eff < sumN)

def test_mbar_computeOverlap():

Expand Down

0 comments on commit c6f3091

Please sign in to comment.