def calc(eq_x, eq_y, eq_alpha, initial_conditions, params, t_end): eq['diff(psi)'] = read_obj('diff(psi)(nu)') eq['diff(theta)'] = read_obj('diff(theta)(nu)') print('diff(PSI) i = 0: ', eq['diff(psi)'](0)) print('diff(THETA) i = 0: ', eq['diff(theta)'](0)) # Представялем в виде массива eq['dot(psi)'] = [eq['diff(psi)'](0), eq['diff(psi)'](1), eq['diff(psi)'](2)] eq['dot(theta)'] = [eq['diff(theta)'](0), eq['diff(theta)'](1), eq['diff(theta)'](2)] # Подставляем геометрию платформы for i in range(3): eq['dot(psi)'][i] = eq['dot(psi)'][i].subs({beta[0]: 0, beta[1]: 2*pi/3, beta[2]: 4*pi/3}) eq['dot(theta)'][i] = eq['dot(theta)'][i].subs({beta[0]: 0, beta[1]: 2*pi/3, beta[2]: 4*pi/3}) x = Function('x')(t) y = Function('y')(t) alpha = Function('alpha')(t) # p = symbols('p') eq['x'] = eq_x eq['y'] = eq_y eq['alpha'] = eq_alpha eq['dot(alpha)'] = diff(eq_alpha).doit() # nu1, nu2 eq['nu1'] = cos(alpha)*diff(x) + sin(alpha)*diff(y) eq['nu2'] = -sin(alpha)*diff(x) + cos(alpha)*diff(y) # nu1(alpha, x, y) -> nu1(t); nu2(alpha, x, y) -> nu2(t) for i in range(1,3)pi/12: eq['nu' + str(i)] = eq['nu' + str(i)].subs({x: eq['x'], y: eq['y'], Derivative(alpha, t): eq['dot(alpha)'], alpha: eq['alpha']})
def rebuild_nn(nn_params): W_e, W_p, W_o, b_o = read_obj(nn_params, 4) mlp = MLPNoHid(W_e.get_value(), W_p.get_value(), W_o.get_value(), b_o.get_value()) wx = T.matrix('word', dtype='int32') px = T.matrix('POS', dtype='int32') f_pred = theano.function([wx, px], mlp.output(wx, px)) return f_pred
def rebuild_cand(cand_params): W_e, W_p, W_c, W_o, b_o = read_obj(cand_params, 5) mlp = MLPLeftCate(W_e.get_value(), W_p.get_value(), W_c.get_value(), W_o.get_value(), b_o.get_value()) wx = T.matrix('wx', dtype='int32') px = T.matrix('px', dtype='int32') cx = T.matrix('cx', dtype='int32') f_pred = theano.function([wx, px, cx], mlp.output(wx, px, cx)) return f_pred
def get_constraint(self): if calc: #Полученные выражения из связей для nu1 nu2 delta_x delta_y eq['delta_x'] = lambda i: scalar(v['S'](i), e['x']) eq['delta_y'] = lambda i: scalar(v['S'](i), e['y']) eq['nu_1'] = lambda i: scalar(v['S'](i), e['xi']) eq['nu_2'] = lambda i: scalar(v['S'](i), e['eta']) write_obj(eq, 'eq') else: eq = read_obj('eq') return eq
def from_obj(filepath): """ Read a mesh from OBJ. :param filepath: path to OFF file :type filepath: str :return: mesh :rtype: Mesh """ vertices, faces = utils.read_obj(filepath) return Mesh(vertices, faces)
def visualize(param, w_default=300): image_file = param['image_file'] model_file = param['model_file'] proj_param = param['proj_param'] # load image if not os.path.exists(os.path.join(image_file)): print "Image file does not exsists. Skip %s"%(image_file) return img = Image.open(image_file) print "Processing %s"%(image_file) w = w_default h = int(w * img.height / float(img.width)) img = img.resize((w, h), Image.ANTIALIAS) img_array = np.array(img) # load CAD model if not os.path.exists(os.path.join(model_file)): print "Model file does not exsists. Skip %s"%(model_file) return data_3d = utils.read_obj(model_file) vertices_3d = data_3d['vertices'] faces = data_3d['faces'] # projection vertices_2d = utils.proj( vertices_3d, proj_param['R'], proj_param['d'], proj_param['uv'], proj_param['f']) # lay projection onto the image num_vertices = vertices_2d.shape[0] num_faces = faces.shape[0] x_min = np.min(vertices_2d[:, 0]) y_min = np.min(vertices_2d[:, 1]) x_max = np.max(vertices_2d[:, 0]) y_max = np.max(vertices_2d[:, 1]) patches = [] for i in range(0, num_faces): trivert = np.zeros((3, 2)) trivert[0, :] = vertices_2d[faces[i, 0], :] trivert[1, :] = vertices_2d[faces[i, 1], :] trivert[2, :] = vertices_2d[faces[i, 2], :] triangle = Polygon(trivert) patches.append(triangle) p = PatchCollection(patches, alpha=0.2, linewidth=0) fig,ax = plt.subplots() plt.imshow(img_array) ax.add_collection(p) plt.axis('off') plt.show() plt.close(fig)
def get_faces_vertices_2d(param): model_file = param['model_file'] proj_param = param['proj_param'] # load CAD model if not os.path.exists(os.path.join(model_file)): print("Model file does not exsists. Skip %s" % model_file) return data_3d = utils.read_obj(model_file) vertices_3d = data_3d['vertices'] faces = data_3d['faces'] # projection vertices_2d = utils.proj(vertices_3d, proj_param['R'], proj_param['d'], proj_param['uv'], proj_param['f']) return faces, vertices_2d
def get_omegas(self, calc=True): """ угловые скорости (платформы, вилки, колеса) относительно пола """ if calc: print(omega) omega['platform']= lambda i: Derivative(alpha,t)*e['z'] omega['fork'] = lambda i: omega['platform'](i) + Derivative(theta[i],t)*e['z'] omega['wheel'] = lambda i: omega['fork'](i) + Derivative(psi[i],t)*n_wheel(i) write_obj(omega, 'omega') # write_obj(omega['platform'], 'angular_velocity_platform') # write_obj(omega['fork'], 'angular_velocity_fork') # write_obj(omega['wheel'], 'angular_velocity_wheel') else: omega = read_obj('omega') # omega['platform'] = read_obj('angular_velocity_platform') # omega['fork'] = read_obj('angular_velocity_fork') # omega['wheel'] = read_obj('angular_velocity_wheel') return omega
def get_euler_equations(self, calc=True): """ УРАНЕНИЯ ЭЁЛЕРА И ОТСУТСТВИЕ ПРОСКАЛЬЗЫВАНИЯ """ if calc: v['S'] = euler(S, P) v['P'] = euler(P, C) v['C'] = euler(C, D) v['D'] = lambda i: Matrix([0,0,0]) # проскальзывания нет # write_obj(self.it(v['S']), 'point_S_velocity') # write_obj(self.it(v['P']), 'point_P_velocity') # write_obj(self.it(v['C']), 'point_C_velocity') # write_obj(self.it(v['D']), 'point_D_velocity') write_obj(v, 'v') else: v = read_obj('v') # v['S'] = read_obj('point_S_velocity') # v['P'] = read_obj('point_P_velocity') # v['C'] = read_obj('point_C_velocity') # v['D'] = read_obj('point_D_velocity') return v
def rebuild_cate(cate_params): W_c, W_o, b_o = read_obj(cate_params, 3) mlp = MLPPret(W_c.get_value(), W_o.get_value(), b_o.get_value()) cx = T.matrix('cate', dtype='int32') f_pred = theano.function([cx], mlp.output(cx)) return f_pred
def load_nn_data(data_file, options): woov, poov, coov = 'OOV_W', 'OOV_P', 'OOV_C' most_common = 10 word2idx, pos2idx, cate2idx, idx2word, idx2pos, idx2cate = read_obj('maps.save', 6) def expand_wink(mid_wid, mid_pid, options): lw_size, rw_size, lp_size, rp_wsize, _, _ = options['wrap_wsizes'] word_wsize = lw_size + rw_size pos_wsize = lp_size + rp_wsize start_wid, end_wid = [], [] start_pid, end_pid = [], [] for d in range(lw_size): insert2map('WSTART%d' % d, word2idx, idx2word) start_wid.append(word2idx.get('WSTART%d' % d)) for d in range(lw_size, word_wsize): insert2map('WEND%d' % d, word2idx, idx2word) end_wid.append(word2idx.get('WEND%d' % d)) for d in range(lp_size): insert2map('PSTART%d' % d, pos2idx, idx2pos) start_pid.append(pos2idx.get('PSTART%d' % d)) for d in range(lp_size, pos_wsize): insert2map('PEND%d' % d, pos2idx, idx2pos) end_pid.append(pos2idx.get('PEND%d' % d)) history_wid = start_wid + mid_wid + end_wid history_pid = start_pid + mid_pid + end_pid res_w, res_p = [], [] for i in range(len(mid_wid)): wfeat = history_wid[i:word_wsize + i + 1] pfeat = history_pid[i:pos_wsize + i + 1] res_w.append(wfeat) res_p.append(pfeat) return res_w, res_p def write_withmap(file_name, data, dmap): data_wx, data_px, data_y = data w2i, p2i, c2i = dmap with open(file_name, 'r') as f: for line in f: res_wx, res_px, res_y = [], [], [] if line.startswith('#') or len(line) <= 1: continue wpc = [wpc.split('|') for wpc in line.split()] words, poses, cates = zip(*wpc) for word in words: res_wx.append(w2i.get(word, w2i[woov])) for pos in poses: res_px.append(p2i.get(pos, p2i[poov])) for cate in cates: res_y.append(c2i.get(cate, c2i[coov])) res_wx, res_px = expand_wink(res_wx, res_px, options) data_wx.append(res_wx) data_px.append(res_px) data_y.append(res_y) return data_wx, data_px, data_y test_data = ([], [], []) data_map = (word2idx, pos2idx, cate2idx) test_data = write_withmap(data_file, test_data, data_map) all_map = (word2idx, pos2idx, cate2idx, idx2word, idx2pos, idx2cate) return test_data, all_map