def main(): delta_days = (dt.date.today() - (dt.date.today() - relativedelta(months=1))).days mizore = Grapher(delta_days) mizore.make_graph_of_counts_per_daily("monthly_graph.png") mizore.make_glaph_of_counts_per_hourly("monthly_graph_per_hourly.png") mizore.post(("monthly_graph.png", "monthly_graph_per_hourly.png"))
def peak_tag_corr(df): #Preprocessing peak_score = pd.DataFrame(df['Peak Score']) tag_data = pd.DataFrame([df.iloc[:, -i] for i in range(1, 7)]).T data_to_plot = pd.concat([peak_score, tag_data], axis=1) log_data = np.log10(data_to_plot) #Instantiating graph variables figsize = (12, 6) fig_name = 'Peak score for each motif tag count with log scaling' axis_names = [ 'Peak Score', 'CCGTCC tag count (in bp)', 'ATGTCA tag count (in bp)', 'AGTTCC tag count (in bp)', 'AGTCAA tag count (in bp)', 'GTCCGC tag count (in bp)', 'GTAGAG tag count (in bp)' ] cols_to_graph = list(range(7)) #Create Grapher object and make a big scatter grapher = Grapher(log_data, figsize) #grapher = Grapher(data_to_plot, figsize) grapher.big_scatter(cols_to_graph, shape=(2, 3), fixed_y=0, axis_names=axis_names, fig_name=fig_name) plt.show() grapher.fig.savefig(out_dir, bbox_inches="tight", dpi=600)
def player(playerID): player = Player(playerID) shotChart = player.getShotData() headers = shotChart['resultSets'][0]['headers'] shots = shotChart['resultSets'][0]['rowSet'] # print(shots) # print('---') grapher = Grapher(shots) x,y,shotStatus = grapher.getShotCoordinates() # split shot coordinates into made and miss madeX = [] madeY = [] missedX = [] missedY = [] for i in range(len(x)): if shotStatus[i] == 'Made Shot': madeX.append(x[i]) madeY.append(y[i]) else: missedX.append(x[i]) missedY.append(y[i]) file = grapher.makeGraph(x,y, madeX, madeY, missedX, missedY) return render_template('player.html', playerID=playerID, shotChart=file)
def run(self, pos1, vel1, pos2, vel2): self.screen = pygame.display.set_mode(self.size) self.coord_converter = CoordConverter((-10, 10), (-10, 10), (0, self.screen.get_size()[0]), (0, self.screen.get_size()[1])) pygame.display.set_caption('Relativistic') self.engine = Engine(pos1, vel1, pos2, vel2) self.time_multiplier = 1.0 self._drawer = Drawer(self.screen, self.coord_converter) self._grapher = Grapher(self.screen, self.coord_converter) #self.drawer = Drawer(self.screen, self.coord_converter) self.drawer = self._drawer self.clock = pygame.time.Clock() self.clock.tick(60) self.running = True while self.running: for event in pygame.event.get(): if event.type == pygame.QUIT: self.running = False else: self.interface.handle_event(event) self.clock.tick(60) if self.drawer is self._drawer: self.engine.adjust_bodies() self.engine.update(self.clock.get_time() / 1000 * self.time_multiplier) self.draw()
def testMeta(): data = Data() meta = MetaNet(input_vector_size= 28*28, subnet_output_vector_size=10) grapher = Grapher() #TODO: Actually use this for something subNetList = [] print("Phase 1: Train Subnet on Numbers") accuracy = [] for datum in data.sub_tr: (img, label) = datum if (meta.trainSubNet(img, label) == label): accuracy.append(1) else: accuracy.append(0) grapher.addGraph(accuracy, "SubNet Train Accuracy") print("Phase 2: Train AlterNet on Letters") accuracy = [] for datum in data.alter_tr: (img, label) = datum if (meta.trainAlterNet(img, label) == label): accuracy.append(1) else: accuracy.append(0) grapher.addGraph(accuracy, "AlterNet Train Accuracy") print("Phase 3: Train SuperNet") accuracy = [] for datum in data.super_tr: (img, label, super_label) = datum if (meta.trainSuperNet(img, label, super_label) == super_label): accuracy.append(1) else: accuracy.append(0) grapher.addGraph(accuracy, "SuperNet Train Accuracy") print("Phase 4: Generate Child Network") (child, accuracy) = meta.generateChild(data.child_tr) grapher.addGraph(accuracy, "Child Generation Accuracy") print("Phase 5: Test Child Network") accuracy = [] for datum in data.child_te: (img, label) = datum if (child.run(img) == label): accuracy.append(1) else: accuracy.append(0) grapher.addGraph(accuracy, "Child Accuracy") grapher.graphAll()
def main(): # parameters: filename of your top output file, where your top output text file is saved tp = TopParser(filename=str(sys.argv[1]), dir_text=str(sys.argv[2])) text = tp.parseText() data = tp.fillDict(text) summary = tp.getSummaryData(data) # parameters (leave data and summary parameter): # - filename that you want your xlsx file to be, # - where you want your xlsx file to be saved g = Grapher(data=data, summary=summary, filename=str(sys.argv[1]), dir_xlsx=str(sys.argv[2])) df1, df_np = g.convertToNumpy() g.createPlot(df_np) g.saveAsXLSX(df1)
def fit(self, *args, **kwargs): MEM_SZ = MEM_SIZE_FCL sess = K.get_session() K.set_learning_phase(1) self.actor = ActorNetwork(sess, self.state_dim, self.nn_action_dim, BATCH_SIZE, TAU, LRA, convolutional=CONVOLUTIONAL, output_activation=ACTION_ACTIVATION) self.critic = CriticNetwork(sess, self.state_dim, self.nn_action_dim, BATCH_SIZE, TAU, LRC, convolutional=CONVOLUTIONAL) self.memory = Memory(MEM_SZ) self.actor.target_model.summary() self.critic.target_model.summary() if LOAD_WEIGHTS: self.actor.model.load_weights(LOAD_WEIGHTS_PREFIX + "actor_model_" + LOAD_WEIGHTS_EPISODE + ".h5") self.critic.model.load_weights(LOAD_WEIGHTS_PREFIX + "critic_model_" + LOAD_WEIGHTS_EPISODE + ".h5") self.actor.target_model.load_weights(LOAD_WEIGHTS_PREFIX + "actor_target_model_" + LOAD_WEIGHTS_EPISODE + ".h5") self.critic.target_model.load_weights(LOAD_WEIGHTS_PREFIX + "critic_target_model_" + LOAD_WEIGHTS_EPISODE + ".h5") print("Weights Loaded!") #==================================================== #Initialize noise processes #self.noise_procs = [] #for i in range(NUM_NOISE_PROCS): # self.noise_procs.append(OUProcess(OU_MEAN, OU_THETA, OU_STD_DEV)) #==================================================== PRE_LEARNING_EPISODES = STARTING_EPISODE + PRE_LEARNING_EPS steps = STARTING_EPISODE * EPISODE_LENGTH start_time = time.time() last_ep_time = time.time() if MAKE_PLOT: reward_graph = Grapher() for ep in range(STARTING_EPISODE, EPISODES): #reset noise processes #for ou in self.noise_procs: # ou.reset() self.noise.reset() #start time counter if (ep == PRE_LEARNING_EPISODES): start_time = time.time() print("Episode: " + str(ep) + " Frames: " + str(ep * EPISODE_LENGTH) + " Uptime: " + str( (time.time() - start_time) / 3600.0) + " hrs ===========") state = self.env.reset() play_only = (ep % 10 == 0) total_reward = 0 if play_only or ALREADY_TRAINED: for step in range(TEST_EPISODE_LENGTH): #print ">>>>>>>>>>>>>", state.shape #img = np.array([np.subtract(img, 128)], dtype=np.float32) #zero center #img = np.multiply(img, 1.0/128.0) #scale [-1,1] #img = np.transpose(state, (1,2,0)) #img = np.array(state) #img = np.transpose(img, (1,2,0)) #print ">>>>>>>>>>>>>", state.shape state = np.reshape(state, state.shape + (1, )) action, control_action = self.selectAction( state, can_be_random=False, use_target=True) nstate, reward, done, info = self.env.step(control_action) total_reward += reward state = nstate else: for step in range(EPISODE_LENGTH): # ACT ============================== epsilon = (float(steps) / float(EPSILON_STEPS)) * ( EPSILON_RANGE[1] - EPSILON_RANGE[0]) + EPSILON_RANGE[0] state = np.reshape(state, state.shape + (1, )) action, control_action = self.selectAction(state, epsilon=epsilon) new_state, reward, done, info = self.env.step( control_action) done = done or (step >= EPISODE_LENGTH) self.memory.addMemory(state, action, reward, new_state, done) state = new_state # LEARN ============================ if ep > PRE_LEARNING_EPISODES: batch, idxs = self.memory.getMiniBatch(BATCH_SIZE) self.learnFromBatch(batch) if done: break # CLEANUP ========================== steps += 1 #we need to consider the episodes without noise to actually tell how the system is doing if play_only and MAKE_PLOT: reward_graph.addSample(total_reward) reward_graph.displayPlot() #calculate fph on total frames total_frames = (ep - PRE_LEARNING_EPISODES) * EPISODE_LENGTH elapsed = time.time() - start_time fps = total_frames / elapsed fph = fps * 3600.0 #re-calculate fps on this episode, so it updates quickly fps = EPISODE_LENGTH / (time.time() - last_ep_time) last_ep_time = time.time() print("fps: " + str(fps) + " fph: " + str(fph) + "\n") #save plot and weights if (ep > 0 and ep % EPISODE_SAVE_FREQUENCY == 0) and not ALREADY_TRAINED: #plot if MAKE_PLOT: reward_graph.savePlot(SAVE_WEIGHTS_PREFIX + "graph_" + str(ep) + ".jpg") #weights self.actor.model.save_weights(SAVE_WEIGHTS_PREFIX + "actor_model_" + str(ep) + ".h5", overwrite=True) self.actor.target_model.save_weights( SAVE_WEIGHTS_PREFIX + "actor_target_model_" + str(ep) + ".h5", overwrite=True) self.critic.model.save_weights( SAVE_WEIGHTS_PREFIX + "critic_model_" + str(ep) + ".h5", overwrite=True) self.critic.target_model.save_weights( SAVE_WEIGHTS_PREFIX + "critic_target_model_" + str(ep) + ".h5", overwrite=True) #network structures (although I don't think I ever actually use these) with open( SAVE_WEIGHTS_PREFIX + "actor_model_" + str(ep) + ".json", "w") as outfile: json.dump(self.actor.model.to_json(), outfile) with open( SAVE_WEIGHTS_PREFIX + "actor_target_model_" + str(ep) + ".json", "w") as outfile: json.dump(self.actor.target_model.to_json(), outfile) with open( SAVE_WEIGHTS_PREFIX + "critic_model_" + str(ep) + ".json", "w") as outfile: json.dump(self.critic.model.to_json(), outfile) with open( SAVE_WEIGHTS_PREFIX + "critic_target_model_" + str(ep) + ".json", "w") as outfile: json.dump(self.critic.target_model.to_json(), outfile)
step=1.0, min_value=0.0) assumptions.RRA = st.number_input('RRA', value=2.0, step=1.0, min_value=0.1) # re initialize strategies based on user defined parameters for i in range(len(strategies)): s = strategies[i].__class__(assumptions) strategies[i] = s sim = Simulator() df = sim.simulate(assumptions, strategies, runs=400) gr = Grapher() chart = gr.graph(df) st.altair_chart(chart) st.title('Asset Sim') st.markdown(''' Asset Sim is a tool to visualize long term investing strategies. Quickly simulate different strategies and market assumptions to see how they affect your finances. ## FAQ ### How is the graph generated? A monte-carlo simulation simulates many runs with the given assumptions and aggegates them together. The lines are the median amounts of assets at a point in time. The error bands show first and third quartiles. ### Why median? Medians are less sensitive to outliers than means. A few lucky runs can blow up a mean. ### Where do the default values come from?
def main(): delta_days = 7 mizore = Grapher(delta_days) mizore.make_graph_of_counts_per_daily("weekly_graph.png") mizore.make_glaph_of_counts_per_hourly("weekly_graph_per_hourly.png") mizore.post(("weekly_graph.png", "weekly_graph_per_hourly.png"))
from grapher import Grapher print("Here are some sample plots for you.") g = Grapher([]) g.examples()
from grapher import Grapher from writer import RowWriter, ColumnWriter from parameters import Parameters params = Parameters() params.use_electrosprayed_parameters() excel_writer = RowWriter() excel_writer.save_row('Mix,Measurement,Result,Diff') subtracted_writer = ColumnWriter() for sheet in params.sheets: print('\n======== ' + sheet + ' ========') grapher = Grapher() grapher.load_sheet_from_excel(params.filename, sheet) grapher.set_params(params) subtracted_writer.save_column('Wavelength', grapher.sheet.get_measurements('Wavelength')) for mixture in params.mixtures: resultMap = {} column_names = [ c for c in list(grapher.sheet.dataframe) if c != 'Wavelength' ] for column_name in column_names: print('\n' + column_name) grapher.calc_exp_model('Wavelength', column_name)
key for key, val in modelData.items() if isinstance(val, UnknownVariable) ] else: task = [key for key in utils.getOutputs() if key in modelData] #LET'S SOLVE if engineType not in graphed or True: graph = args.graph graphed.append(engineType) else: graph = False grph = Grapher(analysisName, graph=graph, view=(not args.noshow), debug=args.debug, cool=args.cool, labels=args.labels) slvr = Solver(modelData, task, grph, logger) utils.tic() try: if slvr.validateTree(): logger.debug("Tree building took %s seconds" % (utils.toc())) logger.debug("Solving tree...") utils.tic() res = slvr.solve() logger.debug("Done! Solving took %s seconds." % (utils.toc())) logger.info("Here are your outputs:\n" + utils.formatData(
span=span, start=stock.shape[0] - 2 * span - 1) env = Longshort(stock_name, window=window, span=span) state_size = env.observation_space.shape[0] action_size = env.action_space.n replay_agent = DQNAgent(state_size, action_size) # model_replay = None agent = DQNAgent(state_size, action_size, model_replay=replay_agent) save_string = './save/' + stock_name + '_weights_without_fees_test.h5' # agent.load(save_string) done = False batch_size = 32 title = env.symbol.upper() + ' MDP Replay ' + os.path.basename( __file__).split('.')[0] grapher = Grapher(title) with open('./save/losses_' + stock_name + '.txt', 'w') as f: for e in range(EPISODES + 1): # Train state = env.reset() state = np.reshape(state, [1, state_size]) for time in range(500): cash, nown, price = env.holdings[0], env.holdings[ 1], env.state[-1] # env.render() action = agent.act(state, time) next_state, reward, done, _ = env.step(action) next_state = np.reshape(next_state, [1, state_size]) agent.remember(state, action, reward, next_state, done) # agent.train(state, action, reward, next_state, done)
from grapher import Grapher c = Grapher('conv.json') print('here')
def extract(raw_txt, logger): c = Cleaner() cleaned_text_list = c.clean(raw_txt) logger.info('Done cleaning') logger.debug(len(cleaned_text_list)) logger.debug(cleaned_text_list) matrix_builder = MatrixBuilder() matrix = matrix_builder.build_sim_matrix(cleaned_text_list, logger) logger.info('Done building sim matrix') logger.debug('Dimensions: {}'.format(matrix.shape)) logger.debug(matrix) g = Grapher() pageranks = g.graph(matrix) logger.info('Generated graph and got pageranks') logger.debug(pageranks) total_doc_size = len(cleaned_text_list) if total_doc_size in range(0, 300): summary_length = int(0.4 * total_doc_size) elif total_doc_size in range(301, 800): summary_length = int(0.2 * total_doc_size) elif total_doc_size in range(801, 1500): summary_length = int(0.1 * total_doc_size) else: summary_length = int(0.05 * total_doc_size) top_ranked = nlargest(summary_length, pageranks, key=pageranks.get) top_ranked.sort() cl = Cluster() top_ranked = cl.splitIntoParagraph(top_ranked, 7.5) logger.debug(top_ranked) result = '' for paragraph in top_ranked: for key in paragraph: top_ranked_sentence = cleaned_text_list[key] result += '{}. '.format(top_ranked_sentence) result += '\n\n' try: del c del cleaned_text_list del matrix_builder del matrix del g del pageranks del total_doc_size del summary_length del top_ranked del cl del raw_txt except: pass return result
def graph(self): self.grapher = Grapher(self.df, self.tags) self.grapher.average_rating() self.grapher.duration() self.grapher.views() self.grapher.gen_tags_plot()
from congress_data_cleaner import CongressDataCleaner from grapher import Grapher from plotter import Plotter ''' Example script for running full analysis on govtrack cosponsor dataset ''' congress_data_cleaner = CongressDataCleaner( 'data/govtrack_cosponsor_data/raw', 'data/govtrack_cosponsor_data/clean/', 'data/party_affiliation/') congress_data_cleaner.clean_all_data() grapher = Grapher('data/govtrack_cosponsor_data/clean/full/', 'analysis/govtrack_cosponsor_data') grapher.get_all_counts() plotter = Plotter('analysis/govtrack_cosponsor_data/counts', 'plots/govtrack_cosponsor_data', 100, 20) plotter.plot_all()
utils.exit_unless_accessible(args.calls) utils.setup_logging(verbosity=args.verbose) # Load graph database (remove duplicates) df_all = df_from_csv_file(args.calls) df = df_all.drop_duplicates() from_fun, to_fun = args.from_function, args.to_function left, right = search_settings(args.direction, args.cutoff) merge_on = ["caller_filename", "caller_function", "callee_filename", "callee_function"] chains_df_right = pd.DataFrame(columns=merge_on) if right: chains_df_right = find_chains_directed_df(df, from_fun, to_fun, right) chains_df_left = pd.DataFrame(columns=merge_on) if left: chains_df_left = find_chains_directed_df(df, from_fun, to_fun, left) _LOGGER.info("Generating the results...") df_chains = pd.concat([chains_df_left, chains_df_right]).drop_duplicates() df_chains = pd.merge(df_all, df_chains, on=merge_on, how='inner') if args.out.endswith(".csv"): df_to_csv_file(df_chains, args.out) else: grapher = Grapher(args.out) grapher.graph(df_chains) grapher.render(args.out) _LOGGER.info("Done")
elif is_line_in_edge(boarded_line, cur_edge.source(), cur_edge.target()): route[counter]._line = cur_line # print("Line Corrected") correct_route(route, boarded_line, remaining_route, counter) else: # print("Changed Bus") boarded_line = cur_edge.line() correct_route(route, boarded_line, remaining_route, counter) e = Exporter() db_edges = e.get_edges() db_vertices = e.get_vertices() # Initialize graph and populate it g = Grapher() g.populate_vertices(db_vertices) g.populate_edges(db_edges) g.populate_graph() d = Dijkstra(g.graph) i = Isochroner(g, 3) route = d.min_path(444, 728) route = route[1] geoms_to_lines = i.geoms_to_lines init_route = route init_line = route[0].line() init_size = len(route) cur_line = init_line counter = 0 corrected_route = correct_route(route, 'A7', route, 0)
lines = [] updatexy(t) p[2] = y + 40 p[1] = x test.update_destination_point(p, s) lines = to_lines(test.joint_points) lines2 = to_lines(test.foward_model(test.joint_angle_only)) for _line in lines2: lines.append(_line) g.redraw(lines) # sys.stdout.write("\r" + test.return_model()) print test.return_model_for_low_level() test.send_serial() sys.stdout.flush() test = RoverArm([50, 40, 15]) test.update_destination_point([40, 0, 40], [1, 0, 0]) test.ros_begin() test.send_serial() lines = to_lines(test.joint_points) # test.establish_serial_connection() # test.serial_write() g = Grapher(lines) g.redraw(lines) while not test.my_rospy.is_shutdown(): g.show(anim)
from flask.ext.script import Manager, Server from grapher import Grapher from vertex import settings if __name__ == "__main__": grapher = Grapher(__name__) manager = Manager(grapher.app) manager.add_command('runserver', Server(port=80)) manager.run()