def __init__(self): ''' Constructor ''' qt4.QObject.__init__( self ) self.view_mode = "R" self.cp1 = CircuitProfile(None) self.cp2 = CircuitProfile(None) self.cpgoal = CircuitProfile(None) self.ops = {} self.results = {"S1": {}, "S2": {}, "Change": {}, "Goal": {}} self.load_operations() # create the GUI app self.app = qt4.QApplication.instance() self.app.processEvents() # instantiate the main window self.ui = MainWindow(self) self.plots_S1 = Plots(self, self.ui, "S1", self.ui.mplS1) self.plots_S2 = Plots(self, self.ui, "S2", self.ui.mplS2) self.plots_S2.hide() # full screen self.ui.showMaximized() # start the Qt main loop execution, exiting from this script # with the same return code of Qt application sys.exit(self.app.exec_()) self.log_file = open("log_file.txt", "w")
def __init__(self): ''' Constructor ''' qt4.QObject.__init__(self) self.view_mode = "R" self.cp1 = CircuitProfile(None) self.cp2 = CircuitProfile(None) self.cpgoal = CircuitProfile(None) self.ops = {} self.results = {"S1": {}, "S2": {}, "Change": {}, "Goal": {}} self.load_operations() # create the GUI app self.app = qt4.QApplication.instance() self.app.processEvents() # instantiate the main window self.ui = MainWindow(self) self.plots_S1 = Plots(self, self.ui, "S1", self.ui.mplS1) self.plots_S2 = Plots(self, self.ui, "S2", self.ui.mplS2) self.plots_S2.hide() # full screen self.ui.showMaximized() # start the Qt main loop execution, exiting from this script # with the same return code of Qt application sys.exit(self.app.exec_()) self.log_file = open("log_file.txt", "w")
def plot_residues(self): self.plots = Plots(self.topol_data) if self.diagram_type == "amino": self.plots.define_amino_acids() self.plots.plot_amino_diagramms() if self.diagram_type == "domains": assert len(self.domain_file) > 0, "Provide a file defining domains" self.plots.define_domains(self.domain_file, self.offset) self.plots.plot_domains_diagramms() if self.diagram_type == "clock": self.plots.plot_clock_diagramms()
def plot(collection_yaml, output_root, metrics, random = False): this_output_root = os.path.join(output_root, collection_yaml['name']) if random: if collection_yaml['name'] == 'disk12' or collection_yaml['name'] == 'robust04' or collection_yaml['name'] == 'robust05' or collection_yaml['name'] == 'core17': beta = 0.5 elif collection_yaml['name'] == 'mb11' or collection_yaml['name'] == 'mb13': beta = 1.0 else: # Web collections beta = 0.1 Plots().plot_random_seeds(collection_yaml['name'], this_output_root, beta, metrics) else: Plots().plot_params_sensitivity(collection_yaml['name'], this_output_root, metrics)
class PlotsTest(unittest.TestCase): _plots = Plots() def bookingsPerCar(self): self.assertEqual(self._plots.bookingsPerCar('toyota', 3)) def userBasePercentages(self): self.assertIsNone(self._plots.userBasePercentages(6, 2))
def get_pulse_signal(mean_rgb, window_size): pulse_signal = np.zeros(mean_rgb.shape[0]) for window_start in range(0, (mean_rgb.shape[0] - window_size)): window_mean_rgb = mean_rgb[window_start:window_start + window_size - 1, :].T Plots().rgb_plot(window_mean_rgb.T) temp_normed_rgb = temp_norm(window_mean_rgb) Plots().rgb_plot(temp_normed_rgb.T) projection_matrix = np.array([[0, 1, -1], [-2, 1, 1]]) POS = np.matmul(projection_matrix, temp_normed_rgb) std = np.array([1, np.std(POS[0, :]) / np.std(POS[1, :])]) pulse = np.matmul(std, POS) pulse_signal[ window_start:window_start + window_size - 1] = pulse_signal[window_start:window_start + window_size - 1] + (pulse - np.mean(pulse)) / np.std(pulse) return pulse_signal
def create_plot(self) -> None: """Creates a plotly graph based on the chosen x and y values uses the values chosen for x, y, and the location by the user""" regions = self.data_set.regions if self.chose_local[0]: if self.chosen_x_values == "time": Plots.in_region_over_time(regions[self.chose_local[1]], self.chosen_y_values) else: Plots.in_region(regions[self.chose_local[1]], self.chosen_x_values, self.chosen_y_values) else: if self.chosen_x_values == "time": Plots.all_regions_over_time(regions, self.chosen_y_values) else: Plots.all_regions(regions, self.chosen_x_values, self.chosen_y_values)
def plot_boxes(): plots = Plots() dots = 5 for size in range(2, 11, 2): x = np.linspace(0, 1, dots + 1) y = all_boxes(size, dots) plots.add_plot(x, y, str(size)) plt.legend() plots.show() exit(0)
def k_fold(self, X, y, k, classifier): X, y = self.shuffle(X, y) subset_size = round(X.shape[0] / k) X_subsets = [ X[i:i + subset_size, :] for i in range(0, X.shape[0], subset_size) ] y_subsets = [ y[i:i + subset_size] for i in range(0, y.shape[0], subset_size) ] train_accuracy_list = np.array([]) test_accuracy_list = np.array([]) print("___________________________K-fold___________________________") for i in range(k): X_test = X_subsets[i] y_test = y_subsets[i] X_train = np.array([]) y_train = np.array([]) for j in range(k): if i != j: X_train = np.append(X_train, X_subsets[j]) y_train = np.append(y_train, y_subsets[j]) X_train = X_train.reshape(y_train.shape[0], X.shape[1]) classifier.fit(X_train, y_train) y_test_pred = classifier.predict(X_test) y_train_pred = classifier.predict(X_train) test_accuracy = self.accuracy_score(y_test, y_test_pred) train_accuracy = self.accuracy_score(y_train, y_train_pred) train_accuracy_list = np.append(train_accuracy_list, train_accuracy) test_accuracy_list = np.append(test_accuracy_list, test_accuracy) print( "___________________________Iteração {}___________________________" .format(i + 1)) print('Acurácia para dados de treino: {}'.format(train_accuracy)) print('Acurácia para dados de teste: {}'.format(test_accuracy)) Plots().plot_confusion_matrix_(X_test, y_test, classifier) print('\n') print('Acurácia geral de treino: {}'.format( train_accuracy_list.mean())) print('Acurácia geral de teste: {}'.format(test_accuracy_list.mean()))
def plot_boxes2(): plots = Plots() dots = 5 res = None for size in range(2, 11, 1): dummy, r = all_boxes(size, dots) if res is None: res = r else: res = np.vstack((res, r)) res = res.transpose() print(res) x = np.arange(2, 11, 1) for i in range(dots + 1): plots.add_plot(x, res[i], str(round(i * 0.2, 1))) plots.show() exit(0)
class Lintools(object): def __init__(self, topology, trajectory, ligand_name, offset, cutoff, analysis_cutoff, diagram_type, domain_file, HB_flag, RMSF_flag, debug_flag, resinfo_flag, mol2_file, output_name): self.topology = os.path.abspath(topology) try: self.trajectory = [] for traj in trajectory: self.trajectory.append(os.path.abspath(traj)) except Exception: self.trajectory = trajectory self.ligand_name = ligand_name self.offset = offset self.cutoff = cutoff self.analysis_cutoff = analysis_cutoff self.diagram_type = diagram_type try: self.domain_file = os.path.abspath(domain_file) except Exception: self.domain_file = domain_file self.HB_flag = HB_flag self.RMSF_flag = RMSF_flag self.debug_flag = debug_flag self.resinfo_flag = resinfo_flag try: self.mol2_file = os.path.abspath(mol2_file) except Exception: self.mol2_file = mol2_file self.output_name = output_name self.rmsf = None self.hbonds = None def get_info_about_input_and_analyse(self): """This function loads all input files and decides which residues to plot""" self.topol_data = Topol_Data(self.topology, self.trajectory, self.ligand_name, self.offset, self.mol2_file) self.topol_data.define_ligand(self.ligand_name, self.mol2_file) if self.trajectory == None: self.topol_data.find_res_to_plot(self.cutoff) else: self.occurrence = Occurrence_analysis(self.topology, self.trajectory, self.ligand_name, self.cutoff, self.offset, self.topol_data) self.occurrence.get_closest_residues(self.analysis_cutoff) if self.HB_flag != True: self.hbonds = HBonds(self.topol_data, self.topology, self.trajectory, self.ligand_name, self.offset, self.analysis_cutoff) self.topol_data.get_closest_ligand_atoms(self.hbonds) else: self.topol_data.get_closest_ligand_atoms() if self.RMSF_flag == True: self.rmsf = RMSF_measurements(self.topol_data, self.topology, self.trajectory, self.ligand_name, self.offset, self.output_name) def plot_residues(self): self.plots = Plots(self.topol_data) if self.diagram_type == "amino": self.plots.define_amino_acids() self.plots.plot_amino_diagramms() if self.diagram_type == "domains": assert len(self.domain_file) > 0, "Provide a file defining domains" self.plots.define_domains(self.domain_file, self.offset) self.plots.plot_domains_diagramms() if self.diagram_type == "clock": self.plots.plot_clock_diagramms() def draw_molecule_and_figure(self, tests=False): self.molecule = Molecule(self.topol_data, self.rmsf) self.figure = Figure(self.molecule, self.diagram_type, self.topol_data, self.hbonds, self.plots, self.rmsf, tests) if self.HB_flag != True: self.figure.draw_hbonds_in_graph(self.diagram_type) self.figure.draw_white_circles_at_atoms(self.diagram_type) if self.debug_flag == True: self.figure.draw_lines_in_graph( ) #a function for debugging purposes self.figure.put_everything_together() self.figure.write_final_draw_file(self.output_name) if self.trajectory != None and self.resinfo_flag != True: self.res_info = Residue_Info(self.topol_data, self.occurrence, self.figure) def save_files(self): """Saves all output from LINTools run in a single directory named after the output name.""" os.system("mkdir " + self.output_name) self.workdir = os.getcwd() os.chdir(self.workdir + "/" + self.output_name) def remove_files(self): file_list = [ "molecule.svg", "LIG.pdb", "test.xtc", "rmsf_colorbar.svg" ] for residue in self.topol_data.dict_of_plotted_res.keys(): file_list.append(str(residue[3:]) + ".svg") for f in file_list: if os.path.isfile(f) == True: os.remove(f)
DATADIR = os.path.abspath(os.path.join(MAINDIR, "data", "signal")) BKGDATADIR = os.path.abspath(os.path.join(MAINDIR, "data", "background")) if __name__ == '__main__': print("MAKING PMT COUNTING STACK PLOTS") #Get list of all signal and background data listofdatafiles = glob.glob(DATADIR + '/*.npz') listofbkgfiles = glob.glob(BKGDATADIR + '/*.npz') if DEBUG is True: print("PRINTING LIST OF DATA FILES, THEN BACKGROUND FILES") print(listofdatafiles) print(listofbkgfiles) # First, initialize your data structure with all desired data file # and background file locations alldatafiles = ds.datacollection(listofdatafiles, listofbkgfiles) # Load the current list of data files into data to be analyzed alldatafiles.load_datafiles() #Loads in bkg files for use. Uncomment to calculate bkgs w/ peak sidebands alldatafiles.load_bkgdatafiles() if DEBUG is True: print("FILES LOADED SUCCESSFULLY. INITIALIZING PLOTTER CLASS") ourplotter = p.DataPlotter(dataclass=alldatafiles) ourplotter.StackPlot_FirstDataFiles() ourplotter.BkgSubtract_FirstDataFiles() ourplotter.BkgSubtract_RoughShift() ourplotter.BkgSubtract_FDF_Peakshift()
'decay_factor': 0.9, 'a': 1, 'b': 1, 'ratio': 2 } if __name__ == "__main__": if len(sys.argv) < 1: print("needs at least 1 argument: (j/p/R/lambda/n0)") exit() param = sys.argv[1] param_values = parameters_range[param] evaluation = Plots() agg_results = {} max_iter = 5 run = 1 for param_val in param_values: # TODO: set the experiment_setup parameter based on param_va agg_results[param_values] = {} evaluation.create_sub_folder(run) results = { 'perf': { 'exact': [[0] * Experiment_Setup.time_steps] * max_iter, 'approx': [[0] * Experiment_Setup.time_steps] * max_iter
print("----") print(f"X_test_vectorized type: {type(X_test_vectorized)}") print(f"X_test_vectorized shape: {X_test_vectorized.shape}") print("----") print(f"y_test type: {type(y_test)}") print(f"y_test shape: {len(y_test)}") # Load the model print(f"Loading classifier from {config.MODEL_PATH}") with open(config.MODEL_PATH, 'rb') as fid: clf = pickle.load(fid) print("Generating confusion matrix") y_pred = clf.predict(X_test_vectorized) plots = Plots(config=config) plots.plot_confusion_matrices(y_pred=y_pred, y_true=y_test) print("Calculating metrics") precision, recall, f1, accuracy = calculate_metrics(y_pred=y_pred, y_true=y_test, config=config) print( f"precision: {precision}, recall: {recall}, f1: {f1}, accuracy: {accuracy}" ) # Record to WanDB print("Logging to wandb") wandb.log({ 'val_f1': f1, 'val_recall': recall, 'val_precision': precision,
if __name__ == '__main__': # X, Y = Reader.read_data('dados/xor.txt', ignore_line_number=False) # data = {'X':X, 'Y':Y} # Reader.save_mat('dados/xor.mat', data) mat = Reader.load_mat('dados/xor.mat') X_orig, Y = np.matrix(mat['X']), mat['Y'] # X, mu, sigma = Features.normalize(X) Plots.scatterplot(X_orig, Y) pyplot.show() max_degree = 60 iters, times, accs, alphas = [], [], [], [] result_times = open("reg_result_times.txt", "w") result_times.write("alpha tempo\n") result_iters = open("reg_result_iters.txt", "w") result_iters.write("alpha iters\n") result_accs = open("reg_result_accs.txt", "w") result_accs.write("alpha acc\n")
def plot_residues(self, colormap): """ Calls Plot() that plots the residues with the required diagram_type. """ self.plots = Plots(self.topol_data, self.diagram_type, colormap)
ylightWeek = [] for entry in dataLightWeek: xlightWeek.append(entry[1]) ylightWeek.append(float(entry[0])) myCursor.close() conn.commit() conn.close() except mysql.connector.Error as e: print("Something went wrong: {}".format(e)) moisPlotName = "/media/pi/USB/" + "MoisturePlot.png" moisPlotCopy = "/var/www/html/" + "MoisturePlot.png" moisPlot = Plots(xmois, y2mois, ymois, "24 hours", "Moisture", moisPlotName, "moisture low limit", "moisture") moisPlot.Create2linePlot() copyfile(moisPlotName, moisPlotCopy) moisPlotNameWeek = "/media/pi/USB/" + "MoisturePlotWeek.png" moisPlotCopyWeek = "/var/www/html/" + "MoisturePlotWeek.png" moisPlotWeek = Plots(xmoisWeek, y2moisWeek, ymoisWeek, "Week", "Moisture", moisPlotNameWeek, "moisture low limit", "moisture") moisPlotWeek.Create2linePlot() copyfile(moisPlotNameWeek, moisPlotCopyWeek) greenPlotName = "/media/pi/USB/" + "GreenPlot.png" greenPlotCopy = "/var/www/html/" + "GreenPlot.png" greenPlot = Plots(xgreen, ygreen, [], "Week", "Growth (%)", greenPlotName, "Growth (%)", "") greenPlot.CreatelinePlot()
use_validation = False nb_input = 2 nb_hidden = 10 nb_labels = 2 nb_iters = 10000 nb_epochs = 1 alpha = 3.0 lbda = 0.0 momentum = 0.0 precision = 1e-6 timer = time.clock if (sys.platform == 'win32') else time.time Plots.scatterplot(X, Y) for nb_hidden in range(1, 7): nn = NeuralNetwork(nb_input, nb_hidden, nb_labels, cost_function='cross_entropy') a, b, c, d = [], [], [], [] for i in range(nb_epochs): X_train, Y_train = X, Y Y_vec = Utils.vectorize_output(Y_train, nb_labels) print('Epoch %d' % (i + 1))
%reload_ext autoreload %autoreload 2 %matplotlib inline from recipes_analizer import RecipesAnalizer from basket_processor import BasketProcessor from plots import Plots import numpy as np from sklearn.metrics.pairwise import euclidean_distances RECEIPES_FILE_TRAIN = '../Data/recipe-ingredients-dataset/train.json' GROCERIES_FILE = '../Data/groceries/groceries.csv' plot = Plots() ra = RecipesAnalizer(source=RECEIPES_FILE_TRAIN) recipes_df = ra.load_data() unique_ingredients = ra.unique_ingredients(recipes_df['ingredients']) recipes_df['ingredient_indexes'] = ra.replace_by_indexes(unique_ingredients, recipes_df['ingredients']) tfidf_matrix = ra.tfidf_matrix(corpus=recipes_df['ingredient_indexes']) recipes_df['cluster'], centroids = ra.cluster_recipes(tfidf_matrix, n_clusters=3) plot.compare_cuisine(recipes_df) vocabulary_text = [unique_ingredients[int(i)] for i in list(ra.vectorizer.vocabulary_.keys())] bp = BasketProcessor() baskets = bp.load_groceries_data(file=GROCERIES_FILE) unique_items = list({item for basket in baskets for item in basket}) print('There are %d unique items' % len(unique_items)) #Includes all items in baskets bp.find_common_items(vocabulary_text, unique_items) #Performs identical string comparison filtered_baskets = bp.get_filtered_baskets(baskets) #Apply the fitted TfidfVectorizer to the baskets with 'transform' method
scrape_web = ScrapeWeb(user="******".format(tweet_user), start_date=start_date, end_date=end_date, logger_name=logger_name) scrape_web.get_tweets() # Get tweet data for tweet_user meta_data = GetMetaData(user="******".format(tweet_user), logger_name=logger_name) meta_data.get_metadata() logger.info("Processing the stock and tweet data") # Process retrieved data process_data = ProcessData(ticker_list=ticker_list, logger_name=logger_name) processed_df_stock = process_data.process_data_stock( '{}/stockdata/output/{}'.format(os.getcwd(), sys.argv[1])) processed_df_tweet = process_data.process_data_tweet( '{}/tweetdata/output/{}.csv'.format(os.getcwd(), sys.argv[4])) logger.info("Performing sentiment analysis") sa = SentimentAnalysis(csv_file='{}/tweetdata/output/{}.csv'.format( os.getcwd(), sys.argv[4]), logger_name=logger_name) sa.plot(['favorite_count', 'retweet_count']) logger.info("Plotting stock and tweet data") for ticker in ticker_list: filtered_df = process_data.filter_tweet(processed_df_tweet, ticker) # Plot processed data plot_data = Plots(logger_name=logger_name) # plot_data.candlestick_stock_plot(processed_df_stock, 'AMZN') plot_data.candlestick_stock_tweet_plot(processed_df_stock, filtered_df, ticker) logger.info("Tick-er-Tweet ran successfully!")
return self.train_binary(X, Y, alpha, lbda, precision, nb_iters, verbose) if __name__ == '__main__': # X, Y = Reader.read_data('dados/xor.txt', ignore_line_number=False) # data = {'X':X, 'Y':Y} # Reader.save_mat('dados/xor.mat', data) mat = Reader.load_mat('dados/xor.mat') X_orig, Y = np.matrix(mat['X']), mat['Y'] # X, mu, sigma = Features.normalize(X) Plots.scatterplot(X_orig, Y) pyplot.show() max_degree = 60 iters, times, accs, alphas = [], [], [], [] result_times = open("reg_result_times.txt", "w") result_times.write("alpha tempo\n") result_iters = open("reg_result_iters.txt", "w") result_iters.write("alpha iters\n") result_accs = open("reg_result_accs.txt", "w") result_accs.write("alpha acc\n") result_alphas = open("reg_result_alphas.txt", "w")
def plot_coverage(collection_yaml, output_root): this_output_root = os.path.join(output_root, collection_yaml['name']) Plots().plot_coverage(collection_yaml['name'], this_output_root)
def logistic_regression_model(x_train, x_test, y_train, y_test): # Training model model = LogisticRegression(C=0.7, random_state=42, max_iter=1000) model.fit(x_train, y_train.ravel()) # Validation model and classification report lr_predict_test = model.predict(x_test) print("Accuracy logistic regression test data : {0:.4f}".format( metrics.accuracy_score(y_test, lr_predict_test))) print("\nClassification Report") print(metrics.classification_report(y_test, lr_predict_test, labels=[1, 0])) if __name__ == '__main__': p = Plots() df = pd.read_csv('pima-data.csv') # data_exploration(df) # Correlation c = df.corr() # p.correlation(c) # print(c) # Format target diabetes_map = {True: 1, False: 0} df['diabetes'] = df['diabetes'].map(diabetes_map) # print(df.head()) # Splitting data
manifold = MultinomialManifold(dimGroup.sum(), dataset.K) # pick a solver #solver = GradientDescent(tol = 1e-3, learning_rate = 0.05, max_iter = 500) solver = ConjugateGradient(tol = 1e-2, max_iter = 500) # define initial point X0 = manifold.random() # define the problem problem = Problem(Xin, dimGroup) # minimize the objective of the problem using solver cache, X = solver.Solve(manifold, problem.cost, problem.egrad, X0) # discretize low-rank factors discretization = Discretization(X, dimGroup) X = discretization.Stochastic2Permutation() # evaluate accuracy evaluation = Eval(Xin, Xgt, X) evaluation.print_accuracy() # plot cost over time plots = Plots(cache) plots.plot_cost()
""" Predict house's price using tensorflow (1.14.0). Functions: np.asarray - transform input to array """ import numpy as np import warnings warnings.simplefilter(action='ignore', category=FutureWarning) import tensorflow as tf from plots import Plots if __name__ == '__main__': p = Plots() # Hyper params learning_rate = 0.01 training_epochs = 2000 display_step = 200 # Train data set: x: house length, y: house price train_x = np.asarray([ 3.3, 4.4, 5.5, 6.71, 6.93, 4.168, 9.779, 6.182, 7.59, 2.167, 7.042, 10.791, 5.313, 7.997, 5.654, 9.27, 3.1 ]) train_y = np.asarray([ 1.7, 2.76, 2.09, 3.19, 1.694, 1.573, 3.366, 2.596, 2.53, 1.221, 2.827, 3.465, 1.65, 2.904, 2.42, 2.94, 1.3 ])
class Model(qt4.QObject): ''' Main work horse. Model of the data. ''' #*************************************__init__()************************************* def __init__(self): ''' Constructor ''' qt4.QObject.__init__(self) self.view_mode = "R" self.cp1 = CircuitProfile(None) self.cp2 = CircuitProfile(None) self.cpgoal = CircuitProfile(None) self.ops = {} self.results = {"S1": {}, "S2": {}, "Change": {}, "Goal": {}} self.load_operations() # create the GUI app self.app = qt4.QApplication.instance() self.app.processEvents() # instantiate the main window self.ui = MainWindow(self) self.plots_S1 = Plots(self, self.ui, "S1", self.ui.mplS1) self.plots_S2 = Plots(self, self.ui, "S2", self.ui.mplS2) self.plots_S2.hide() # full screen self.ui.showMaximized() # start the Qt main loop execution, exiting from this script # with the same return code of Qt application sys.exit(self.app.exec_()) self.log_file = open("log_file.txt", "w") #*************************************load_circuit_profile()************************************* def load_circuit_profile(self, identifier, fname): ''' Args: Returns: Raises: ''' if identifier == "S1": cp = self.cp1 elif identifier == "S2": cp = self.cp2 self.plots_S2.unhide() if len(cp.results) == 0: self.plots_S1.hide() elif identifier == "Goal": cp = self.cpgoal else: print "Unknown circuit profile identifier" sys.exit() cp.open_file(fname) results = self.compute_operations(cp) cp.set_results(results) self.results[identifier] = results if identifier == "S1": self.plots_S1.update_plots(cp) elif identifier == "S2": self.plots_S2.update_plots(cp) self.check_change() self.emit(qt4.SIGNAL("sigModified")) #***************************check_change()*************************** def check_change(self): ''' Args: Returns: Raises: ''' rS1 = self.results["S1"] rS2 = self.results["S2"] if len(rS1) > 0 and len(rS2) > 0: self.results["Change"] = self.cp2 - self.cp1 self.plots_S1.unhide() self.plots_S2.unhide() #***************************load_operations()*************************** def load_operations(self): ''' Args: Returns: Raises: ''' self.ops = Operations(self) self.vert_headers = ["S1", "S2", "Change", "Goal"] self.horiz_headers = self.ops.get_ops("table").keys() self.horiz_headers.sort() #***************************compute_operations()*************************** def compute_operations(self, cp): ''' Args: Returns: Raises: ''' return self.ops.compute(cp) #***************************change_view()*************************** def change_view(self, view): ''' Args: Returns: Raises: ''' self.view_mode = view temp = [] temp_plots = [] if self.view_mode == "R": temp = self.ops.get_ops("table").keys() temp_plots = self.ops.get_ops("plot").keys() if self.view_mode == "T": for opname, op in self.ops.get_ops("table").items(): if op.therapist is True or op.patient is True: temp.append(opname) for opname, op in self.ops.get_ops("plot").items(): if op.therapist is True or op.patient is True: temp_plots.append(opname) if self.view_mode == "P": for opname, op in self.ops.get_ops("table").items(): if op.patient is True: temp.append(opname) for opname, op in self.ops.get_ops("plot").items(): if op.patient is True: temp_plots.append(opname) self.plots_S1.change_view(temp_plots) self.plots_S2.change_view(temp_plots) temp.sort() self.horiz_headers = temp self.emit(qt4.SIGNAL("sigModified")) #***************************get_result_at()*************************** def get_result_at(self, row, col): ''' Args: Returns: Raises: ''' cpname = self.vert_headers[col] cp_results = self.results[cpname] if len(cp_results) == 0: return None opname = self.horiz_headers[row] if self.view_mode == "R": return cp_results[opname] if self.view_mode == "T": op = self.ops.ops[opname] if op.therapist is True or op.patient is True: return cp_results[opname] if self.view_mode == "P": op = self.ops.ops[opname] if op.patient is True: return cp_results[opname] #***************************get_description_at()*************************** def get_description_at(self, row, col): ''' Args: Returns: Raises: ''' cpname = self.vert_headers[col] opname = self.horiz_headers[row] return self.ops.get_description(opname) #***************************get_vert_headers()*************************** def get_vert_headers(self): ''' Args: Returns: Raises: ''' return self.vert_headers #***************************get_horiz_headers()*************************** def get_horiz_headers(self): ''' Args: Returns: Raises: ''' return self.horiz_headers
from csv2df import Csv2Frame, saveToPDF from plots import Plots, Map """Creating BAR PLOTS""" #reading CSV file to panda DataFrames c = Csv2Frame() #DataFrame create object #Two files available: male and female names, only one can be active at once #df = c.ReadCSV('imiona_żeńskie.csv') df = c.ReadCSV('imiona_meskie.csv') df, woj = c.CreateDF(df) dfs = c.SetOfDataFrames(df, woj) plot = Plots() #BarPlots object plotBar = plot.bars(dfs) """Creating polish provinces map with top 1 name""" #Reading JSON with polish provinces boundaries pol_url = "https://raw.githubusercontent.com/deldersveld/topojson/master/countries/poland/poland-provinces.json" #map instance map = Map() m = map.readMap(pol_url) stats = c.DataFramesMax(dfs) m_stats = c.MergingData(m, stats) mapWithLabels = map.mapLabels(m_stats) """creating WORD CLOUD with names""" #sorting and summing occurences of each name dfSum = c.sumByName(df) #creating word cloud for top 35 names wc = plot.wc(dfSum.head(35)) """creating PIE CHART with a percentage distribution""" dfPie = c.percByName(df, 15) pie = plot.pie(dfPie)
class Model(qt4.QObject): ''' Main work horse. Model of the data. ''' #*************************************__init__()************************************* def __init__(self): ''' Constructor ''' qt4.QObject.__init__( self ) self.view_mode = "R" self.cp1 = CircuitProfile(None) self.cp2 = CircuitProfile(None) self.cpgoal = CircuitProfile(None) self.ops = {} self.results = {"S1": {}, "S2": {}, "Change": {}, "Goal": {}} self.load_operations() # create the GUI app self.app = qt4.QApplication.instance() self.app.processEvents() # instantiate the main window self.ui = MainWindow(self) self.plots_S1 = Plots(self, self.ui, "S1", self.ui.mplS1) self.plots_S2 = Plots(self, self.ui, "S2", self.ui.mplS2) self.plots_S2.hide() # full screen self.ui.showMaximized() # start the Qt main loop execution, exiting from this script # with the same return code of Qt application sys.exit(self.app.exec_()) self.log_file = open("log_file.txt", "w") #*************************************load_circuit_profile()************************************* def load_circuit_profile(self, identifier, fname): ''' Args: Returns: Raises: ''' if identifier == "S1": cp = self.cp1 elif identifier == "S2": cp = self.cp2 self.plots_S2.unhide() if len(cp.results) == 0: self.plots_S1.hide() elif identifier == "Goal": cp = self.cpgoal else: print "Unknown circuit profile identifier" sys.exit() cp.open_file(fname) results = self.compute_operations(cp) cp.set_results(results) self.results[identifier] = results if identifier == "S1": self.plots_S1.update_plots(cp) elif identifier == "S2": self.plots_S2.update_plots(cp) self.check_change() self.emit(qt4.SIGNAL("sigModified")) #***************************check_change()*************************** def check_change(self): ''' Args: Returns: Raises: ''' rS1 = self.results["S1"] rS2 = self.results["S2"] if len(rS1) > 0 and len(rS2) > 0: self.results["Change"] = self.cp2 - self.cp1 self.plots_S1.unhide() self.plots_S2.unhide() #***************************load_operations()*************************** def load_operations(self): ''' Args: Returns: Raises: ''' self.ops = Operations(self) self.vert_headers = ["S1", "S2", "Change", "Goal"] self.horiz_headers = self.ops.get_ops("table").keys() self.horiz_headers.sort() #***************************compute_operations()*************************** def compute_operations(self, cp): ''' Args: Returns: Raises: ''' return self.ops.compute(cp) #***************************change_view()*************************** def change_view(self, view): ''' Args: Returns: Raises: ''' self.view_mode = view temp = [] temp_plots = [] if self.view_mode == "R": temp = self.ops.get_ops("table").keys() temp_plots = self.ops.get_ops("plot").keys() if self.view_mode == "T": for opname, op in self.ops.get_ops("table").items(): if op.therapist is True or op.patient is True: temp.append(opname) for opname, op in self.ops.get_ops("plot").items(): if op.therapist is True or op.patient is True: temp_plots.append(opname) if self.view_mode == "P": for opname, op in self.ops.get_ops("table").items(): if op.patient is True: temp.append(opname) for opname, op in self.ops.get_ops("plot").items(): if op.patient is True: temp_plots.append(opname) self.plots_S1.change_view(temp_plots) self.plots_S2.change_view(temp_plots) temp.sort() self.horiz_headers = temp self.emit(qt4.SIGNAL("sigModified")) #***************************get_result_at()*************************** def get_result_at(self, row, col): ''' Args: Returns: Raises: ''' cpname = self.vert_headers[col] cp_results = self.results[cpname] if len(cp_results) == 0: return None opname = self.horiz_headers[row] if self.view_mode == "R": return cp_results[opname] if self.view_mode == "T": op = self.ops.ops[opname] if op.therapist is True or op.patient is True: return cp_results[opname] if self.view_mode == "P": op = self.ops.ops[opname] if op.patient is True: return cp_results[opname] #***************************get_description_at()*************************** def get_description_at(self, row, col): ''' Args: Returns: Raises: ''' cpname = self.vert_headers[col] opname = self.horiz_headers[row] return self.ops.get_description(opname) #***************************get_vert_headers()*************************** def get_vert_headers(self): ''' Args: Returns: Raises: ''' return self.vert_headers #***************************get_horiz_headers()*************************** def get_horiz_headers(self): ''' Args: Returns: Raises: ''' return self.horiz_headers
def plot_per_topic_analysis(collection_yaml, output_root): this_output_root = os.path.join(output_root, collection_yaml['name']) Plots().plot_per_topic_analysis(collection_yaml['name'], this_output_root)
from lin_alg import LinAlg from plots import Plots __author__ = 'Vitold Komorovski' def set_matrix(inp): matrix = np.ones((3, 3), 'int32') matrix[0][0] *= inp matrix[1][1] *= inp return matrix if __name__ == '__main__': print('Give me a number: \n') inp = input() matrix = set_matrix(inp) # Linear algebra # lin_alg = LinAlg(matrix) # lin_alg.get_det() # lin_alg.solve_lin() # Simple plots plt = Plots(matrix) # plt.display() # plt.gray_noise() # # Plot surfaces plt.plot_linear(matrix)
use_validation = False nb_input = 2 nb_hidden = 10 nb_labels = 2 nb_iters = 10000 nb_epochs = 1 alpha = 3.0 lbda = 0.0 momentum = 0.0 precision = 1e-6 timer = time.clock if (sys.platform == 'win32') else time.time Plots.scatterplot(X, Y) for nb_hidden in range(1, 7): nn = NeuralNetwork(nb_input, nb_hidden, nb_labels, cost_function='cross_entropy') a,b,c,d = [],[],[],[] for i in range(nb_epochs): X_train, Y_train = X, Y Y_vec = Utils.vectorize_output(Y_train, nb_labels) print('Epoch %d' % (i+1)) print("-"*30) nn.initialize_weights()
from twitter_connection import Connection, GettingTweetsOfParties from db_connection import DBConnection, tmpTable from plots import Dataframes, Plots import matplotlib.pyplot as plt import datetime api = Connection() db = DBConnection() d = Dataframes() p = Plots() #users definitions Partie = {1:'PiS', 2:'PO', 3:'Lewica', 4:'Wiosna',5:'Razem',6:'PSL', 7:'Konfederacja', 8:'Duda',9:'Bosak',10:'Trzaskowki', 11:'Biedroń', 12:'Hołownia', 13:'Kosiniak-Kamysz'} ###saving tweets from Twitter into DB_table from 6th of June to 19th of July 2020 """timeStart = datetime.datetime(2020,6,1,0,0,0) timeStop = datetime.datetime(2020,7,19,0,0,0) GettingTweetsOfParties(timeStart, timeStop,db)""" ###getting most frequently used words for each account """c = db.cursor() tmpQ = c.execute('select id from Partie_polityczne') tmpQ = tmpQ.fetchall() t =tmpTable() for i in tmpQ: t.CreatingTmpTable(i[0])""" ###dictionary for collecting all plots tmpPlots = {} ###getting sum of tweets per day for users: