def nextTimeStep( Q, epsilon ): #returns the next timestep and a 0 to continue loop, or the same value and a 1 to stop the loop n = Q.shape[0] NextQ = np.zeros((n, n)) for i in range(n): for j in range(n): NextQ[i, j] = expectation( Q, i, j) #as defined in paper, see above functions NextQN = matrixFunctions2d.normalize2dMatrix(NextQ) #Cannot be weighted adjust, investigate why later NextQ = matrixFunctions2d.weightedAdjustment2d(NextQN) NextQ = matrixFunctions2d.diagonalAdjustment2d(NextQN) # print NextQ dist = frobenius(NextQ, Q) if (dist < epsilon): return Q, dist, 1 else: return NextQ, dist, 0
z = hops[index - 1] switch = -1 if (iters > maxIters): value = 0 iters += 1 # print index, value, iters, x, y return hops[index] mat = matrixFunctions2d.read2dMatrix(sys.argv[1]) mat = matrixFunctions2d.normalize2dMatrix(mat, 0) P = np.copy(mat) #initial Probability Matrix mat = logm(mat) Q = matrixFunctions2d.diagonalAdjustment2d(mat, 0) #this is our Qnaught #Q = matrixFunctions2d.weightedAdjustment2d(log) def func(x, i, j, Q, P): #x is exp(Q(q_{i,j})) # P = expm(Q) Q_e = expm(Q) n = Q.shape[0] copy = np.copy(Q) #diff = np.real(Q[i,j] - x)#initially zero for first iteration, should change as x changes diff = np.real( Q_e[i, j] - P[i, j]) #initially zero for first iteration, should change as x changes for k in range(n): for u in range(n):
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)