dir_output_name_case = dir_output_name+ '/' + dirs + '/' if not os.path.exists(dir_output_name_case): os.mkdir(dir_output_name_case) for dir in natsorted(os.listdir((path_input_aux + '/' + dirs))): print(dir) print (''.join('*' * temperature_parameters[2])) dir_output_name_case_exp = dir_output_name_case + '/' + dir if not os.path.exists(dir_output_name_case_exp): os.mkdir(dir_output_name_case_exp) output = open(dir_output_name_case_exp + '/' + 'parameters.pkl', 'wb') pickle.dump({'temperature_parameters': temperature_parameters, 'no_simulations': no_simulations, 'thermalize_time': thermalize_time}, output) output.close() for entity in natsorted(os.listdir((path_input_aux + dirs + '/' + dir))): sub_dir_output_name = dir_output_name_case_exp + '/' + entity + '/' if not os.path.exists(sub_dir_output_name): J = to_normalize(np.loadtxt(path_input_aux + dirs + '/' + dir + '/' + entity + '/' + default_Jij_name, delimiter=',')) start_time = time.time() simulated_fc, critical_temperature, E, M, S, H = generalized_ising(J, temperature_parameters=temperature_parameters, no_simulations=no_simulations, thermalize_time=thermalize_time) print(time.time() - start_time) os.mkdir(sub_dir_output_name) to_save_results(temperature_parameters, J, E, M, S, H, simulated_fc, critical_temperature, sub_dir_output_name)
def phi_sim_save(size, output_directory,count,temperature_parameters=(-1,5,50), no_simulations=500, thermalize_time=0.3): import numpy as np from generalize_ising_model.core import generalized_ising import time from generalize_ising_model.ising_utils import to_save_results, makedir, \ to_generate_randon_graph, save_graph from generalize_ising_model.phi_project.utils import to_estimate_tpm_from_ising_model, to_calculate_mean_phi, \ to_save_phi makedir(output_directory + '/phi/') makedir(output_directory + '/ising/') size = int(size) output_path_phi = output_directory + '/' + 'phi/' + str(count) + '/' output_path_ising = output_directory + '/' + 'ising/' + str(count) + '/' if makedir(output_path_ising) and makedir(output_path_phi): J = save_graph(output_path_phi + 'Jij_' + str(count) + '.csv', to_generate_randon_graph(size, isolate=False, weighted=True)) # Ising Parameters temperature_parameters = temperature_parameters # Temperature parameters (initial tempeture, final tempeture, number of steps) no_simulations = no_simulations # Number of simulation after thermalization thermalize_time = thermalize_time # start_time = time.time() print('Fitting Generalized Ising model for a ', size, ' by', size, ' random matrix.') simulated_fc, critical_temperature, E, M, S, H, spin_mean = generalized_ising(J, temperature_parameters=temperature_parameters, no_simulations=no_simulations, thermalize_time=thermalize_time, temperature_distribution='log') to_save_results(temperature_parameters, J, E, M, S, H, simulated_fc, critical_temperature, output_path_ising, temperature_distribution='log') print('It took ', time.time() - start_time, 'seconds to fit the generalized ising model') print('Computing Phi for random ' + str(size) + ' by ' + str(size) + ' matrix') ts = np.logspace(temperature_parameters[0], np.log10(temperature_parameters[1]), temperature_parameters[2]) phi_temperature, phi_sum, phi_sus = [], [], [] cont = 0 start_time = time.time() for t in ts: # print('Temperature: ' + str(t)) tpm, fpm = to_estimate_tpm_from_ising_model(J, t) phi_, phiSum, phiSus = to_calculate_mean_phi(fpm, spin_mean[:, cont], t) phi_temperature.append(phi_) phi_sum.append(phiSum) phi_sus.append(phiSus) cont += 1 to_save_phi(ts, phi_temperature, phi_sum, phi_sus, S, critical_temperature, size, output_path_phi) print('It takes ', time.time() - start_time, 'seconds to compute phi for a ', size, 'by', size, ' random matrix.') else: print(str(count) + ' is already done!')
i_l.append(v - 1) j_l.append(w - 1) J = 1. / D[i_l, j_l] J[J == np.inf] = 0 J[J == -np.inf] = 0 J = J / np.max(J) J = np.reshape(J, (len(value), len(value))) J = to_normalize(J) start_time = time.time() print('Fitting Generalized ising model') simulated_fc, critical_temperature, E, M, S, H, spin_mean = generalized_ising( J, temperature_parameters=temperature_parameters, no_simulations=no_simulations, thermalize_time=thermalize_time, temperature_distribution='log') sub_dir_output_name = dir_output_name + '/' + key + '/' makedir(dir_output_name + '/' + key) to_save_results(temperature_parameters, J, E, M, H, S, simulated_fc, critical_temperature, sub_dir_output_name) print(time.time() - start_time) start_time = time.time() print('Computing Phi for: ' + key) #ts = np.linspace(temperature_parameters[0], temperature_parameters[1], temperature_parameters[2]) ts = np.logspace(temperature_parameters[0], np.log10(temperature_parameters[1]),
dir_output_name = path_input + 'simulation' if not os.path.exists(dir_output_name): os.mkdir(dir_output_name) path_input_aux = path_input + 'data/' for dirs in natsorted(os.listdir(path_input_aux)): dir_output_name_case = dir_output_name + '/' + dirs + '/' print(dirs) J = to_normalize( np.loadtxt(path_input_aux + dirs + '/' + default_Jij_name, delimiter=',')) temperature_parameters = ( 0.002, 3, no_temperature ) # Temperature parameters (initial tempeture, final tempeture, number of steps) start_time = time.time() simulated_fc, critical_temperature, E, M, S, H = generalized_ising( J, temperature_parameters=temperature_parameters, n_time_points=no_simulations, thermalize_time=thermalize_time, phi_variables=False) print(time.time() - start_time) os.mkdir(dir_output_name_case) save_results(temperature_parameters, J, E, M, S, H, simulated_fc, critical_temperature, dir_output_name_case) gc.collect()