def make_uniform_mdp(problem,N,A): boundary = problem.gen_model.boundary.boundary grid = [(l,u,N) for (l,u) in boundary] discretizer = RegularGridInterpolator(grid) action_limits = problem.action_limits action_cuts = [np.linspace(l,u,A) for (l,u) in action_limits] actions = discrete.make_points(action_cuts) num_samples = 150 builder = MDPBuilder(problem, discretizer, actions, num_samples) mdp_obj = builder.build_mdp() return (mdp_obj,discretizer)
def build_basis(disc): N = disc.num_nodes() n = disc.num_real_nodes() points = np.empty((N,2)) points[:n,:] = disc.get_cutpoints() points[n:,:] = np.zeros((N-n,2)) K = 5 W = make_points([np.linspace(0,2.0*np.pi/10,K)]*2) B = [] B.append(np.cos(W.dot(points.T))) B.append(np.sin(W[1:,:].dot(points.T))) B = np.vstack(B).T c = np.random.randn(49) print c Z = B[:n,:].dot(c) plt.imshow(Z.reshape((21,21)),interpolation='none') plt.show()
[z[i],z[i]+w[i]],'-k') plt.show() if __name__ == '__main__': Nx = 33 Ny = 33 Tx = 33 # Resolution for terrain Ty = 33 xdesc = (-2,6,Nx) ydesc = (-2,6,Ny) txdesc = (-2,6,Tx) tydesc = (-2,6,Ty) (P,(X,Y)) = make_points([np.linspace(*xdesc),np.linspace(*ydesc)],True) (_,(TX,TY)) = make_points([np.linspace(*txdesc),np.linspace(*tydesc)],True) x = P[:,0] y = P[:,1] H = height_map_mesh(xdesc,ydesc) h = H.flatten() TH = height_map_mesh(txdesc,tydesc) #(Nx,Ny,Nz) = normal_map(x,y) # Basic surface fig = plt.figure() ax = plt.subplot(1,2,1,projection='3d')
setup = marsh.load('cdiscrete/test.mcts') sim = marsh.load('cdiscrete/test.mcts.sim') (ret,traj,dec,costs) = sim (N,D,T) = traj.shape xl = np.min(traj[:,0,:]) xh = np.max(traj[:,0,:]) vl = np.min(traj[:,1,:]) vh = np.max(traj[:,1,:]) knn = neighbors.KNeighborsRegressor(n_neighbors=1) X = np.array([traj[:,0,0], traj[:,1,0]]).T knn.fit(X,ret) G = 150 (P,(X,Y)) = make_points([np.linspace(xl,xh,G), np.linspace(vl,vh,G)],True) Z = knn.predict(P) plt.pcolormesh(X,Y,np.reshape(Z,(G,G))) for i in xrange(N): plt.plot(traj[i,0,:], traj[i,1,:], 'x-k') plt.show()