def main(): ''' In this method we ask the user if they want to enter a show, and if they type 'N' the program defaults to Family Guy and American Dad. Due to an error in the IMDb PY data base, whenever Family Guy is searched the first output is "The Sorpranos". After testing we found that, this error does not happen on most tv shows. To fix this we coded in an index feature for each of the data sets. if the user wants to put in their own TV show the are prompted to selct theirapportare show from a list. From there we create the dataset and graph them 3 different ways. ''' reader = GetCSV() if input("Do you want to input TV shows? Y or N : ") == "Y": string1 = input("Enter 1st TV show: ") string2 = input("Enter 2nd TV show: ") print() list1 = reader.get_ttcode_list(string1) print("Top 5 Search Results for ", string1, " :") # print(list1) for i in range(5): print((i + 1), ". ", list1[i]) print() print('Select which show you prefer by their number.') # print('Index goes up by one after every line. Start from the top.') index1 = input("Select the index you prefer: ") index1 = str(int(index1) - 1) # index1 -= 1 print('\n') list2 = reader.get_ttcode_list(string2) # print(list2) print() print("Top 5 Search Results for ", string2, " :") # print(list2) for i in range(5): print((i + 1), ". ", list2[i]) print() print('Select the show that you prefer by their number.') # print('Index goes up by one after every line. Start from the top.') index2 = input("Select the index you prefer: ") index2 = str(int(index2) - 1) # index2 -= 1 else: string1 = "Family Guy" string2 = "American Dad" index1 = 1 index2 = 0 print("Please hold while we scrape your data") graphs = Graphs() tt_string1 = reader.get_ttcode(string1, index1) season_length1 = reader.get_season_length(tt_string1) # print(tt_string1, season_length1) data1 = reader.get_csv(tt_string1, season_length1, string1) tt_string2 = reader.get_ttcode(string2, index2) season_length2 = reader.get_season_length(tt_string2) data2 = reader.get_csv(tt_string2, season_length2, string2) graphs.testing(data1, data2, string1, string2) graphs.scatterplot(data1, data2, string1, string2) graphs.boxplot(data1, data2, string1, string2) graphs.multi(data1, data2, string1, string2)
def main(): nlp = spacy.load("en_core_web_lg") directory = "/home/harsh/Downloads/data/ner-eval-collection-master/plainTextFiles/" results = [] for i in range(0, 128): filename = directory + str(i) + ".txt" file = open(filename, "r") file_content = file.read() file_content = file_content.split("<delim>") article_text = file_content[0] doc = nlp(article_text) if file_content[1]: file_content[1].strip() mse_text = file_content[1].replace("[", "").replace("]", "").replace("\n", "") mse_text = mse_text.split(",") if file_content[2]: file_content[2].strip() lse_text = file_content[2].replace("[", "").replace("]", "").replace("\n", "") lse_text = lse_text.split(",") article_result = Result(i, article_text, mse_text, lse_text) frequency_analysis(doc, article_result) results.append(article_result) # print(article_result.toString()) graph = Graphs(results) graph.graph2('frequency_analysis')
def main(): fin = open("input.txt", "r") numVert = int(fin.readline()) numEdges = int(fin.readline()) g = Graphs(numVert) for i in range(numEdges): pair = fin.readline() numbers = pair.split() V0 = int(numbers[0]) V1 = int(numbers[1]) g.addEdges(V0, V1) testcases = int(fin.readline()) for i in range(testcases): pair = fin.readline() testnumbers = pair.split() V0 = int(testnumbers[0]) V1 = int(testnumbers[1]) depthsearch = g.findPathDepth(V0, V1) # print("Depth Search is", depthsearch) #breadthsearch = g.findpathBreadth(V0,V1) print("Breadth Search is", depthsearch)
def graph_no_correct(self,average=False): if average == True: no_correct = Graphs(title=self.title,xlabel="Time in Seconds",ylabel="Absorbance",y_names=self.unique_names) fig, ax = no_correct.basic_plot(x_data=self.x_data,y_data=self.averages) plt.show() elif average == False: no_correct = Graphs(title=self.title,xlabel="Time in Seconds",ylabel="Absorbance",y_names=list(self.names)) fig, ax = no_correct.basic_plot(x_data=self.x_data,y_data=self.y_data) plt.show()
def __init__(self, graphs: Graphs, feature_pairs, split=1): self._interval = int(graphs.number_of_graphs() / split) self._all_features = graphs.features_matrix_by_index(for_all=True) self._nodes_for_graph = graphs.nodes_count_list() self._all_ftr_graph_index = [] for i in range(len(self._nodes_for_graph) + 1): self._all_ftr_graph_index.append(np.sum( self._nodes_for_graph[0:i])) super(LinearContext, self).__init__(graphs, feature_pairs)
def __init__(self): self.window = Tk() self.window.protocol("WM_DELETE_WINDOW", self.finishApp) self.window.title('Herramienta de prueba para la predicción') ico = PhotoImage(file=os.path.abspath('.') + '/Activos/term.png') self.window.call('wm', 'iconphoto', self.window._w, ico) self.window.config(bg=mainColor) self.window.attributes("-zoomed", False) self.window.minsize(width=300, height=300) #Peso 100% en self.window self.window.grid_rowconfigure(0, weight=1) self.window.grid_columnconfigure(0, weight=1) #Ventana principal fija sin ajuste de tamaño self.window.resizable(False, False) #Centrar ventana en función de las dimendsiones del contenedor de inicio self.center(450, 490) self.view = Window(self.window) self.functions = Functions() self.infoW = Info(self.view.dataContainer) self.genDataW = GenData(self.view.dataContainer) self.predW = Predictions(self.view.dataContainer) self.graphsW = Graphs(self.view.dataContainer) #Botones de las acciones del usuario self.view.buttonDisconnect.bind("<Button>", self.disconnect) self.view.buttonToBD.bind("<Button>", self.changeToConnect) self.view.buttonConnect.bind("<Button>", self.checkConnection) self.view.infoButton.bind( "<Button>", lambda event: self.switchSelector( self.view.predButton, self.view.graphButton, self.view. genDataButton, self.view.infoButton, 1)) self.view.genDataButton.bind( "<Button>", lambda event: self.switchSelector( self.view.infoButton, self.view.predButton, self.view. graphButton, self.view.genDataButton, 2)) self.view.predButton.bind( "<Button>", lambda event: self.switchSelector( self.view.infoButton, self.view.graphButton, self.view. genDataButton, self.view.predButton, 3)) self.view.graphButton.bind( "<Button>", lambda event: self.switchSelector( self.view.infoButton, self.view.genDataButton, self.view. predButton, self.view.graphButton, 4)) self.genDataW.buttonFilterData.bind("<Button>", lambda event: self.getNewGenData()) self.graphsW.buttonGetGraph.bind("<Button>", lambda event: self.getGraphsData()) self.predW.buttonForecast.bind("<Button>", self.getForecast) self.predW.butHistForecast.bind("<Button>", self.getHistForecast) #Ventana principal actualizaciones self.window.mainloop()
def graph(id): if id == 0: Graphs().cases_of_the_world(write=True) return render_template("./graphs/world.html") data = DataProcessing().all_cases_per_day_where_country_id_equal( country_id=id) df = DataProcessing().get_dateframe(data=data) get_graph = Graphs().get_graph(dataframe=df, country_id=id, write=True) return render_template("./graphs/" + get_graph[1] + ".html")
def __init__(self): # pearson + linear_regression(simple) + KNN + context self._params = { 'database': 'EnronInc', # 'database': 'mc2_vast12', # 'database': 'twitter_security', 'files_path': "../../../databases/EnronInc/EnronInc_by_day", # 'files_path': "../../databases/mc2_vast12/basic_by_minute", # 'files_path': "../../databases/twitter_security/data_by_days", 'date_format': '%d-%b-%Y.txt', # Enron # 'date_format': '%d:%m:%Y_%H:%M.txt', # vast # 'date_format': '%d:%m.txt', # Twitter 'directed': False, 'max_connected': False, 'logger_name': "default Anomaly logger", 'ftr_pairs': 28, 'identical_bar': 0.9, # 'single_c': False, 'dist_mat_file_name': "dist_mat", 'anomalies_file_name': "anomalies", 'context_beta': 4.1, 'KNN_k': 18, 'context_split': 1, 'context_bar': 0.45 } self._ground_truth = [ '13-Dec-2000', '18-Oct-2001', '22-Oct-2001', '19-Nov-2001', '23-Jan-2002', '30-Jan-2002', '04-Feb-2002' ] # Enron # self._ground_truth = ['1:5', '13:5', '20:5', '24:5', '30:5', '3:6', '5:6', '6:6', '9:6', '10:6', '11:6', # '15:6', '18:6', '19:6', '20:6', '25:6', '26:6', '3:7', '18:7', '30:7', '8:8', # '9:8'] # Twitter # self._ground_truth = ['4:5:2012_17:51', '4:5:2012_20:25', '4:5:2012_20:26', '4:5:2012_22:16', '4:5:2012_22:21' # , '4:5:2012_22:40', '4:5:2012_22:41', '4:6:2012_17:41', '4:5:2012_18:11'] # vast self._logger = PrintLogger("default Anomaly logger") self._graphs = Graphs(self._params['database'], files_path=self._params['files_path'], logger=self._logger, features_meta=ANOMALY_DETECTION_FEATURES, directed=self._params['directed'], date_format=self._params['date_format'], largest_cc=self._params['max_connected']) self._graphs.build(force_rebuild_ftr=REBUILD_FEATURES, pick_ftr=RE_PICK_FTR, should_zscore=False) # normalize features --------------------------------- self._graphs.norm_features(log_norm) # convert to index self._ground_truth = [ self._graphs.name_to_index(event) for event in self._ground_truth ] self.print_feature_meta()
def render_panel(state, method, tab): if tab == "Deaths": data = pd.read_csv(pred_path + "death_{}_{}.csv".format(state, method), index_col=0) data = pd.Series(data[state], index=data.index) return Graphs.draw_panel(data, state, tab) else: data = pd.read_csv(pred_path + "daily_{}_{}.csv".format(state, method), index_col=0) data = pd.Series(data[state], index=data.index) return Graphs.draw_panel(data, state, "Cases")
def __init__(self): # pearson + linear_regression(simple) + KNN + context self._params = { 'database': 'EnronInc', 'files_path': "../databases/EnronInc/EnronInc_by_day", 'date_format': '%d-%b-%Y.txt', # Enron 'directed': False, 'max_connected': True, 'logger_name': "Yeela's logger", 'ftr_pairs': 25, 'identical_bar': 0.95, 'dist_mat_file_name': "dist_mat", 'anomalies_file_name': "anomalies", 'context_beta': 4, 'KNN_k': 30, 'context_split': 1, 'context_bar': 0.45 } # the anomalies self._ground_truth = [ '13-Dec-2000', '18-Oct-2001', '22-Oct-2001', '19-Nov-2001', '23-Jan-2002', '30-Jan-2002', '04-Feb-2002' ] # Enron # init logger self._logger = PrintLogger(self._params['logger_name']) # init multi-graph self._graphs = Graphs(self._params['database'], files_path=self._params['files_path'], logger=self._logger, features_meta=ANOMALY_DETECTION_FEATURES, directed=self._params['directed'], date_format=self._params['date_format'], largest_cc=self._params['max_connected']) self._graphs.build(force_rebuild_ftr=REBUILD_FEATURES, pick_ftr=RE_PICK_FTR) # replace features with features from old version old_features_path = path.join("data", "EnronInc_directed:False_lcc:True", "old_features.pkl") self._graphs._multi_graph._features_matrix_dict = pickle.load( open(old_features_path, "rb")) # convert anomalies name to index self._ground_truth = [ self._graphs.name_to_index(event) for event in self._ground_truth ] # print features that are being used self.print_feature_meta()
def graph_corrected_normalized(self,average=False): if self.dic == None and average == False: baseline = raw_input("Which well had the baseline? ") for i in xrange(0,len(self.names)): if baseline == self.names[i]: baseline_number = i else: pass elif self.dic != None and average == False: for index, name in enumerate(self.names): if name.lower() == 'baseline': baseline_number = index new_names = self.names new_names.pop(baseline_number) baseline_list = self.y_data[baseline_number] data = self.y_data y_data_baseline = [] elif self.dic != None and average == True: for index, name in enumerate(self.unique_names): if name.lower() == 'baseline': baseline_number = index new_names = self.unique_names new_names.pop(baseline_number) baseline_list = self.averages[baseline_number] data = self.averages y_data_baseline = [] for i in xrange(0,len(data)): y_dat = data[i] if i == baseline_number: pass else: for j in xrange(0,len(y_dat)): y_dat[j] = y_dat[j] - baseline_list[j] y_data_baseline.append(y_dat) y_data_normalized = [] for i in xrange(0,len(y_data_baseline)): y_dat = y_data_baseline[i] normalizer = y_dat[0] for j in xrange(0,len(y_dat)): y_dat[j] = y_dat[j] - normalizer y_data_normalized.append(y_dat) no_correct = Graphs(title=self.title,xlabel="Time in Seconds",ylabel="Absorbance",y_names=new_names) fig, ax = no_correct.basic_plot(x_data=self.x_data,y_data=y_data_normalized) plt.show()
def graph_diff(id): if id == 0: data = DataProcessing().total_cases_per_day() df = DataProcessing().get_dateframe_diff(data=data) Graphs().get_graph(dataframe=df, country_id=0, write=True, diff=True) return render_template("./graphs/world-diff.html") data = DataProcessing().all_cases_per_day_where_country_id_equal( country_id=id) df = DataProcessing().get_dateframe_diff(data=data) get_graph = Graphs().get_graph(dataframe=df, country_id=id, write=True, diff=True) return render_template("./graphs/" + get_graph[1] + ".html")
def main(): try: # Initialization args = handle_args() init_logging(args) # Getting data from external resources balances = [] for s in args.sources: src = source_classes[s]() balance = src.get_balance() balances.append((s, balance)) logging.info(u'%s: %s', s, balance) # Write received data (and only if all sources returned data successfully) now_str = time.strftime(u'%d.%m.%Y %H:%M') for source, balance in balances: log_fname = u'logs/%s.log' % source with open(log_fname, u'a') as f: f.write(u'%s, %.2f\n' % (now_str, balance.value)) logging.info(u'Updated file %s' % log_fname) # Generate html file with fancy graphs Graphs().generate_html() except Exception as e: # We want to notify user that error happened write_exception(e) raise
def display_page(pathname): if pathname == '/Plots/state_county_confirmed_line_chart': return state_county_confirmed_line_chart.get_layout() elif pathname == '/Plots/daily_changes_bar_chart': return daily_changes_bar_chart.get_layout() elif pathname == '/Plots/us_cases': return us_cases.get_layout() elif pathname == '/Plots/us_deaths': return us_deaths.get_layout() elif pathname == '/Plots/state_county_death_line_chart': return state_county_death_line_chart.get_layout() elif pathname == '/graphs': return Graphs() else: return Homepage()
def eliminateWarmUpCustomer(self, vector_data): """iterate over the vector and compare the average in order to check for the steady state samples""" temp_vector = [] rk = [] # mean computation for the customers in the queue customer_avg = CustomerAverage(vector_data[0][0]) for data in vector_data: customer_avg.update(data[0], data[1]) x = customer_avg.mean(vector_data[-1][0]) while self.k < len(vector_data) / 100: temp_vector = vector_data[self.k * 15:] # mean computation for the customers in the queue customer_avg = CustomerAverage(temp_vector[0][0]) for data in temp_vector: customer_avg.update(data[0], data[1]) customer_mean = customer_avg.mean(list(temp_vector)[-1][0]) rk.append(((customer_mean - x) / x)) # DEBUG print str(((customer_mean - x) / x)) + " -- " + str( len(temp_vector)) + "/" + str(len(vector_data)) + "\n" print "\n" + str(self.k) + "/" + str(len(vector_data) / 100) self.previous_mean = customer_mean self.k += 1 Graphs.showRk(rk) time = [] cust = [] for element in vector_data: time.append(element[0]) cust.append(element[1]) Graphs.customerQueueView(time, cust, "cust", "customer in queue") Graphs.show() return temp_vector
def __init__(self, graphs: Graphs, feature_pairs, split=1): self._interval = int(graphs.number_of_graphs() / split) self._all_features = [] for graph in graphs.graph_names(): m = graphs.features_matrix(graph) # self._nodes_for_graph.append(m.shape[0]) # append graph features self._all_features.append(m) # append 0.001 for all missing nodes self._all_features.append(np.ones((graphs.nodes_for_graph(graphs.name_to_index(graph)) - m.shape[0], m.shape[1])) * 0.001) # create one big matrix of everything - rows: nodes, columns: features self._all_features = np.concatenate(self._all_features) # all_ftr_graph_index - [ .... last_row_index_for_graph_i ... ] self._all_ftr_graph_index = np.cumsum([0] + graphs.nodes_count_list()).tolist() super(LinearContext, self).__init__(graphs, feature_pairs)
def display_page(pathname): if pathname == '/Plots/state_county_confirmed_line_chart': return state_county_confirmed_line_chart.get_layout() elif pathname == '/Plots/daily_changes_bar_chart': return daily_changes_bar_chart.get_layout() elif pathname == '/Plots/us_cases': return us_cases.get_layout() elif pathname == '/Plots/us_deaths': return us_deaths.get_layout() elif pathname == '/Plots/state_county_death_line_chart': return state_county_death_line_chart.get_layout() elif pathname == '/Plots/stocks': return stocks.get_layout() elif pathname == '/info/about': return about.get_layout() elif pathname == '/info/what_to_do': return what_to_do.get_layout() elif pathname == '/effects': return Effects() elif pathname == '/graphs': return Graphs() else: return Homepage()
def eliminateWarmUpResponseTime(self, vector_data): """iterate over the vector and compare the average in order to check for the steady state samples""" temp_vector = [] rk = [] x = numpy.mean(vector_data) while self.k <= len(vector_data) / 100: temp_vector = vector_data[self.k * 15:] temp_mean = numpy.mean(temp_vector) rk.append((temp_mean - x) / x) self.previous_mean = temp_mean self.k += 1 Graphs.showRk(rk) Graphs.responseTimeShow(vector_data, x) Graphs.show() return temp_vector
def join_two_graphs(first_id, second_id): get_graphs = Graphs().join_two_graphs(first_country_id=first_id, second_country_id=second_id) return render_template("./graphs/" + get_graphs[1] + ".html")
# contains all errors as key:(title,msg) items. # will be used throughout the runtime to track all encountered errors errors = {} # will contain the latest data last_update = None config = make_config(config) logger = make_logger('app', config) logger.debug('app starting') backend = Backend(config, logger) s_metrics = structured_metrics.StructuredMetrics(config, logger) graphs_manager = Graphs() graphs_manager.load_plugins() graphs_all = graphs_manager.list_graphs() bottle.TEMPLATE_PATH.insert(0, os.path.dirname(__file__)) @route('<path:re:/assets/.*>') @route('<path:re:/timeserieswidget/.*(js|css)>') @route('<path:re:/timeserieswidget/timezone-js/src/.*js>') @route('<path:re:/timeserieswidget/tz/.*>') @route('<path:re:/DataTables/media/js/.*js>') @route('<path:re:/DataTablesPlugins/integration/bootstrap/.*(js|css)>') def static(path): return static_file(path, root=os.path.dirname(__file__))
from graphs import Graphs from helper import Data import pandas as pd pred_path = "data/" models = ['ARIMA', 'XGBoost', 'LSTM'] import dash_core_components as dcc import dash_html_components as html import dash_bootstrap_components as dbc import dash from dash.dependencies import Input, Output data = Data() graph = Graphs() data.fetch_data() preprocessed_df = data.preprocess_cases_data(data.df_us_cases) app = dash.Dash(__name__, external_stylesheets=[dbc.themes.LUX]) server = app.server navbar = dbc.Nav( className="nav nav-pills", children=[ dbc.NavItem( dbc.NavLink([html.I(className="fa fa-github"), " GitHub"], href="https://github.com/sheelshah9", active=True, target="_blank")), dbc.NavItem(
for lambda_arr in lambda_arr_values: sim = SimulationAdvancedUsingBatches(lambda_arr, MU_SERVICE, SERVICE_NUMB, CONFIDENCE_INTERVAL, MIN_NUMB_BATCHES, SIZE, A, B, warm_up=True) sim.runSim() temp = sim.returnValuesSimulation() # saving the data in separate lists means_resp.append(temp["mean_resp"]) means_custom.append(temp["mean_custom"]) means_dropped.append(temp["mean_dropped"]) upper_interval_resp.append(temp["interval_resp"][1]) lower_interval_resp.append(temp["interval_resp"][0]) upper_interval_custom.append(temp["interval_custom"][1]) lower_interval_custom.append(temp["interval_custom"][0]) upper_interval_dropped.append(temp["interval_dropped"][1]) lower_interval_dropped.append(temp["interval_dropped"][0]) print str(temp) + "\n" print str(time_debug) + "/" + str(len(lambda_arr_values)) + "\n" time_debug = time_debug + 1 pyplot.close() Graphs.meanAndConfidenceInterval(roh, means_resp, lower_interval_resp, upper_interval_resp, "Average Response Time", "Packet Response Time") Graphs.meanAndConfidenceInterval(roh, means_custom, lower_interval_custom, upper_interval_custom, "Average Customers", "Customer Buffer Occupancy") Graphs.meanAndConfidenceInterval(roh, means_dropped, lower_interval_dropped, upper_interval_dropped, "Average Packet Dropped", "Packer Dropped") pyplot.show()
logger = logging.getLogger('app') logger.setLevel(logging.DEBUG) chandler = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') chandler.setFormatter(formatter) logger.addHandler(chandler) if config.log_file: fhandler = logging.FileHandler(config.log_file) fhandler.setFormatter(formatter) logger.addHandler(fhandler) logger.debug('app starting') backend = Backend(config) s_metrics = structured_metrics.StructuredMetrics(config) graphs = Graphs() graphs.load_plugins() graphs_all = graphs.list_graphs() @route('<path:re:/assets/.*>') @route('<path:re:/timeserieswidget/.*js>') @route('<path:re:/timeserieswidget/.*css>') @route('<path:re:/timeserieswidget/timezone-js/src/.*js>') @route('<path:re:/timeserieswidget/tz/.*>') @route('<path:re:/DataTables/media/js/.*js>') @route('<path:re:/DataTablesPlugins/integration/bootstrap/.*js>') @route('<path:re:/DataTablesPlugins/integration/bootstrap/.*css>') def static(path): return static_file(path, root='.')
class Aplicacion(): #Inicialización def __init__(self): self.window = Tk() self.window.protocol("WM_DELETE_WINDOW", self.finishApp) self.window.title('Herramienta de prueba para la predicción') ico = PhotoImage(file=os.path.abspath('.') + '/Activos/term.png') self.window.call('wm', 'iconphoto', self.window._w, ico) self.window.config(bg=mainColor) self.window.attributes("-zoomed", False) self.window.minsize(width=300, height=300) #Peso 100% en self.window self.window.grid_rowconfigure(0, weight=1) self.window.grid_columnconfigure(0, weight=1) #Ventana principal fija sin ajuste de tamaño self.window.resizable(False, False) #Centrar ventana en función de las dimendsiones del contenedor de inicio self.center(450, 490) self.view = Window(self.window) self.functions = Functions() self.infoW = Info(self.view.dataContainer) self.genDataW = GenData(self.view.dataContainer) self.predW = Predictions(self.view.dataContainer) self.graphsW = Graphs(self.view.dataContainer) #Botones de las acciones del usuario self.view.buttonDisconnect.bind("<Button>", self.disconnect) self.view.buttonToBD.bind("<Button>", self.changeToConnect) self.view.buttonConnect.bind("<Button>", self.checkConnection) self.view.infoButton.bind( "<Button>", lambda event: self.switchSelector( self.view.predButton, self.view.graphButton, self.view. genDataButton, self.view.infoButton, 1)) self.view.genDataButton.bind( "<Button>", lambda event: self.switchSelector( self.view.infoButton, self.view.predButton, self.view. graphButton, self.view.genDataButton, 2)) self.view.predButton.bind( "<Button>", lambda event: self.switchSelector( self.view.infoButton, self.view.graphButton, self.view. genDataButton, self.view.predButton, 3)) self.view.graphButton.bind( "<Button>", lambda event: self.switchSelector( self.view.infoButton, self.view.genDataButton, self.view. predButton, self.view.graphButton, 4)) self.genDataW.buttonFilterData.bind("<Button>", lambda event: self.getNewGenData()) self.graphsW.buttonGetGraph.bind("<Button>", lambda event: self.getGraphsData()) self.predW.buttonForecast.bind("<Button>", self.getForecast) self.predW.butHistForecast.bind("<Button>", self.getHistForecast) #Ventana principal actualizaciones self.window.mainloop() #Centra la ventana def center(self, width, height): w = self.window.winfo_screenwidth() h = self.window.winfo_screenheight() x = int((w - width) / 2) y = int((h - height) / 2) self.window.geometry('+{}+{}'.format(x, y)) #Función para comprobar a conexión con la base de datos con los parametros introducidos def checkConnection(self, event): global connectionData connectionData['hostDir'] = self.view.dir.get() connectionData['serverUser'] = self.view.user.get() connectionData['userPassword'] = self.view.password.get() connectionData['port'] = self.view.portEntry.get() connectionData['databaseName'] = self.view.dataB.get() if (connectionData['hostDir'] == None or connectionData['hostDir'] == ''): resultConnection = 'Debe indicar la dirección del servidor' elif (connectionData['serverUser'] == None or connectionData['serverUser'] == ''): resultConnection = 'Debe introducir un usuario' elif (connectionData['userPassword'] == None): resultConnection = 'Debe introducir una contraseña' elif (connectionData['port'] == None or connectionData['port'] == ''): resultConnection = 'Debe indicar el puerto de conexión' elif (connectionData['databaseName'] == None or connectionData['databaseName'] == ''): resultConnection = 'Debe indicar la base de datos a usar' else: global bd bd = BD(connectionData) resultConnection = bd.connect() self.view.setConnectionResult(self.window, resultConnection) if (resultConnection == True): #Se obtienen los nombres de las tablas a mostrar estData = bd.getTableNames(connectionData['databaseName']) #Se olvida el frame de conexion self.view.firstContainer.grid_forget() #Ventana principal fija sin ajuste de tamaño self.window.resizable(True, True) #Se establece el frame princial y sus widgets self.view.mainView(self.window) self.genDataW.complete(estData) self.predW.complete(estData) self.graphsW.complete(estData) self.getNewGenData() self.getGraphsData() self.genDataW.hideGenData() self.predW.hidePredictions() self.graphsW.hideGraphs() self.infoW.showInfo() #Pasar a la vista de conexxion def changeToConnect(self, event): #Olvidar el grid de start container y eliminarlo self.view.startContainer.grid_forget() self.view.startContainer.destroy() self.view.firstContainer.grid(row=0, column=0) #Función para elegir pestaña en la ventana principal def switchSelector(self, button1, button2, button3, button4, number): if (number == 1): self.genDataW.hideGenData() self.predW.hidePredictions() self.graphsW.hideGraphs() self.infoW.showInfo() elif (number == 2): self.infoW.hideInfo() self.predW.hidePredictions() self.graphsW.hideGraphs() self.genDataW.showGenData() elif (number == 3): self.infoW.hideInfo() self.genDataW.hideGenData() self.graphsW.hideGraphs() self.predW.showPredictions() else: self.infoW.hideInfo() self.genDataW.hideGenData() self.predW.hidePredictions() self.graphsW.showGraphs() button1.config(bg=mainColor, activebackground=thirdColor) button2.config(bg=mainColor, activebackground=thirdColor) button3.config(bg=mainColor, activebackground=thirdColor) button4.config(bg=secondaryColor, activebackground=secondaryColor) #Filtra los datos que se tienen que mostrar en la pestaña de datos generales def getNewGenData(self): self.genDataW.textResult.set('') if (self.genDataW.desdeE.get() != '' and self.genDataW.hastaE.get() != ''): try: d = datetime(int(self.genDataW.desdeE.get()[0:4]), int(self.genDataW.desdeE.get()[5:7]), int(self.genDataW.desdeE.get()[8:10])) h = datetime(int(self.genDataW.hastaE.get()[0:4]), int(self.genDataW.hastaE.get()[5:7]), int(self.genDataW.hastaE.get()[8:10]), 23, 00, 00) if (d <= h): result = 1 result = self.functions.getGenData(bd, d, h) else: self.genDataW.textResult.set( 'La primera fecha debe ser menor que la segunda') return except: self.genDataW.textResult.set( 'El formato de las fechas es incorrecto') return elif (self.genDataW.desdeE.get() == '' and self.genDataW.hastaE.get() != ''): try: h = datetime(int(self.genDataW.hastaE.get()[0:4]), int(self.genDataW.hastaE.get()[5:7]), int(self.genDataW.hastaE.get()[8:10]), 23, 00, 00) result = self.functions.getGenData(bd, self.genDataW.desdeE.get(), h) except: self.genDataW.textResult.set( 'El formato de las fechas es incorrecto') return elif (self.genDataW.desdeE.get() != '' and self.genDataW.hastaE.get() == ''): try: d = datetime(int(self.genDataW.desdeE.get()[0:4]), int(self.genDataW.desdeE.get()[5:7]), int(self.genDataW.desdeE.get()[8:10])) result = self.functions.getGenData(bd, d, self.genDataW.hastaE.get()) except: self.genDataW.textResult.set( 'El formato de las fechas es incorrecto') return else: result = self.functions.getGenData(bd, self.genDataW.desdeE.get(), self.genDataW.hastaE.get()) if (result == None): self.genDataW.textResult.set( 'No hay datos para las fechas seleccionadas') else: self.genDataW.start.set(result[1]) self.genDataW.finish.set(result[2]) self.genDataW.changeTableValues(result[0]) #Filtra los datos de los gráficos def getGraphsData(self): self.graphsW.textGraphResult.set('') estacion = self.graphsW.localization.get() meteoData = self.graphsW.atr.get() if (estacion == ''): self.graphsW.textGraphResult.set('Debe elegir una localización') elif (meteoData == ''): self.graphsW.textGraphResult.set('Debe elegir una variable') else: if (self.graphsW.dgEntry.get() != '' and self.graphsW.hgEntry.get() != ''): try: d = datetime(int(self.graphsW.dgEntry.get()[0:4]), int(self.graphsW.dgEntry.get()[5:7]), int(self.graphsW.dgEntry.get()[8:10])) h = datetime(int(self.graphsW.hgEntry.get()[0:4]), int(self.graphsW.hgEntry.get()[5:7]), int(self.graphsW.hgEntry.get()[8:10]), 23, 00, 00) if (d <= h): result = 1 result = bd.selectFromTable(estacion, d, h) else: self.graphsW.textGraphResult.set( 'La primera fecha debe ser menor que la segunda') return except: self.graphsW.textGraphResult.set( 'El formato de las fechas es incorrecto') return elif (self.graphsW.dgEntry.get() == '' and self.graphsW.hgEntry.get() != ''): try: h = datetime(int(self.graphsW.hgEntry.get()[0:4]), int(self.graphsW.hgEntry.get()[5:7]), int(self.graphsW.hgEntry.get()[8:10]), 23, 00, 00) result = bd.selectFromTable(estacion, self.graphsW.dgEntry.get(), h) except: self.graphsW.textGraphResult.set( 'El formato de las fechas es incorrecto') return elif (self.graphsW.dgEntry.get() != '' and self.graphsW.hgEntry.get() == ''): try: d = datetime(int(self.graphsW.dgEntry.get()[0:4]), int(self.graphsW.dgEntry.get()[5:7]), int(self.graphsW.dgEntry.get()[8:10])) result = bd.selectFromTable(estacion, d, self.graphsW.hgEntry.get()) except: self.graphsW.textGraphResult.set( 'El formato de las fechas es incorrecto') return else: result = bd.selectFromTable(estacion, self.graphsW.dgEntry.get(), self.graphsW.hgEntry.get()) if (len(result) == 0): self.graphsW.textGraphResult.set( 'No hay datos para las fechas seleccionadas') else: figure = self.functions.graphData( self.graphsW.localization.get(), self.graphsW.atr.get(), result) self.graphsW.newGraph(figure) #Función al pulsar el botón de predecir def getForecast(self, event): self.predW.butHistForecast.grid_forget() self.predW.resultPredContainer.grid_columnconfigure(2, weight=0) self.predW.predErr.set('') self.predW.predResult.set('') self.predW.textForecast.set('') atr = [] vars = [] if (self.predW.loc.get() == 'None'): self.predW.predErr.set( 'Debe seleccionar una localización para poder completar la predicción' ) return elif (self.predW.t.get() == 0 and self.predW.w.get() == 0 and self.predW.p.get() == 0 and self.predW.h.get() == 0 and self.predW.d.get() == 0): self.predW.predErr.set( 'Debe seleccionar al menos una variable para poder completar la predicción' ) return elif (self.predW.mod.get() == 'None'): self.predW.predErr.set( 'Debe seleccionar una modelo de predicción para poder completar la predicción' ) return else: if (self.predW.t.get() == 1): atr.append('temperatura') if (self.predW.w.get() == 1): atr.append('viento') if (self.predW.d.get() == 1): atr.append('direccion') if (self.predW.p.get() == 1): atr.append('presion') if (self.predW.h.get() == 1): atr.append('humedad') if (self.predW.mod.get() == 'K-NN'): vars.append(self.predW.neighbors.get()) elif (self.predW.mod.get() == 'Red neuronal'): vars.append(self.predW.layers.get()) vars.append(self.predW.neurons1.get()) vars.append(self.predW.neurons2.get()) vars.append(self.predW.neurons3.get()) vars.append(self.predW.itersRedNeu.get()) vars.append(self.predW.learnRate.get()) elif (self.predW.mod.get() == 'Árbol de decisión'): if (self.predW.maxDepth.get() != 0): vars.append(self.predW.maxDepth.get()) else: vars.append(None) else: None res = bd.selectDataForecast( self.predW.loc.get(), self.predW.iter.get() + int(self.predW.dayRef.get()), False) result = self.functions.valoresTempMaximas(res) pred = self.functions.dataForecast(result, self.predW.mod.get(), atr, vars, int(self.predW.dayRef.get()), self.predW.iter.get()) self.predW.showPrediction(pred) #Mostrar gráfico con historico de predicciones def getHistForecast(self, event): self.predW.predErr.set('') atr = [] vars = [] if (self.predW.loc.get() == 'None'): self.predW.predErr.set( 'Debe seleccionar una localización para poder completar la predicción' ) return elif (self.predW.t.get() == 0 and self.predW.w.get() == 0 and self.predW.p.get() == 0 and self.predW.h.get() == 0 and self.predW.d.get() == 0): self.predW.predErr.set( 'Debe seleccionar al menos una variable para poder completar la predicción' ) return elif (self.predW.mod.get() == 'None'): self.predW.predErr.set( 'Debe seleccionar una modelo de predicción para poder completar la predicción' ) return else: if (self.predW.t.get() == 1): atr.append('temperatura') if (self.predW.w.get() == 1): atr.append('viento') if (self.predW.d.get() == 1): atr.append('direccion') if (self.predW.p.get() == 1): atr.append('presion') if (self.predW.h.get() == 1): atr.append('humedad') if (self.predW.mod.get() == 'K-NN'): vars.append(self.predW.neighbors.get()) elif (self.predW.mod.get() == 'Red neuronal'): vars.append(self.predW.layers.get()) vars.append(self.predW.neurons1.get()) vars.append(self.predW.neurons2.get()) vars.append(self.predW.neurons3.get()) vars.append(self.predW.itersRedNeu.get()) vars.append(self.predW.learnRate.get()) elif (self.predW.mod.get() == 'Árbol de decisión'): if (self.predW.maxDepth.get() != 0): vars.append(self.predW.maxDepth.get()) else: vars.append(None) else: None res = bd.selectDataForecast( self.predW.loc.get(), self.predW.iter.get() + int(self.predW.dayRef.get()), True) result = self.functions.valoresTempMaximas(res) figure = self.functions.AllForecast(result, self.predW.mod.get(), atr, vars, int(self.predW.dayRef.get()), self.predW.iter.get()) self.predW.showHist(figure) #Función para descconectar de la base de datos def disconnect(self, event): global bd self.view.execute = False try: bd.close() except: None #Olvidar self.mainContainer self.view.mainContainer.grid_forget() #Atributos de la ventana self.window.attributes("-zoomed", False) self.window.geometry('450x490') self.center(450, 490) self.window.resizable(False, False) #Cargar connection container self.view.firstContainer.grid(row=0, column=0) self.view.connectionView(self.window) def finishApp(self): global bd self.view.execute = False try: bd.close() except: None try: self.view.t1.join(0) self.view.t2.join(1) except: None sys.exit(0)
def main(): network_file = "network_default.txt" initial_weights_file = None args = sys.argv[1:] if len(args) is 3: network_file = args[0] initial_weights_file = args[1] dataset_file = args[2] else: print( "Selecione seu dataset: \n 1 - Ionosphere \n 2 - Pima \n 3 - Wdbc \n 4 - Wine \n 5 - Teste \n 6 - Galaxy " ) escolha = int(input("Escolha: ")) if escolha is 1: dataset_file = "./datasets/ionosphere.csv" elif escolha is 2: dataset_file = "./datasets/pima.csv" elif escolha is 3: dataset_file = "./datasets/wdbc.csv" elif escolha is 4: dataset_file = "./datasets/wine.csv" elif escolha is 5: dataset_file = "./datasets/teste2.csv" elif escolha is 6: dataset_file = "./datasets/galaxy1.csv" else: print("Escolha invalida") exit() camadas = [] fator_regularizacao = None with open(network_file) as network: info_camadas = csv.reader(network, delimiter=",", quoting=csv.QUOTE_NONE) for index, row in enumerate(info_camadas): if index is 0: fator_regularizacao = float(row[0]) else: camadas.append(int(row[0])) dataset = DataHandler(dataset_file) entradas = len(dataset.data[0]) nn = NeuralNetwork(entradas, camadas, initial_weights_file, fator_regularizacao) custo = nn.calcula_custos(dataset.data, dataset.results) if len(args) is 3: print("FATOR DE REGULARIZACAO: ", fator_regularizacao) print("PESOS INICIAIS:") nn.print_matrizes() for index_data, data in enumerate(dataset.data): print("ENTRADA: ", data) print("SAIDAS:") ativacao_matriz = nn.calcula_saidas(data) printMatriz(ativacao_matriz) deltas = nn.calcula_deltas(ativacao_matriz, dataset.results[index_data]) gradiente_bias = deltas gradiente_pesos = nn.calcula_gradientes(data, ativacao_matriz, deltas) print("GRADIENTES DOS BIAS PARA ENTRADA:") printMatriz(gradiente_bias) print("GRADIENTES DOS PESOS PARA ENTRADA:") printMatriz(gradiente_pesos) nn.atuliza_matriz_gradientes(gradiente_bias, gradiente_pesos) print( "\n \n =================== FIM TREINAMENTO ==================== \n" ) nn.calcula_gradientes_total_regularizados(index_data + 1) print("GRADIENTES BIAS FINAIS DO DATASET:") printMatriz(nn.gradientes_bias) print("GRADIENTES PESOS FINAIS DO DATASET:") printMatriz(nn.gradientes) nn.atualiza_pesos(alpha) print("NOVOS PESSO:") nn.print_matrizes() custo = nn.calcula_custos(dataset.data, dataset.results) print("Custo total: ", custo) else: dataset.normalizeData() batches_dados, batches_resultados = dataset.generate_batches( num_batches) saida_da_rede = [] i = 0 custos = [] epocas = 0 while custo > 0.01: print(custo) for index_batch, batch_dados in enumerate(batches_dados): for index_entrada, entrada in enumerate(batch_dados): nn.treina_rede( entrada, batches_resultados[index_batch][index_entrada]) nn.calcula_gradientes_total_regularizados(index_entrada + 1) nn.atualiza_pesos(alpha) epocas += 1 nn.gradientes = None nn.gradientes_bias = None custo = nn.calcula_custos(dataset.data, dataset.results) custos.append(custo) i = i + 1 if i == 500: print(custo) i = 0 saida_da_rede = [] for index, data in enumerate(dataset.data): saida_da_rede.append(nn.calcula_saidas(data)[-1]) g = Graphs() g.classificacao(dataset.results, saida_da_rede, epocas, enfase_f1_score=1, custo=custo, custos=custos) nn.print_matrizes() for index, data in enumerate(dataset.data): saida_da_rede.append(nn.calcula_saidas(data)[-1]) g = Graphs() g.classificacao(dataset.results, saida_da_rede, epocas, enfase_f1_score=1, custo=custo, custos=custos)
def plot_cases(state, method): data = pd.read_csv(pred_path + "death_{}_{}.csv".format(state, method), index_col=0) data = data.cumsum() return Graphs.draw_graph(data, row=state)
def __init__(self, main_gui): self.main_gui = main_gui widget_label_font = tk_font.Font(family="Tw Cen MT", size=self.main_gui.label_font_small) widget_title_font = tk_font.Font(family="Tw Cen MT", size=self.main_gui.label_font, weight="bold") graph_frame = tk.LabelFrame(self.main_gui.window, text="GRAPHS", fg="#323338", bg='#f2f3fc', font=widget_title_font, relief=tk.RIDGE) graph_frame.grid(row=0, column=3, sticky=tk.N, rowspan=15, padx=(self.main_gui.padx, 0)) self.graph1 = tk.LabelFrame(graph_frame, fg="#323338", bg='#f2f3fc', font=widget_title_font, relief=tk.RIDGE) self.graph1.grid(row=0, column=0, sticky=tk.N, rowspan=4) self.graph1_plot = Graphs(self.graph1, self.main_gui.program, self.main_gui.fig_a, self.main_gui.fig_b) self.graph1_variable = tk.IntVar() self.graph1_XYY_radiobutton = tk.Radiobutton( self.graph1, text="XYY", bg='#f2f3fc', fg="#323338", command=self.graph1_plot_draw, variable=self.graph1_variable, value=0, font=widget_label_font) self.graph1_Smith_radiobutton = tk.Radiobutton( self.graph1, text="Smith", bg='#f2f3fc', fg="#323338", command=self.graph1_plot_draw, variable=self.graph1_variable, value=1, font=widget_label_font) self.graph1_XYY_radiobutton.grid(row=3, column=0, padx=(self.main_gui.fig_padx, 0), sticky=tk.N + tk.W) self.graph1_Smith_radiobutton.grid(row=4, column=0, padx=(self.main_gui.fig_padx, 0), sticky=tk.N + tk.W) self.graph1_s_variable = tk.IntVar() self.graph1_S11_radiobutton = tk.Radiobutton( self.graph1, text="S11", bg='#f2f3fc', fg="#323338", command=self.graph1_plot_draw, variable=self.graph1_s_variable, value=0, font=widget_label_font) self.graph1_S11_radiobutton.select() self.graph1_S12_radiobutton = tk.Radiobutton( self.graph1, text="S12", bg='#f2f3fc', fg="#323338", command=self.graph1_plot_draw, variable=self.graph1_s_variable, value=1, font=widget_label_font) self.graph1_S21_radiobutton = tk.Radiobutton( self.graph1, text="S21", bg='#f2f3fc', fg="#323338", command=self.graph1_plot_draw, variable=self.graph1_s_variable, value=2, font=widget_label_font) self.graph1_S22_radiobutton = tk.Radiobutton( self.graph1, text="S22", bg='#f2f3fc', fg="#323338", command=self.graph1_plot_draw, variable=self.graph1_s_variable, value=3, font=widget_label_font) self.graph1_s_variable.set(0) self.graph1_S11_radiobutton.grid(row=3, column=0, padx=(10, 0), sticky=tk.N + tk.W) self.graph1_S12_radiobutton.grid(row=3, column=0, padx=(70, 0), sticky=tk.N + tk.W) self.graph1_S21_radiobutton.grid(row=4, column=0, padx=(10, 0), pady=(0, 0), sticky=tk.N + tk.W) self.graph1_S22_radiobutton.grid(row=4, column=0, padx=(70, 0), pady=(0, 0), sticky=tk.N + tk.W) self.graph2 = tk.LabelFrame(graph_frame, fg="#323338", bg='#f2f3fc', font=widget_title_font, relief=tk.RIDGE) self.graph2.grid(row=0, column=1, sticky=tk.N, rowspan=5) self.graph2_plot = Graphs(self.graph2, self.main_gui.program, self.main_gui.fig_a, self.main_gui.fig_b) self.graph2_variable = tk.IntVar() self.graph2_XYY_radiobutton = tk.Radiobutton( self.graph2, text="XYY", bg='#f2f3fc', fg="#323338", command=self.graph2_plot_draw, variable=self.graph2_variable, value=0, font=widget_label_font) self.graph2_Smith_radiobutton = tk.Radiobutton( self.graph2, text="Smith", bg='#f2f3fc', fg="#323338", command=self.graph2_plot_draw, variable=self.graph2_variable, value=1, font=widget_label_font) self.graph2_XYY_radiobutton.grid(row=3, column=0, padx=(self.main_gui.fig_padx, 0), sticky=tk.N + tk.W) self.graph2_Smith_radiobutton.grid(row=4, column=0, padx=(self.main_gui.fig_padx, 0), sticky=tk.N + tk.W) self.graph2_s_variable = tk.IntVar() self.graph2_S11_radiobutton = tk.Radiobutton( self.graph2, text="S11", bg='#f2f3fc', fg="#323338", command=self.graph2_plot_draw, variable=self.graph2_s_variable, value=0, font=widget_label_font) self.graph2_S12_radiobutton = tk.Radiobutton( self.graph2, text="S12", bg='#f2f3fc', fg="#323338", command=self.graph2_plot_draw, variable=self.graph2_s_variable, value=1, font=widget_label_font) self.graph2_S12_radiobutton.select() self.graph2_S21_radiobutton = tk.Radiobutton( self.graph2, text="S21", bg='#f2f3fc', fg="#323338", command=self.graph2_plot_draw, variable=self.graph2_s_variable, value=2, font=widget_label_font) self.graph2_S22_radiobutton = tk.Radiobutton( self.graph2, text="S22", bg='#f2f3fc', fg="#323338", command=self.graph2_plot_draw, variable=self.graph2_s_variable, value=3, font=widget_label_font) self.graph2_S11_radiobutton.grid(row=3, column=0, padx=(10, 0), sticky=tk.N + tk.W) self.graph2_S12_radiobutton.grid(row=3, column=0, padx=(70, 0), sticky=tk.N + tk.W) self.graph2_S21_radiobutton.grid(row=4, column=0, padx=(10, 0), pady=(0, 0), sticky=tk.N + tk.W) self.graph2_S22_radiobutton.grid(row=4, column=0, padx=(70, 0), pady=(0, 0), sticky=tk.N + tk.W) self.graph3 = tk.LabelFrame(graph_frame, fg="#323338", bg='#f2f3fc', font=widget_title_font, relief=tk.RIDGE) self.graph3.grid(row=5, column=0, sticky=tk.N, rowspan=5) self.graph3_plot = Graphs(self.graph3, self.main_gui.program, self.main_gui.fig_a, self.main_gui.fig_b) self.graph3_variable = tk.IntVar() self.graph3_XYY_radiobutton = tk.Radiobutton( self.graph3, text="XYY", bg='#f2f3fc', fg="#323338", command=self.graph3_plot_draw, variable=self.graph3_variable, value=0, font=widget_label_font) self.graph3_Smith_radiobutton = tk.Radiobutton( self.graph3, text="Smith", bg='#f2f3fc', fg="#323338", command=self.graph3_plot_draw, variable=self.graph3_variable, value=1, font=widget_label_font) self.graph3_XYY_radiobutton.grid(row=8, column=0, padx=(self.main_gui.fig_padx, 0), sticky=tk.N + tk.W) self.graph3_Smith_radiobutton.grid(row=9, column=0, padx=(self.main_gui.fig_padx, 0), sticky=tk.N + tk.W) self.graph3_s_variable = tk.IntVar() self.graph3_S11_radiobutton = tk.Radiobutton( self.graph3, text="S11", bg='#f2f3fc', fg="#323338", command=self.graph3_plot_draw, variable=self.graph3_s_variable, value=0, font=widget_label_font) self.graph3_S12_radiobutton = tk.Radiobutton( self.graph3, text="S12", bg='#f2f3fc', fg="#323338", command=self.graph3_plot_draw, variable=self.graph3_s_variable, value=1, font=widget_label_font) self.graph3_S21_radiobutton = tk.Radiobutton( self.graph3, text="S21", bg='#f2f3fc', fg="#323338", command=self.graph3_plot_draw, variable=self.graph3_s_variable, value=2, font=widget_label_font) self.graph3_S21_radiobutton.select() self.graph3_S22_radiobutton = tk.Radiobutton( self.graph3, text="S22", bg='#f2f3fc', fg="#323338", command=self.graph3_plot_draw, variable=self.graph3_s_variable, value=3, font=widget_label_font) self.graph3_S11_radiobutton.grid(row=8, column=0, padx=(10, 0), sticky=tk.N + tk.W) self.graph3_S12_radiobutton.grid(row=8, column=0, padx=(70, 0), sticky=tk.N + tk.W) self.graph3_S21_radiobutton.grid(row=9, column=0, padx=(10, 0), pady=(0, 0), sticky=tk.N + tk.W) self.graph3_S22_radiobutton.grid(row=9, column=0, padx=(70, 0), pady=(0, 0), sticky=tk.N + tk.W) self.graph4 = tk.LabelFrame(graph_frame, fg="#323338", bg='#f2f3fc', font=widget_title_font, relief=tk.RIDGE) self.graph4.grid(row=6, column=1, sticky=tk.N, rowspan=5) self.graph4_plot = Graphs(self.graph4, self.main_gui.program, self.main_gui.fig_a, self.main_gui.fig_b) self.graph4_variable = tk.IntVar() self.graph4_XYY_radiobutton = tk.Radiobutton( self.graph4, text="XYY", bg='#f2f3fc', fg="#323338", command=self.graph4_plot_draw, variable=self.graph4_variable, value=0, font=widget_label_font) self.graph4_Smith_radiobutton = tk.Radiobutton( self.graph4, text="Smith", bg='#f2f3fc', fg="#323338", command=self.graph4_plot_draw, variable=self.graph4_variable, value=1, font=widget_label_font) self.graph4_XYY_radiobutton.grid(row=8, column=0, padx=(self.main_gui.fig_padx, 0), sticky=tk.N + tk.W) self.graph4_Smith_radiobutton.grid(row=9, column=0, padx=(self.main_gui.fig_padx, 0), sticky=tk.N + tk.W) self.graph4_s_variable = tk.IntVar() self.graph4_S11_radiobutton = tk.Radiobutton( self.graph4, text="S11", bg='#f2f3fc', fg="#323338", command=self.graph4_plot_draw, variable=self.graph4_s_variable, value=0, font=widget_label_font) self.graph4_S12_radiobutton = tk.Radiobutton( self.graph4, text="S12", bg='#f2f3fc', fg="#323338", command=self.graph4_plot_draw, variable=self.graph4_s_variable, value=1, font=widget_label_font) self.graph4_S21_radiobutton = tk.Radiobutton( self.graph4, text="S21", bg='#f2f3fc', fg="#323338", command=self.graph4_plot_draw, variable=self.graph4_s_variable, value=2, font=widget_label_font) self.graph4_S22_radiobutton = tk.Radiobutton( self.graph4, text="S22", bg='#f2f3fc', fg="#323338", command=self.graph4_plot_draw, variable=self.graph4_s_variable, value=3, font=widget_label_font) self.graph4_S22_radiobutton.select() self.graph4_S11_radiobutton.grid(row=8, column=0, padx=(10, 0), sticky=tk.N + tk.W) self.graph4_S12_radiobutton.grid(row=8, column=0, padx=(70, 0), sticky=tk.N + tk.W) self.graph4_S21_radiobutton.grid(row=9, column=0, padx=(10, 0), pady=(0, 0), sticky=tk.N + tk.W) self.graph4_S22_radiobutton.grid(row=9, column=0, padx=(70, 0), pady=(0, 0), sticky=tk.N + tk.W)
lower_interval_resp_time.append(temp["interval_resp"][0]) upper_interval_custom_front.append(temp["interval_custom_front"][1]) lower_interval_custom_front.append(temp["interval_custom_front"][0]) means_dropped.append(temp["mean_dropped"]) upper_interval_dropped.append(temp["interval_dropped"][1]) lower_interval_dropped.append(temp["interval_dropped"][0]) # saving the data in separate lists for back means_custom_back.append(temp["mean_custom_back"]) upper_interval_custom_back.append(temp["interval_custom_back"][1]) lower_interval_custom_back.append(temp["interval_custom_back"][0]) print str(temp) + "\n" print str(time_debug) + "/" + str(len(lambda_arr_values)) + "\n" time_debug = time_debug + 1 pyplot.close() Graphs.meanAndConfidenceInterval(roh, means_resp_time, lower_interval_resp_time, upper_interval_resp_time, "Average Response Time", "Packet Response Time Front Server") Graphs.meanAndConfidenceInterval(roh, means_custom_front, lower_interval_custom_front, upper_interval_custom_front, "Average Customers", "Customer Buffer Occupancy Front Server") Graphs.meanAndConfidenceInterval(roh, means_dropped, lower_interval_dropped, upper_interval_dropped, "Average Packet Dropped", "Packer Dropped Front Server") Graphs.meanAndConfidenceInterval([1.0 / x for x in lambda_arr_values], means_custom_back, lower_interval_custom_back, upper_interval_custom_back, "Average Customers", "Customer Buffer Occupancy Back Server", x_label="lambda front") pyplot.show()
logger = logging.getLogger('app') logger.setLevel(logging.DEBUG) chandler = logging.StreamHandler() formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') chandler.setFormatter(formatter) logger.addHandler(chandler) if config.log_file: fhandler = logging.FileHandler(config.log_file) fhandler.setFormatter(formatter) logger.addHandler(fhandler) logger.debug('app starting') backend = Backend(config) s_metrics = structured_metrics.StructuredMetrics(config) graphs = Graphs() graphs.load_plugins() graphs_all = graphs.list_graphs() @route('<path:re:/assets/.*>') @route('<path:re:/timeserieswidget/.*js>') @route('<path:re:/timeserieswidget/.*css>') @route('<path:re:/timeserieswidget/timezone-js/src/.*js>') @route('<path:re:/timeserieswidget/tz/.*>') @route('<path:re:/DataTables/media/js/.*js>') @route('<path:re:/DataTablesPlugins/integration/bootstrap/.*js>') @route('<path:re:/DataTablesPlugins/integration/bootstrap/.*css>') def static(path): return static_file(path, root='.')
logger = logging.getLogger('app') logger.setLevel(logging.DEBUG) chandler = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') chandler.setFormatter(formatter) logger.addHandler(chandler) if config.log_file: fhandler = logging.FileHandler(config.log_file) fhandler.setFormatter(formatter) logger.addHandler(fhandler) logger.debug('app starting') backend = Backend(config) s_metrics = structured_metrics.StructuredMetrics(config) graphs = Graphs() graphs.load_plugins() graphs_all = graphs.list_graphs() def parse_query(query_str): query = { 'patterns': [], 'group_by': ['target_type=', 'what=', 'server'], 'sum_by': [] } # for a call like ('foo bar baz quux', 'bar ', 'baz', 'def') # returns ('foo quux', 'baz') or the original query and the default val if no match def parse_out_value(query_str, predicate_match, value_match, value_default): match = re.search('(%s%s)' % (predicate_match, value_match), query_str)
def train(agent, sim, replay_buffer): """Train the agent for exploration steps Args: :param replay_buffer: (ReplayBuffer) replay buffer for arm :param sim: (robot environment) vrep simulation :param agent: (Agent) agent to use, TD3 Algorithm """ best_avg = -10 start_time = time.time() # initialize graphs graphs = Graphs() while glo.TIMESTEP < cons.EXPLORATION: if glo.EPISODE == cons.MAX_EPISODE: print('Max Episode Reached: {}'.format(cons.MAX_EPISODE)) break print('Timesteps: {}/{}.'.format(glo.TIMESTEP, cons.EXPLORATION)) glo.EPISODE += 1 # start at episode 1, after the test so the last episode runs # get the current state of the robot arms (joint angles) right_pos, left_pos = sim.get_current_position() state = right_pos + left_pos # video recording video_array = [] if glo.EPISODE % cons.VIDEO_INTERVAL == 0: video_record = True video_array.append(sim.get_video_image()) else: video_record = False # reset episode variables solved = False # reset each episode as unsolved rewards = [ ] # used to store the episode rewards, used to average the rewards. collision_count = 0 episode_length = 0 # ------------------------------------------------------------------------------------------------- # Start Episode # ------------------------------------------------------------------------------------------------- while True: glo.TIMESTEP += 1 episode_length += 1 # check memory utilization ''' GPUtil.showUtilization() print(torch.cuda.memory_allocated()) count_objs = 0 for obj in gc.get_objects(): try: if torch.is_tensor(obj) or (hasattr(obj, 'data') and torch.is_tensor(obj.data)): # print(type(obj), obj.size()) count_objs += 1 except: pass print("Total objects in GPU memory: {}".format(count_objs)) ''' # get the initial location of the target object target_start = sim.get_target_position() new_state = [] if set_mode.MODE == 'cooperative': # get a new action based on policy action = agent.select_action(np.array(state), noise=cons.POLICY_NOISE).tolist() # apply the action and get the new state right_state, left_state = sim.step_arms(action[:7], action[7:]) new_state = right_state + left_state elif set_mode.MODE == 'independent' or set_mode.MODE == 'partial': right_action = agent.select_action( np.array(state)[:7], 'right', noise=cons.POLICY_NOISE).tolist() left_action = agent.select_action( np.array(state)[7:], 'left', noise=cons.POLICY_NOISE).tolist() # apply the action and get the new state right_state, left_state = sim.step_arms( right_action, left_action) new_state = right_state + left_state # store the actions together in the replay action = right_action + left_action # add the image to the video array if video_record: video_array.append(sim.get_video_image()) # get the new position of the target target_end = sim.get_target_position() target_x, target_y, target_z = target_end # calculate the reward and distance to target for the step reward, distance_moved, distance_to_target = rew.target_movement_reward( target_start, target_end, cons.XYZ_GOAL) # TODO: might want to use a range for each x,y,z rather than rounding. # round the x, y, z to compare with the goal positions round_target_x = round(target_x, 1) round_target_y = round(target_y, 1) round_target_z = round(target_z, 1) # check and see if the target is within the goal range if round_target_x == cons.XYZ_GOAL[0] and round_target_y == cons.XYZ_GOAL[1] and \ round_target_z == cons.XYZ_GOAL[2]: # end episode if the goal is reached done = True else: done = False # check for multiple collisions in a row (5), reset sim if so object_collision_table = sim.object_collision_state() if object_collision_table: # if it collides with the table 5 times in a row - end episode collision_count += 1 if collision_count > 4: done = True collision_count = 0 else: collision_count = 0 # check distance between grippers to see if dropped if sim.check_suction_distance() > .32: done = True time.sleep(1) # wait to allow the sim to catch up reward = -1 # if it is dropped, reward is zero. end the episode and start a new one, it was very bad to drop it. if not sim.check_suction_prox(): done = True time.sleep(1) # wait to allow the sim to catch up reward = -1 # was zero, try a big, bad reward when you drop it # update the replay buffer with new tuple replay_buffer.add(state, action, reward, new_state, done) # training step agent.train(replay_buffer, episode_length) # set the state to the new state for the next step state = new_state if solved: print('Solved on Episode: {}'.format(glo.EPISODE)) # add the reward to the reward list rewards.append(reward) if episode_length == 50: # stop after 50 attempts, 30 was too low to reach goal, tried 45. done = True # stop after 50 attempts, was getting stuck flipping from bad to good. # calculate the elapsed time elapsed_time = time.time() - start_time if cons.WRITE_TO_FILE: cons.report.write_report_step(glo.EPISODE, glo.TIMESTEP, reward, distance_moved, distance_to_target, solved, elapsed_time) if done: # get the average reward for the episode mean_reward_episode = mean(rewards) # if current episodes reward better, becomes new save if best_avg < mean_reward_episode: best_avg = mean_reward_episode agent.save() if video_record and episode_length > 10: # only record episodes over 10 output_video(video_array, cons.SIZE, names.EPISODE_VIDEO) if solved: output_video(video_array, cons.SIZE, names.EPISODE_VIDEO_SOLVED) system_info = psutil.virtual_memory() if True: print("\n*** Episode " + str(glo.EPISODE) + " ***") print("Avg_Reward [last episode of " + str(episode_length) + " steps]: " + str(mean_reward_episode)) print("Total Timesteps: " + str(glo.TIMESTEP)) print("Elapsed Time: ", time.strftime("%H:%M:%S", time.gmtime(elapsed_time))) print("Memory Usage: " + str(system_info.percent) + "%") # reset the simulation at the end of the episode sim.reset_sim() # at the end of the episode, visualize the charts. graphs.update_step_list_graphs() # end the episode break # check for system overload, if memory over-utilized, quit system_info = psutil.virtual_memory() if system_info.percent > 98: break # write any remaining values cons.report.write_final_values() # at the end do a final update of the graphs graphs.update_step_list_graphs()
from datetime import datetime import dash import dash_core_components as dcc import dash_html_components as html import dash_bootstrap_components as dbc import pandas as pd import numpy as np import flask from graphs import Graphs as Grph external_stylesheets = [dbc.themes.COSMO] app = dash.Dash(__name__, external_stylesheets=external_stylesheets) server = app.server app.layout = dbc.Container([ dbc.Row(dbc.Col(html.H1('Kanban Dashboard'), md=12, className='mb-3')), dbc.Row([ dbc.Col(dbc.Card([ dbc.CardHeader('Timeline'), dbc.CardBody(Grph.timeline()) ]), md=12, className='mb-3'), ]), ], fluid=True) if __name__ == '__main__': app.run_server(host='0.0.0.0', port=8050, debug=True)
def plot_statewise_map(state): if state == "Total": return Graphs.draw_total_state_map(preprocessed_df) else: return graph.draw_statewise_map(data.df_us_cases, row=state)
for y in mapa[x]: print(x, y) edge.append((x, y)) print(edge) for x, y in edge: if (direct): matriz[mapan[x]][mapan[y]] = 1 else: matriz[mapan[x]][mapan[y]] = 1 matriz[mapan[y]][mapan[x]] = 1 print(matriz) graph = Graphs(edge, direct) # Criando o grafo print(graph.adj) # Lista de adjacências search = input("Deseja realizar uma busca? (S-> Sim / N -> Não): ") if search is "S" or search is "s": vertice_root = input( "Defina qual o vértice raíz para realização da busca: ") search_type = input( "Deseja realizar busca de em Largura(L) ou Profundidade(P)?: ") visited = [] if search_type == "L": bfs(graph, vertice_root, visited) elif search_type == "P": dfs(graph, vertice_root, visited) else: print("Digite uma letra correta!")