import matplotlib.pyplot as plt from utils.archiver import * from utils.plotting import cdf_points import tri_mesh_viewer as tmv if __name__ == "__main__": (_,file_base) = sys.argv (nodes,faces) = read_ctri(file_base + ".mesh") print "Number of nodes:",len(nodes) print "Number of faces:",len(faces) D = Unarchiver(file_base + ".data") (N,A) = D.basis.shape plt.figure() plt.suptitle("Value -> Flow"); for a in xrange(A): plt.subplot(2,2,a+1); tmv.plot_vertices(nodes,faces,D.basis[:,a], cmap=plt.get_cmap('jet')) plt.figure() plt.suptitle("Flow -> Value"); for a in xrange(A): plt.subplot(2,2,a+1); tmv.plot_vertices(nodes,faces,D.ibasis[:,a], cmap=plt.get_cmap('jet')) plt.show()
if __name__ == "__main__": (_,filename) = sys.argv (nodes,faces) = read_ctri(filename + ".mesh") sol = Unarchiver(filename + '.sol') V = nodes.shape[0] assert 0 == sol.p.size % V A = sol.p.size / V P = np.reshape(sol.p,(V,A),order='F') residual = sol.res assert V == residual.size plt.figure() plt.title("Residual l2-norm: " + str(np.linalg.norm(residual))) tmv.plot_vertices(nodes,faces,residual) plt.figure() plt.title("Agg flow") agg_flow = np.sum(P[:,1:],axis=1) tmv.plot_vertices(nodes,faces,agg_flow) plt.clim([0,np.max(agg_flow)]) plt.figure() assert A <= 4 for i in xrange(A): plt.subplot(2,2,(i+1)) plt.title("Component " + str(i)) tmv.plot_vertices(nodes,faces,P[:,i]) plt.figure()
print "Number of faces:",len(faces) sol = Unarchiver(file_base + ".data") ref_P = sol.ref_P ref_D = sol.ref_D P = sol.P D = sol.D (N,A) = P.shape ####################################### # Value plt.figure() plt.suptitle("Value information") plt.subplot(2,2,1) plt.title("Ref. value") tmv.plot_vertices(nodes,faces,ref_P[:,0]) plt.subplot(2,2,2) plt.title("Approx. value") tmv.plot_vertices(nodes,faces,P[:,0]) plt.subplot(2,2,3) plt.title("Difference") tmv.plot_vertices(nodes,faces,P[:,0] - ref_P[:,0]) plt.subplot(2,2,4) plt.title("Bellman res") tmv.plot_vertices(nodes,faces,sol.res) ####################################### # Flow
sol = Unarchiver(file_base + ".sol") N = nodes.shape[0] assert 0 == sol.p1.size % N A = sol.p1.size / N # RHS information if False: Q = sol.Q assert((N,A) == Q.shape) plt.figure() plt.suptitle('Projected Q') for a in range(A): plt.subplot(2,2,a+1) tmv.plot_vertices(nodes,faces,Q[:,a]) # Before and after primal/dual info if True: P1 = np.reshape(sol.p1,(N,A),order='F') D1 = np.reshape(sol.d1,(N,A),order='F') P2 = np.reshape(sol.p2,(N,A),order='F') D2 = np.reshape(sol.d2,(N,A),order='F') for (X,name) in [(P1,"Primal 1"),(D1,"Dual 1"), (P2,"Primal 2"),(D2,"Dual 2")]: plt.figure() plt.suptitle(name) assert A == 3 for a in xrange(A): plt.subplot(2,2,a+1) if a > 0:
if __name__ == "__main__": (_,file_base) = sys.argv (nodes,faces) = read_ctri(file_base + ".mesh") print "Number of nodes:",len(nodes) print "Number of faces:",len(faces) sol = Unarchiver(file_base + ".data") plt.figure() plt.suptitle("Reference solve") plt.subplot(2,3,1) plt.title("Value") tmv.plot_vertices(nodes,faces, sol.primal[:,0]) plt.subplot(2,3,2) plt.title("Policy") tmv.plot_vertices(nodes,faces, np.argmax(sol.primal[:,1:],axis=1)) plt.subplot(2,3,3) plt.title("Min Flow Slack") tmv.plot_vertices(nodes,faces, np.min(sol.dual[:,1:],axis=1)) plt.subplot(2,3,4) plt.title('Residual') tmv.plot_vertices(nodes,faces,sol.residual)
print "Number of nodes:",len(nodes) print "Number of faces:",len(faces) sol = Unarchiver(file_base + ".data") l1 = sol.data[:,:,0] l2 = sol.data[:,:,1] linf = sol.data[:,:,2] ############ plt.figure() plt.suptitle("Residual change") for (i,name) in enumerate(["l1","l2","linf"]): plt.subplot(2,2,i+1) Z = np.min(sol.data[:,:,i],axis=1) plt.title(name) tmv.plot_vertices(nodes,faces,Z,cmap=plt.get_cmap('jet')) ############ plt.figure() plt.suptitle("Minimizing bandwidth") for (i,name) in enumerate(["l1","l2","linf"]): plt.subplot(2,2,i+1) Z = sol.bandwidths[np.argmin(sol.data[:,:,i],axis=1)] Z = np.log(Z) plt.title(name) tmv.plot_vertices(nodes,faces,Z,cmap=plt.get_cmap('jet')) ############ plt.figure() plt.suptitle('Residuals') plt.subplot(2,2,1)
import numpy as np import matplotlib.pyplot as plt from utils.archiver import * from scipy.stats import pearsonr import tri_mesh_viewer as tmv (nodes,faces) = read_shewchuk("/home/epz/data/minop/sensitivity") unarch = Unarchiver("/home/epz/data/minop/sensitivity.exp_res") (N,D) = nodes.shape assert(N == unarch.twiddle.size) plt.subplot(1,2,1) tmv.plot_vertices(nodes,faces,unarch.twiddle) J = unarch.jitter R = unarch.noise P = np.zeros(N) for i in xrange(N): (r,p) = pearsonr(J[i,:],R[i,:]) if(p < 0.01): P[i] = r plt.subplot(1,2,2) tmv.plot_vertices(nodes,faces,P) plt.show()
group = np.argmax(np.abs(basis),1) idx = np.argsort(group) residual = np.array(residual).T jitter = np.array(jitter).T np.savez("tmp.npz", residual=residual, jitter=jitter) Cor1 = np.cov(residual[idx,:]) Cor2 = np.cov(residual[idx,:]*jitter[idx,:]) cmap = plt.get_cmap('jet') (nodes,faces) = read_shewchuk(base_file) for (i,c) in enumerate([Cor1,Cor2]): plt.figure(1); plt.subplot(1,2,i+1) tmv.plot_vertices(nodes,faces,np.diag(c), cmap=cmap,interp='nearest'); plt.colorbar() plt.figure(2); plt.subplot(1,2,i+1) plt.imshow(c, cmap=cmap,interpolation='nearest'); plt.colorbar() plt.show()
if __name__ == "__main__": (_,file_base) = sys.argv sol = Unarchiver(file_base + ".data") (nodes,faces) = read_ctri(file_base + ".mesh") R = sol.residuals (N,I) = R.shape for i in xrange(0,I): plt.figure() plt.suptitle("Iter " + str(i)) plt.subplot(2,3,1) plt.title("Value") tmv.plot_vertices(nodes,faces, sol.primals[:,0,i]) plt.subplot(2,3,2) plt.title("Policy") tmv.plot_vertices(nodes,faces, sol.policies[:,i]) plt.subplot(2,3,3) plt.title("Min Flow Slack") tmv.plot_vertices(nodes,faces, sol.min_duals[:,i]) plt.subplot(2,3,4) plt.title('Residual') tmv.plot_vertices(nodes,faces,sol.residuals[:,i])