print "Opened %s" % sys.argv[1] out = open(sys.argv[2], "w+") print "Output will be written to %s" % sys.argv[2] if (k == 0): print "Currently Configured to sum along the COLUMN" else: print "Currently Configured to sum along the ROW" n = matrix.shape[0] print "Normalizing Input Matrix along ", if (k == 0): print "each column" else: print "each row" Norm = matrixFunctions2d.normalize2dMatrix(matrix, k) #print Norm logd = logm(Norm) print logd diag = matrixFunctions2d.diagonalAdjustment2d(logd) #print free energy to f.txt matrixFunctions2d.printDetailedBalanceftxt(diag, "diagonal_db_%s.dat" % sys.argv[1]) matrixFunctions2d.write2dMatrix(diag, "diagonal_Matrix_%s.dat" % sys.argv[1]) #detailed balance #matrixFunctions2d.print2dMatrix(diag)
#!/usr/bin/python import sys import numpy as np import matrixFunctions2d from scipy.linalg import expm, logm matrix = matrixFunctions2d.read2dMatrix(sys.argv[1]) Norm = matrixFunctions2d.normalize2dMatrix(matrix, 0) logd = logm(Norm) #mat = expm(matrix) #matrixFunctions2d.printDetailedBalanceftxt(mat, "quickout.txt") matrixFunctions2d.printDetailedBalanceftxt( logd, "detailedBalance_%s.dat" % sys.argv[1]) #matrixFunctions2d.printDetailedBalanceftxt(matrix, "quickout.txt")
print "Opened %s" % sys.argv[1] out = open(sys.argv[2], "w+") print "Output will be written to %s" % sys.argv[2] if (k == 0): print "Currently Configured to sum along the COLUMN" else: print "Currently Configured to sum along the ROW" n = matrix.shape[0] print "Normalizing Input Matrix along ", if (k == 0): print "each column" else: print "each row" Norm = matrixFunctions2d.normalize2dMatrix(matrix, k) #print Norm log = logm(Norm) adjusted = matrixFunctions2d.weightedAdjustment2d(log, k) exp = expm(adjusted) matrixFunctions2d.printDetailedBalanceftxt(adjusted, "weighted_db_%s.dat" % sys.argv[1]) matrixFunctions2d.write2dMatrix(adjusted, "weighted_Matrix_%s.dat" % sys.argv[1]) #matrixFunctions2d.print2dMatrix(adjusted)
norm = matrixFunctions2d.normalize2dMatrix(mat, 1)#along row log = logm(norm) Q = matrixFunctions2d.diagonalAdjustment2d(log) #this is our Qnaught #Q = matrixFunctions2d.weightedAdjustment2d(log) def func(x, i, j, Q): P = expm(Q) n = Q.shape[0] copy = np.copy(Q) for k in range(n): diff = Q[i,j] - x#initially zero for first iteration, should change as x changes for u in range(n): if(u!=j): copy[i,u] += float(diff/n) copy[i,i] = -1 * (np.sum(copy[i,:]) - copy[i,i]) #set diagonal to neg sum return distance(copy, Q) n = norm.shape[0] q = np.copy(Q) for i in range(n): for j in range(n): if(i!=j): calculations+=1 print calculations q[i,j] = optimize.fmin(func, Q[i,j], args=(i,j,Q))#argmin(i, j, Q, c) print q[i,j] Q = np.copy(q) #put updated matrix in place of Q matrixFunctions2d.printDetailedBalanceftxt(np.transpose(Q), "componentwise_%s.dat"%sys.argv[1])
elif(j==0): Sort[j,i] = Sort[j,i] + l[i] else: Sort[j,i] = Sort[j,i] + l[i] #matrixFunctions2d.print2dMatrix(Sort) #use Unsort Matrix to get final output final = np.zeros((n,n)) if(k==1): for i in range(n): for j in range(n): final[i,j] = Sort[i,int(Unsort[i,j])-1] else: for i in range(n): for j in range(n): final[j,i] = Sort[int(Unsort[j,i])-1,i] #print #print #matrixFunctions2d.print2dMatrix(Unsort) #print #print #matrixFunctions2d.print2dMatrix(final) matrixFunctions2d.printDetailedBalanceftxt(final, "QOG_DB_%s.dat"%sys.argv[1]) matrixFunctions2d.write2dMatrix(final, "QOG_mat_%s.dat"%sys.argv[1])
xval = 4 niters = 1000 deltaT = 1 #number of times to jump through prior before moving to next step repeats = 100 while (nGibbs > 0): print "Gibbs Iteration: ", totalIters - nGibbs nGibbs -= 1 samples, accepted, totalCount = metropolis.metropolisHastings( niters, repeats, n, distribution, deltaT, metropolis.transitionProbSimple, metropolis.stepGenerator, Q) #Draw Samples Using Q N = metropolis.samplesToN(samples, n) N = matrixFunctions2d.normalize2dMatrix(N, 0) #normalize along row for i in range(n): for j in range(n): if (N[i, j] == 0): N[i, j] = val Q[i, j] = gammaFunction(N[i, i], N[i, j], alpha[i, j]) #Use Samples to make new Q for i in range(n): Q[i, i] = -1.0 * (np.sum(Q[i, :]) - Q[i, i]) #repeat matrixFunctions2d.write2dMatrix( N, "gibbs_matrix_%s_%s.dat" % (sys.argv[1], totalIters - nGibbs)) matrixFunctions2d.printDetailedBalanceftxt( N, "gibbs_db_%s_%s.dat" % (sys.argv[1], totalIters - nGibbs), "#Number of Iterations : %s" % sys.argv[2]) # counts = metropolis.countSamples(samples, n) # metropolis.printCounts(fname, totalCount, accepted, n, counts, xval)
from scipy.linalg import expm, logm mat = matrixFunctions2d.read2dMatrix(sys.argv[1]) tau = int(sys.argv[2]) kb = 0.0019872041 T = 298 kbT = kb * T #print kbT beta = 1 / kbT #print beta binWidth = 0.083333 #edit, first calculate DB statistics, then D(x), then double sum for an answer #calculate DB f = matrixFunctions2d.printDetailedBalanceftxt(mat, "temp") #print f[11], f[35] Our -1, 1 are at 11/35 respectivelyi lower = 11 upper = 35 adjustment = 1 #the F index is off by one lower = 12 upper = 36 adjustment = 0 P = expm(0.000001 * mat) f = np.zeros(P.shape[0]) sumd = 0 for i in range(P.shape[0]): sumd += P[i, i] for i in range(P.shape[0]): f[i] = P[i, i] / sumd for i in range(40):