def test_mbar_computeMultipleExpectations(): """Can MBAR calculate E(u_kn)??""" for system_generator in system_generators: name, test = system_generator() x_n, u_kn, N_k_output, s_n = test.sample(N_k, mode='u_kn') eq(N_k, N_k_output) mbar = MBAR(u_kn, N_k) A = np.zeros([2, len(x_n)]) A[0, :] = x_n A[1, :] = x_n**2 state = 1 results = mbar.computeMultipleExpectations(A, u_kn[state, :], return_dict=True) mu_t, sigma_t = mbar.computeMultipleExpectations(A, u_kn[state, :], return_dict=False) mu = results['mu'] sigma = results['sigma'] eq(mu, mu_t) eq(sigma, sigma_t) mu0 = test.analytical_observable(observable='position')[state] mu1 = test.analytical_observable(observable='position^2')[state] z = (mu0 - mu[0]) / sigma[0] eq(z / z_scale_factor, 0 * z, decimal=0) z = (mu1 - mu[1]) / sigma[1] eq(z / z_scale_factor, 0 * z, decimal=0)
def test_mbar_computeMultipleExpectations(): """Can MBAR calculate E(u_kn)??""" for system_generator in system_generators: name, test = system_generator() x_n, u_kn, N_k_output, s_n = test.sample(N_k, mode='u_kn') eq(N_k, N_k_output) mbar = MBAR(u_kn, N_k) A = np.zeros([2,len(x_n)]) A[0,:] = x_n A[1,:] = x_n**2 state = 1 mu, sigma, covariances = mbar.computeMultipleExpectations(A,u_kn[state,:]) mu0 = test.analytical_observable(observable = 'position')[state] mu1 = test.analytical_observable(observable = 'position^2')[state] z = (mu0 - mu[0]) / sigma[0] eq(z / z_scale_factor, 0*z, decimal=0) z = (mu1 - mu[1]) / sigma[1] eq(z / z_scale_factor, 0*z, decimal=0)
A_k_estimated_all[observe] = A_k_estimated A_kl_estimated_all[observe] = A_kl_estimated print("=============================================") print(" Testing computeMultipleExpectations") print("=============================================") # have to exclude the potential and RMS displacemet for now, not functions of a single state observables_single = ['position', 'position^2'] A_ikn = numpy.zeros([len(observables_single), K, N_k.max()], numpy.float64) for i, observe in enumerate(observables_single): A_ikn[i, :, :] = A_kn_all[observe] for i in range(K): results = mbar.computeMultipleExpectations(A_ikn, u_kln[:, i, :], compute_covariance=True) A_i = results['mu'] dA_ij = results['sigma'] Ca_ij = results['covariances'] print("Averages for state %d" % (i)) print(A_i) print("Uncertainties for state %d" % (i)) print(dA_ij) print("Correlation matrix between observables for state %d" % (i)) print(Ca_ij) print("============================================") print(" Testing computeEntropyAndEnthalpy") print("============================================")
# save up the A_k for use in computeMultipleExpectations A_kn_all[observe] = A_kn A_k_estimated_all[observe] = A_k_estimated print "=============================================" print " Testing computeMultipleExpectations" print "=============================================" # have to exclude the potential and RMS displacemet for now, not functions of a single state observables_single = ['position','position^2'] A_ikn = numpy.zeros([len(observables_single), K, N_k.max()], numpy.float64) for i,observe in enumerate(observables_single): A_ikn[i,:,:] = A_kn_all[observe] for i in range(K): [A_i,d2A_ij] = mbar.computeMultipleExpectations(A_ikn, u_kln[:,i,:]) print "Averages for state %d" % (i) print A_i print "Correlation matrix between observables for state %d" % (i) print d2A_ij print "============================================" print " Testing computeEntropyAndEnthalpy" print "============================================" (Delta_f_ij, dDelta_f_ij, Delta_u_ij, dDelta_u_ij, Delta_s_ij, dDelta_s_ij) = mbar.computeEntropyAndEnthalpy(verbose = True) print "Free energies" print Delta_f_ij print dDelta_f_ij diffs1 = Delta_f_ij - Delta_f_ij_estimated print "maximum difference between values computed here and in computeFreeEnergies is %g" % (numpy.max(diffs1))
# save up the A_k for use in computeMultipleExpectations A_kn_all[observe] = A_kn A_k_estimated_all[observe] = A_k_estimated print "=============================================" print " Testing computeMultipleExpectations" print "=============================================" # have to exclude the potential and RMS displacemet for now, not functions of a single state observables_single = ['position', 'position^2'] A_ikn = numpy.zeros([len(observables_single), K, N_k.max()], numpy.float64) for i, observe in enumerate(observables_single): A_ikn[i, :, :] = A_kn_all[observe] for i in range(K): [A_i, d2A_ij] = mbar.computeMultipleExpectations(A_ikn, u_kln[:, i, :]) print "Averages for state %d" % (i) print A_i print "Correlation matrix between observables for state %d" % (i) print d2A_ij print "============================================" print " Testing computeEntropyAndEnthalpy" print "============================================" (Delta_f_ij, dDelta_f_ij, Delta_u_ij, dDelta_u_ij, Delta_s_ij, dDelta_s_ij) = mbar.computeEntropyAndEnthalpy(verbose=True) print "Free energies" print Delta_f_ij print dDelta_f_ij diffs1 = Delta_f_ij - Delta_f_ij_estimated
A_kn_all[observe] = A_kn A_k_estimated_all[observe] = A_k_estimated A_kl_estimated_all[observe] = A_kl_estimated print "=============================================" print " Testing computeMultipleExpectations" print "=============================================" # have to exclude the potential and RMS displacemet for now, not functions of a single state observables_single = ['position','position^2'] A_ikn = numpy.zeros([len(observables_single), K, N_k.max()], numpy.float64) for i,observe in enumerate(observables_single): A_ikn[i,:,:] = A_kn_all[observe] for i in range(K): [A_i,dA_ij,Ca_ij] = mbar.computeMultipleExpectations(A_ikn, u_kln[:,i,:], compute_covariance=True) print "Averages for state %d" % (i) print A_i print "Uncertainties for state %d" % (i) print dA_ij print "Correlation matrix between observables for state %d" % (i) print Ca_ij print "============================================" print " Testing computeEntropyAndEnthalpy" print "============================================" (Delta_f_ij, dDelta_f_ij, Delta_u_ij, dDelta_u_ij, Delta_s_ij, dDelta_s_ij) = mbar.computeEntropyAndEnthalpy(u_kn = u_kln, verbose = True) print "Free energies" print Delta_f_ij print dDelta_f_ij
A_kn_all[observe] = A_kn A_k_estimated_all[observe] = A_k_estimated A_kl_estimated_all[observe] = A_kl_estimated print("=============================================") print(" Testing computeMultipleExpectations") print("=============================================") # have to exclude the potential and RMS displacemet for now, not functions of a single state observables_single = ['position','position^2'] A_ikn = numpy.zeros([len(observables_single), K, N_k.max()], numpy.float64) for i,observe in enumerate(observables_single): A_ikn[i,:,:] = A_kn_all[observe] for i in range(K): results = mbar.computeMultipleExpectations(A_ikn, u_kln[:,i,:], compute_covariance=True) A_i = results['mu'] dA_ij = results['sigma'] Ca_ij = results['covariances'] print("Averages for state %d" % (i)) print(A_i) print("Uncertainties for state %d" % (i)) print(dA_ij) print("Correlation matrix between observables for state %d" % (i)) print(Ca_ij) print("============================================") print(" Testing computeEntropyAndEnthalpy") print("============================================") results = mbar.computeEntropyAndEnthalpy(u_kn = u_kln, verbose = True)
A_kn_all[observe] = A_kn A_k_estimated_all[observe] = A_k_estimated A_kl_estimated_all[observe] = A_kl_estimated print "=============================================" print " Testing computeMultipleExpectations" print "=============================================" # have to exclude the potential and RMS displacemet for now, not functions of a single state observables_single = ['position','position^2'] A_ikn = numpy.zeros([len(observables_single), K, N_k.max()], numpy.float64) for i,observe in enumerate(observables_single): A_ikn[i,:,:] = A_kn_all[observe] for i in range(K): [A_i,dA_ij,Ca_ij] = mbar.computeMultipleExpectations(A_ikn, u_kln[:,i,:], compute_covariance=True) print "Averages for state %d" % (i) print A_i print "Uncertainties for state %d" % (i) print dA_ij print "Correlation matrix between observables for state %d" % (i) print Ca_ij print "============================================" print " Testing computeEntropyAndEnthalpy" print "============================================" (Delta_f_ij, dDelta_f_ij, Delta_u_ij, dDelta_u_ij, Delta_s_ij, dDelta_s_ij) = mbar.computeEntropyAndEnthalpy(u_kn = u_kln, verbose = True) print "Free energies" print Delta_f_ij print dDelta_f_ij