def case11(): y0 = [[1,7],[2,6]] t_tuple = 2 stepsize = 0.01 order = 2 maxorder = 2 # start = time.time() t_list, y_list = simulation_ode(mode2_1, y0, t_tuple, stepsize, eps=0) for temp_y in y_list: y0_list = temp_y.T[0] y1_list = temp_y.T[1] plt.plot(y0_list,y1_list,'b') plt.show() tpar_list,ypar_list = parti(t_list,y_list,0.2,1/3) print(len(tpar_list)) for i in range(0,len(tpar_list)): print(tpar_list[i][0]) print(tpar_list[i][-1]) print(ypar_list[i][0]) print(ypar_list[i][-1]) G,labels = infer_dynamic_modes_pie(tpar_list, ypar_list, stepsize, maxorder, 0.02) # modes, coefs, mdors = infer_dynamic_modes_ex(tpar_list, ypar_list, stepsize, maxorder, 0.01) # print(modes) # print(coefs) # print(mdors) print(len(labels)) print(G)
def case4(): y0 = [[5,5,5],[2,2,2]] t_tuple = 5 stepsize = 0.01 maxorder = 2 t_list, y_list = simulation_ode(fvdp3_3, y0, t_tuple, stepsize, eps=0) draw3D(y_list) tpar_list,ypar_list = parti(t_list,y_list,0.2,1/3) G,labels = infer_dynamic_modes_pie(tpar_list, ypar_list, stepsize, maxorder, 0.02) print(labels) print(G)
def case1(): y0 = [[1,7]] t_tuple = 25 stepsize = 0.01 order = 2 maxorder = 4 # start = time.time() t_list, y_list = simulation_ode(mode2_1, y0, t_tuple, stepsize, eps=0) # end_simulation = time.time() # result_coef, calcdiff_time, pseudoinv_time = infer_dynamic(t_list, y_list, stepsize, order) # end_inference = time.time() # print(result_coef) # print() # print("Total time: ", end_inference-start) # print("Simulation time: ", end_simulation-start) # print("Calc-diff time: ", calcdiff_time) # print("Pseudoinv time: ", pseudoinv_time) tpar_list,ypar_list = parti(t_list,y_list,0.05) print(len(tpar_list)) for i in range(0,len(tpar_list)): print(tpar_list[i][0],tpar_list[i][-1]) print(ypar_list[i][0],ypar_list[i][-1]) for temp_y in y_list: y0_list = temp_y.T[0] y1_list = temp_y.T[1] plt.plot(y0_list,y1_list,'b') plt.show() # result_coef, calcdiff_time, pseudoinv_time = infer_dynamic([tpar_list[0],tpar_list[1]], [ypar_list[0],ypar_list[1]], stepsize, 4) # print(result_coef) # tstart = time.time() # comt,comy = simulation_ode_stiff(ode_test(result_coef,4), [ypar_list[0][0],ypar_list[1][0]], [(tpar_list[0][0], tpar_list[0][-1]),(tpar_list[1][0], tpar_list[1][-1])], stepsize,eps=0) # tend = time.time() # print(dist(comy,[ypar_list[0],ypar_list[1]])) # print(tend-tstart) # print(dist([ypar_list[0],ypar_list[2],ypar_list[4]],comy)) # result_coef = np.matrix([[ 0, 0, 0, -0.26, 0.26, 0], [0, 0, 0, 0, 0, -1]]) # comt,comy = simulation_ode(ode_test(result_coef,2), [ypar_list[0][0],ypar_list[2][0],ypar_list[4][0]], [(tpar_list[0][0], tpar_list[0][-1]),(tpar_list[2][0], tpar_list[2][-1]),(tpar_list[4][0], tpar_list[4][-1])], stepsize,eps=0) # print(dist([ypar_list[0],ypar_list[2],ypar_list[4]],comy)) # result_coef = np.matrix([[ 0, 0, 0, -0.26, 0.26, 0], [0, 0, 0, 0, 0, 1]]) # comt,comy = simulation_ode(ode_test(result_coef,2), [ypar_list[1][0],ypar_list[3][0],ypar_list[5][0]], [(tpar_list[1][0], tpar_list[1][-1]),(tpar_list[3][0], tpar_list[3][-1]),(tpar_list[5][0], tpar_list[5][-1])], stepsize,eps=0) # print(dist([ypar_list[1],ypar_list[3],ypar_list[5]],comy)) tstart = time.time() modes, coefs, mdors = infer_dynamic_modes_ex(tpar_list, ypar_list, stepsize, maxorder, 0.001) # modes, coefs, mdors = infer_dynamic_modes_exx(tpar_list, ypar_list, stepsize, maxorder, 0.01) tend = time.time() print(modes) print(coefs) print(mdors) print(tend-tstart)
def case5(): y0 = [[0,0],[1,0]] t_tuple = 2 stepsize = 0.01 order = 2 maxorder = 3 t_list, y_list = simulation_ode(conti_test, y0, t_tuple, stepsize, eps=0) tpar_list,ypar_list = parti(t_list,y_list,0.2,1/3) print(len(tpar_list)) for i in range(0,len(tpar_list)): print(tpar_list[i][0]) print(tpar_list[i][-1]) print(ypar_list[i][0]) print(ypar_list[i][-1]) for temp_y in y_list: y0_list = temp_y.T[0] y1_list = temp_y.T[1] plt.plot(y0_list,y1_list,'b') plt.show() # modes, coefs, mdors = infer_dynamic_modes_ex(tpar_list, ypar_list, stepsize, maxorder, 0.01) # modes, coefs, mdors = infer_dynamic_modes_exx(tpar_list, ypar_list, stepsize, maxorder, 0.01) # print(modes) # print(coefs) # print(mdors) ttest_list=[] ttest_list.append(tpar_list[0]) ttest_list.append(tpar_list[1]) ytest_list=[] ytest_list.append(ypar_list[0]) ytest_list.append(ypar_list[1]) A, b = diff_method(ttest_list, ytest_list, 3, stepsize) g = pinv2(A).dot(b) print(g.T) t_start = tpar_list[0][0] t_end = tpar_list[0][-1] t_start = 0 t_end = 0.01 t_points = np.arange(t_start, t_end + stepsize, stepsize) tstart = time.time() y_object = solve_ivp(ode_test(g.T,3), (t_start, t_end+stepsize), ypar_list[0][0], t_eval = t_points, rtol=1e-7, atol=1e-9) y_points = y_object.y.T tend = time.time() print(y_points) print(tend-tstart)
def case9(): y0 = [[4.7,0.2,-6,0,0,3]] t_tuple = [(0,10)] stepsize = 0.001 maxorder = 1 # start = time.time() t_list, y_list = simulation_ode_2([mmode1, mmode2], event3, y0, t_tuple, stepsize) tpar_list,ypar_list = parti(t_list,y_list,0.2,1/3) print(tpar_list[0].shape) tt = [tpar_list[0],tpar_list[2],tpar_list[4]] yy = [ypar_list[0],ypar_list[2],ypar_list[4]] A ,b = diff_method1(tt, yy, maxorder, stepsize) # # clf = linear_model.LinearRegression(fit_intercept=False,normalize=True) # # clf.fit(A,b) # # g = clf.coef_ # bb = clf.predict(A) g = pinv2(A).dot(b) print("g=",g.T)
def case9(): y0 = [[0,0]] t_tuple = 7 stepsize = 0.001 order = 2 maxorder = 4 t_list, y_list = simulation_ode(mode2_11, y0, t_tuple, stepsize, eps=0) for temp_y in y_list: y0_list = temp_y.T[0] y1_list = temp_y.T[1] plt.plot(y0_list,y1_list,'b') plt.show() tpar_list,ypar_list = parti(t_list,y_list,0.2,1/3) print(len(tpar_list)) for i in range(0,len(tpar_list)): print(tpar_list[i][0]) print(tpar_list[i][-1]) print(ypar_list[i][0]) print(ypar_list[i][-1]) labels = infer_dynamic_modes_ex_dbs(tpar_list, ypar_list, stepsize, maxorder, 0.0001) print(labels)
def case4(): y0 = [[0,0],[1,0]] t_tuple = [(0,2.5),(0,2)] stepsize = 0.01 order = 2 maxorder = 4 # start = time.time() t_list, y_list = simulation_ode(conti_test, y0, t_tuple, stepsize, eps=0) # end_simulation = time.time() # result_coef, calcdiff_time, pseudoinv_time = infer_dynamic(t_list, y_list, stepsize, order) # end_inference = time.time() # print(result_coef) # print() # print("Total time: ", end_inference-start) # print("Simulation time: ", end_simulation-start) # print("Calc-diff time: ", calcdiff_time) # print("Pseudoinv time: ", pseudoinv_time) tpar_list,ypar_list = parti(t_list,y_list,0.2,1/3) print(len(tpar_list)) for i in range(0,len(tpar_list)): print(tpar_list[i][0]) print(tpar_list[i][-1]) print(ypar_list[i][0]) print(ypar_list[i][-1]) for temp_y in y_list: y0_list = temp_y.T[0] y1_list = temp_y.T[1] plt.plot(y0_list,y1_list,'b') plt.show() modes, coefs, mdors = infer_dynamic_modes_ex(tpar_list, ypar_list, stepsize, maxorder, 0.0001) # modes, coefs, mdors = infer_dynamic_modes_exx(tpar_list, ypar_list, stepsize, maxorder, 0.0001) print(modes) print(coefs) print(mdors)
def case10(): y0 = [[0,0],[1,0],[0.3,0],[2.7,0]] t_tuple = 2 stepsize = 0.01 order = 2 maxorder = 3 # start = time.time() t_list, y_list = simulation_ode(conti_test, y0, t_tuple, stepsize, eps=0) # end_simulation = time.time() # result_coef, calcdiff_time, pseudoinv_time = infer_dynamic(t_list, y_list, stepsize, order) # end_inference = time.time() # print(result_coef) # print() # print("Total time: ", end_inference-start) # print("Simulation time: ", end_simulation-start) # print("Calc-diff time: ", calcdiff_time) # print("Pseudoinv time: ", pseudoinv_time) tpar_list,ypar_list = parti(t_list,y_list,0.2,1/3) print(len(tpar_list)) for i in range(0,len(tpar_list)): print(tpar_list[i][0]) print(tpar_list[i][-1]) print(ypar_list[i][0]) print(ypar_list[i][-1]) for temp_y in y_list: y0_list = temp_y.T[0] y1_list = temp_y.T[1] plt.plot(y0_list,y1_list,'b') plt.show() G,labels = infer_dynamic_modes_pie(tpar_list, ypar_list, stepsize, maxorder, 0.15) print(labels) print(G)