def plot_reconstruction_result(res): """ Plot original and reconstructed graph plus time series """ fig = plt.figure(figsize=(32, 8)) gs = mpl.gridspec.GridSpec(1, 4) # original graph orig_ax = plt.subplot(gs[0]) plot_graph(nx.from_numpy_matrix(res.A.orig), orig_ax) orig_ax.set_title('Original graph') # time series ax = plt.subplot(gs[1:3]) sns.tsplot( time='time', value='theta', unit='source', condition='oscillator', estimator=np.mean, legend=False, data=compute_solutions(res), ax=ax) ax.set_title(r'$A_{{err}} = {:.2}, B_{{err}} = {:.2}$'.format(*compute_error(res))) # reconstructed graph rec_ax = plt.subplot(gs[3]) tmp = res.A.rec tmp[abs(tmp) < 1e-1] = 0 plot_graph(nx.from_numpy_matrix(tmp), rec_ax) rec_ax.set_title('Reconstructed graph') plt.tight_layout() save(fig, 'reconstruction_overview')
def plot_reconstruction_result(res): """ Plot original and reconstructed graph plus time series """ fig = plt.figure(figsize=(32, 8)) gs = mpl.gridspec.GridSpec(1, 4) # original graph orig_ax = plt.subplot(gs[0]) plot_graph(nx.from_numpy_matrix(res.A.orig), orig_ax) orig_ax.set_title('Original graph') # time series ax = plt.subplot(gs[1:3]) sns.tsplot(time='time', value='theta', unit='source', condition='oscillator', estimator=np.mean, legend=False, data=compute_solutions(res), ax=ax) ax.set_title( r'$A_{{err}} = {:.2}, B_{{err}} = {:.2}$'.format(*compute_error(res))) # reconstructed graph rec_ax = plt.subplot(gs[3]) tmp = res.A.rec tmp[abs(tmp) < 1e-1] = 0 plot_graph(nx.from_numpy_matrix(tmp), rec_ax) rec_ax.set_title('Reconstructed graph') plt.tight_layout() save(fig, 'reconstruction_overview')
def input_graph(): global graph from sphereofinfluence import SoIGraph graph = SoIGraph.randomize(0, 100, 100) plotter.start_gui(graph) # plotter.show() plotter.plt.ion() plotter.plot_graph(graph) plotter.plot_arrows(graph) plotter.show() # breadth_first_search(graph) # depth_first_search(graph) dijkstra(graph)
def compute(infile, outfile): start = time.time() df = pd.read_csv(infile) N, n = df.shape G = nx.gn_graph(n) #==========================================# #to verify values # G = nx.DiGraph() # G_new, G_alt = create_random_graph(n, G) #==========================================# bayes = BayesScore(G, df) # This is inside compute G_opt, score_opt = local_search(bayes, G, df) end = time.time() timer = end - start print('total time: %.2', timer) # G_opt = G; score_opt = 100; G_opt = nx.relabel_nodes(G_opt, bayes.idx2node) # plot_graph(G_opt, show=True) # pdb.set_trace() print('best final score:', score_opt) length = df.shape[1] d = bayes.node2idx node_list = sorted(d, key=d.get) # parents_values = [data[parent]-1 for parent in parents] # pdb.set_trace() timestamp = str(int(time.time())) new_dir = str("./out_") + timestamp os.mkdir(new_dir) filename = new_dir + ('/') + outfile write_gph(G_opt, bayes.node2idx, filename) fig = plot_graph(G_opt) title = 'score = %.2f, time taken = %.2f (s)' % (score_opt, timer) plt.title(title) # new_dir = str("./out_")+str(int(time.time()) ) figname = new_dir + ('/') + (infile[:2]) + ('.png') plt.savefig(figname)
def main(): #call classifier for an svm clf = classifier("SVM") #call train for an svm result_clf = clf.train() #call test for an svm svm_stats = clf.test(result_clf) #create a dataframe object with the results from testing the svm df = pd.DataFrame.from_dict(svm_stats) #call classifier for KNN, train, test, and append the results to the dataframe clf = classifier("KNN") result_clf = clf.train() knn_stats = clf.test(result_clf) df = df.append(knn_stats, ignore_index=True) #call classifier for a neural net, train, test, and append results to the dataframe clf = classifier("ANN") result_clf = clf.train() ann_stats = clf.test(result_clf) df = df.append(ann_stats, ignore_index=True) #call classifier for a decision tree, train, test, and append results to the dataframe clf = classifier('DT') result_clf = clf.train() dt_stats = clf.test(result_clf) df = df.append(dt_stats, ignore_index=True) #call classifier for an adaboosted decision tree, train, test, and append results to dateframe clf = classifier('Boost') result_clf = clf.train() boost_stats = clf.test(result_clf) df = df.append(boost_stats, ignore_index=True) # Create plot_graph object with df to plot relevant graphs grapher = plot_graph(df) grapher.plot_graphs()
scores_global_agent = [] scores=[] steps = [] for runs in range(1, 50000000): for (i, agent) in enumerate(agents): # training each agent serially (needs to be parallelized) agent.train(FREQUENCY_OF_UPDATE) scores.append(test_agent(test_env, agent)) #Cartpole # scores.append(501+test_agent(test_env, agent)) #Acrobot # scores.append(201+test_agent(test_env, agent)) #Mountain Car single_agent.train(FREQUENCY_OF_UPDATE) global_agent = combine_agents_reward_based(global_agent, agents, scores) # global_agent = combine_agents(global_agent, agents) scores=[] agents = distribute_agents(global_agent, agents) if(runs%5==0): scores_global_agent.append(test_agent(test_env, global_agent)) scores_single_agent.append(test_agent(test_env, single_agent)) steps.append(single_agent.step_cnt) np.savetxt('arrays/scores_global_agent_'+ENV_NAME+'.csv', np.array(scores_global_agent)) np.savetxt('arrays/scores_single_agent_'+ENV_NAME+'.csv', np.array(scores_single_agent)) np.savetxt('arrays/steps_'+ENV_NAME+'.csv', np.array(steps)) ###############PLOT################## plot_graph(scores_global_agent, scores_single_agent, steps, ENV_NAME, NO_OF_TRAINERS, ROLLING=20)
model.compile(loss='mse', optimizer='adam', metrics=['mae', 'mse']) model.summary() model.fit(X_train, Y_train, epochs=1000, validation_split=0.2, callbacks=[tb]) loss, mae, mse = model.evaluate(X_test, Y_test, verbose=0) #predicting input_dict = train input_dict_x = input_dict.drop("Y", axis=1) input_dict_y = input_dict["Y"] predict_results = model.predict(input_dict_x) print(predict_results) predictions_Original = predict_results # New Dataset d = {'X': [7, 8, 9, 10, 11]} df = pd.DataFrame(data=d) predict_results = model.predict(df) print(predict_results) new_predections = predict_results from plotter import plot_graph plot_graph(train, predictions_Original, new_predections, "graph_{}".format(int(time.time())))