def main(): # read in data from csv file tl.get_data([confirmed_data, death_data, recovery_data]) # size constants of files ~~~ will need to make larger for all 3 files sizer = np.shape(confirmed_data) print(sizer) entries = sizer[0] num_days = sizer[1] - 4 # first 4 columns are state,country,lat,long # sort data by countries get_countries(entries) #print(country_list) num_countries = np.size(country_list) country_rates = np.zeros( (num_countries, num_days)) # will make this a 3 dim vector for other dat # find the rates in each country per day country_rates = get_country_rates(num_countries, entries, num_days, country_rates) sorted_country = [] for i in range(num_countries): sorted_country.append([country_list[i], country_rates[i, :]]) sorted_country_list = sorted(sorted_country, key=lambda l: float(l[1][-1]), reverse=True) #wanted = [] #for i in range(5): # wanted.append(sorted_country_list[i][0]) # wanted = ["China","Italy","US"] #global wanted_num #wanted_num = np.size(wanted) #global wanted_index #wanted_index = [0]*wanted_num #global wanted_fit_param #wanted_fit_param = np.zeros((wanted_num,3)) # determine index of wanted countries from total array get_country_index(num_countries) # resize data to start at similar times rates_resize = get_same_start(country_rates, num_days, 200) # find the fit parameters for the wanted countries x = [lis[0] for lis in rates_resize] y = [lis[1] for lis in rates_resize] for i in range(np.size(y)): # scale rate by pop density y[i] = y[i] #/ wanted_pop_density[i] get_fit_param(x, y, pl.logistic) print(wanted_fit_param) print(wanted_index) # plot wanted data with extrapolation fit if type_val[0] > 0: fig, ax = plt.subplots() for i in range(len(wanted)): title = ['Confirmed Cases', 'Days', 'Num Affected', wanted[i]] pl.scatter_plot((x[i]), y[i], title, '.') if type_val[0] == 2: num_sim = 30 modelPredictions = pl.logistic((range(num_sim)), *wanted_fit_param[i, :]) pl.scatter_plot(range(num_sim), modelPredictions, title, '-') plt.show() # get state / province data state_list = [] for i in range(entries): if confirmed_data[i][1] == 'US': # US state_list.append( [confirmed_data[i][0], i, (confirmed_data[i][4:])]) # removing cruises i = 0 while i < len(state_list): if ' Princess' in state_list[i][0]: print(state_list[i][0]) state_list.remove(state_list[i]) i -= 1 i += 1 state_list_resize = get_same_start(country_rates, num_days, 1) sorted_state_list = sorted(state_list, key=lambda l: float(l[2][-1]), reverse=True) if type_val[1] == 1: if 1 == 1: wanted_state = ["Colorado", "Oklahoma", "Arkansas"] fig, ax = plt.subplots() for i in range(50): if sorted_state_list[i][0] in wanted_state: title = [ 'Confirmed Cases', 'Days', 'Num Affected', sorted_state_list[i][0] ] x = range(num_days) y = np.array(sorted_state_list[i][2], dtype=np.float) #/ wanted_pop_density[1] pl.scatter_plot(x, y, title, '-') plt.show() if 1 == 0: fig, ax = plt.subplots() for i in range(10): title = [ 'Confirmed Cases', 'Days', 'Num Affected', sorted_state_list[i][0] ] x = range(num_days) y = np.array(sorted_state_list[i][2], dtype=np.float) #/ wanted_pop_density[1] pl.scatter_plot(x, y, title, '-') plt.show()
def main(): # Run kMC and mass-action kinetics if type_val[0] > 0: #====================== Introduce correlation into the system ======================# for ii in range(0, ncorr): corr_matrix = [[1.0, x1[ii], x2[ii]], [x1[ii], 1.0, x1_2[ii]], [x2[ii], x1_2[ii], 1.0]] # get distriubtion of energies where the DFT energy is the mean for i in range(0, nsim): for j in dist_constants: if (type_dist == 1): ea[j, i] = np.random.normal( loc=dft_ea[j], scale=sig) # gaussian distribution if (type_dist == 2): ea[j, i] = np.random.laplace( loc=dft_ea[j], scale=sig) # laplace distribution ea_diff[j, i] = ea[j, i] - dft_ea[j] for j in non_dist_constants: # these are constant rates ea[j, i] = dft_ea[j] # correlate the energies now based on corr_matrix y = tl.get_correlation(corr_matrix, ea_diff) for i in dist_constants: ea_corr[i, :, ii] = y[i, :] + dft_ea[i] for i in non_dist_constants: ea_corr[i, :, ii] = ea[i, :] # plot distribution of individual rate constants if type_val[1] == 1: names = [str(ii), str(int(10 * sig)), str(int(dft_ea[2]))] pl.distribution_plot(ea_corr) dist_nam = [type_name, 'dist', *names, '.png'] dist_namer = '_'.join([str(v) for v in dist_nam]) plt.savefig(dist_namer) turnover_dist = np.zeros(np.shape(ea_corr)) for i in range(nrxn): for j in range(nsim): turnover_dist[i, j, ii] = 1.0 / tl.get_rate_const( 1.0e13, ea_corr[i, j, ii], tl.kb_kcal, 273.15 + 50.0) # plot correlated distributions if type_val[1] == 2: for i in range(0, nrxn): for j in range(0, nrxn): if (i != j): title = [i + 1, j + 1] pl.correlation_plot( [ea[i, :], ea[j, :]], [ea_corr[i, :, ii], ea_corr[j, :, ii]], title) plt.savefig('correlation_' + str(i) + '_' + str(j) + '.png') #================================== Run klafter calculation ==================================# if type_val[0] == 2: y = (turnover_dist[1, :, ii]) #ea_un = [40.0,36.0,32.0,30.0] ea_un = [dft_ea[2]] turnover_x = np.zeros(np.size(ea_un)) turnover_rate = np.zeros((np.size(ea_un), 2)) turnover_fil = open( 'turnover_rate_0' + str(int(10 * sig)) + '.txt', "w") turnover_fil.close() turnover_fil = open( 'turnover_rate_0' + str(int(10 * sig)) + '.txt', "a") for i in range(np.size(ea_un)): turnover_rate[i] = get_turnover_freq(ea_un[i], y) turnover_x[i] = tl.get_rate_const(1.0e13, ea_un[i], tl.kb_kcal, 273.15 + 50.0) dat = np.hstack([turnover_x[i], turnover_rate[i, 0]]) np.savetxt(turnover_fil, dat, newline=" ") turnover_fil.write('\n') fig, ax = plt.subplots() title = [ 'Unbinding Effects', 'Unbinding Rate (log 10)', 'Turnover freq (log 10)', 'Fit' ] pl.scatter_plot(np.log10(turnover_x), np.log10(turnover_rate[:, 0]), title) title = [ 'Unbinding Effects', 'Unbinding Rate (log 10)', 'Turnover freq (log 10)', 'Log Normal' ] plt.savefig('turnover_0' + str(int(10 * sig)) + '.png') # make figure of all the plots if 1 == 0: sig_val = ['01', '08', '010', '013', '015', '018', '020'] turn_rate = [] fig, ax = plt.subplots() for i in sig_val: fil = open('turnover_rate_' + str(i) + '.txt', "r") dat = np.genfromtxt(fil) plt.plot(np.log10(dat[:, 0]), np.log10(dat[:, 1]), label=str(int(i) * 10 / 100)) plt.legend() plt.title('Turnover Rate vs Unbinding Rate') plt.xlabel('k$_{off}$ (log10 $s^{-1}$)') plt.ylabel('k$_{turnover}$ (log10 $s^{-1}$)') #plt.savefig('total_rates.png') plt.show() #=======================================================================================# #================================ Run over temperatures ================================# print('running sim') rate_list = [] if type_run == 1: for iii in range(0, np.size(temp_val)): job = temp_run(temp_val[iii], tend[iii], iii) rate_list.append(job) if type_run == 2: iterable = zip(temp_val, tend, range(np.size(temp_val))) with mp.Pool(num_cores) as p: rate_list = p.starmap(temp_run, iterable) #=====================================================================================# #=======================================================================================# if type_val[3] == 1: # make plots without running the sim for iii in range(0, np.size(temp_val)): for ii in range(0, np.size(x1)): names = [ str(int(temp_val[iii])), str(ii), str(int(sig)), str(int(dft_ea[2])) ] nam1 = [type_name, 'kmc', *names, '.txt'] namer1 = '_'.join([str(v) for v in nam1]) get_sim_plots(namer1, namer, names, temp_val[iii]) get_prod_rate(namer1) #=======================================================================================# if type_val[4] == 1: # arrhenius plot if type_val[2] == 1: # determine production rate from file for iii in range(0, np.size(temp_val)): for ii in range(0, ncorr): dat = np.hstack([ rate_list[iii][0], rate_list[iii][1][ii], rate_list[iii][2][0, ii], rate_list[iii][2][1, ii] ]) np.savetxt(h, dat, newline=" ") h.write('\n') if type_val[2] == 1: h.close() rate_data = np.genfromtxt(namer0, delimiter=' ') temps = rate_data[0::3, 0] print('temps', temps) prod_rate = [ rate_data[0::3, 2:], rate_data[1::3, 2:], rate_data[2::3, 2:] ] print(np.shape(prod_rate)) pl.arrhenius_plot(temps, prod_rate) plt.savefig('arrhenius.png')
model = RandomForestRegressor(n_estimators=50, max_depth=10, min_samples_leaf=5, max_features="sqrt", random_state=42, n_jobs=1) model.fit(X, components.drop(columns="Data")) # collect and sort feature importance importance = pd.DataFrame({ "name": X.columns, "importance": model.feature_importances_ }) importance = importance.sort_values(by="importance", ascending=False).reset_index(drop=True) # choose how many features to plot num_features = 10 features = importance.loc[:(num_features - 1), "name"].tolist() # plot the variables vs. components comp_ = 0 # the column number of a component to plot for c in features: scatter_plot(data=data, x=c, y=components.columns[comp_], color=None, title="Isomap", legend=True, save=False)
def main(argv): settings.init() # Call only once print("Start Deepov tuning v0.2") #TODO make a useful main function # Define global variables that will contain the cutechess configuration if argv is None: argv = sys.argv[1:] args=createParser() # print("List of arguments\n") # print(args) # Store the run configuration settings.main_command,settings.main_config=cutechessConfig(args) # if args.verbosity: # print('Sending command to cutechess :') # print(settings.main_command+settings.main_config) # print('\n') # No input parameters ( for test purpose ) if args.name is None: if args.verbosity: print("#WARNING : No input parameters.") command = settings.main_command+settings.main_config runCutechess(command) return 0 paramList=initParameters(args) if args.verbosity: print("List of parameters : ") print(paramList) # Choose method print("Initial empty dataset") print(settings.dataset) # Execute method print(settings.main_command+settings.main_config) # Ensure method is an interger args.method = int(args.method) if (args.method==0): # brute force (opt_gridSearch) best,elo=opt_gridSearch(paramList) # Display resultes print("Best set of values is {}".format(best)) print("Elo improvement is {}".format(elo)) # Display the stored dataset print(settings.dataset) plots.scatter_plot(0) elif (args.method==1): scipy_res=opt_differential_evolution(paramList) print(scipy_res) elif (args.method==2): scipy_res=opt_basinhopping(paramList) print(scipy_res) else: print("#WARNING> Not a valid optimization method.") # if args.verbosity: # print(results) ??? return 0