fc_empirical_path = '/home/brainlab/Desktop/Rudas/Scripts/ising/hcp_84_fc.csv' # Ising Parameters temperature_parameters = ( 0.002, 3, 50 ) # Temperature parameters (initial tempeture, final tempeture, number of steps) no_simulations = 1200 # Number of simulation after thermalization thermalize_time = 0.3 # J = to_normalize(np.loadtxt(path_input, delimiter=',')) fc = np.loadtxt(fc_empirical_path, delimiter=',') a_simulated_fc, a_critical_temperature, a_E, a_M, a_S, a_H = generalized_ising( J, temperature_parameters=temperature_parameters, n_time_points=no_simulations, thermalize_time=thermalize_time, phi_variables=False, type='analogy') to_save_results(temperature_parameters, J, a_E, a_M, a_S, a_H, a_simulated_fc, a_critical_temperature, '/home/brainlab/Desktop/new_test/a/') d_simulated_fc, d_critical_temperature, d_E, d_M, d_S, d_H = generalized_ising( J, temperature_parameters=temperature_parameters, n_time_points=no_simulations, thermalize_time=thermalize_time, phi_variables=False, type='digital')
#fetch the Jij csv file J = to_normalize(np.loadtxt(input_path + file_name)) # Ising Parameters temperature_parameters = ( 0.002, 3, 50 ) # Temperature parameters (initial tempeture, final temperature, number of steps) no_simulations = 1200 # Number of simulations after thermalization thermalize_time = 0.3 # start_time = time.time() Simulated_FC, Critical_Temperature, E, M, S, H, Mean_Spin, time_course = generalized_ising( J, temperature_parameters=temperature_parameters, n_time_points=no_simulations, thermalize_time=thermalize_time, phi_variables=True, return_tc=True, type="digital") final_time = time.time() delta_time = final_time - start_time print("It took " + str(delta_time) + " seconds to calculate the simulated functional connectivity matricies") #Making the TPM based on the GIM empirical_tpm_concat_sbys(time_course, output_path + "TPM_list")
dim_list = [] hubs_list = [] for tpm_index in range(totalMatrix.shape[2]): tpm_ = totalMatrix[i, condition, tpm_index, ...] hist, bin_edges = np.histogram(tpm_index, number_bins) hist = hist / np.sum(tpm_) S_list.append(entropy(hist)) D_list.append(nx.density(nx.Graph(tpm_))) simulated_fc, critical_temperature, E, M, S, H = generalized_ising( tpm_, temperature_parameters=temperature_parameters, n_time_points=1200, thermalize_time=0.3, temperature_distribution='lineal', phi_variables=False, type='digital') c, r = correlation_function(simulated_fc, tpm_) dimensionality = dim(c, r, find_nearest(ts, critical_temperature)) dim_list.append(dimensionality) h = nx.hits(nx.Graph(tpm_))[0] hubs_list.append([value for key, value in h.items()]) S_conditions.append(S_list) den_conditions.append(D_list)
from projects.generalize_ising_model.core import generalized_ising from projects.generalize_ising_model.tools.utils import to_save_results,to_generate_random_graph,to_normalize,save_graph sizes = [250]#[250,500] main_path = '/home/user/Desktop/Popiel/check_ising/' temperature_params = [(np.log10(75),150,50)]#[(1.3,200,50),(1.8,600,50)]# Params for 5,10,25,100 (-3,4,50),(-1,8,50),[(0,20,50)] (1,100,50), no_simulations = 4000 thermalize_time =0.3 for ind, size in enumerate(sizes): save_path = main_path + str(size) + '/' J = save_graph(save_path + 'Jij_' + str(size) + '.csv', to_normalize(to_generate_random_graph(size, isolate=False, weighted=True),netx=True)) # Ising Parameters temperature_parameters = temperature_params[ind] # Temperature parameters (initial tempeture, final tempeture, number of steps) start_time = time.time() print('Fitting Generalized Ising model for a ', size, ' by', size, ' random matrix.') simulated_fc, critical_temperature, E, M, S, H = generalized_ising(J, temperature_parameters=temperature_parameters, n_time_points=no_simulations, thermalize_time=thermalize_time, temperature_distribution='log') to_save_results(temperature_parameters, J, E, M, S, H, simulated_fc, critical_temperature, save_path, temperature_distribution='log') print('It took ', time.time() - start_time, 'seconds to fit the generalized ising model')
for parcel in parcels: print('Running', parcel) parcel_path = main_path + parcel + '/' #results_path = sub_path + 'results/' save_path = parcel_path + '/results/' makedir(save_path) if not file_exists(save_path + 'phi.csv'): Jij = to_normalize(load_matrix(parcel_path + 'Jij_avg.csv')) start_time = time.time() simulated_fc, critical_temperature, E, M, S, H, spin_mean, tc = generalized_ising(Jij, temperature_parameters=temperature_parameters, n_time_points=n_time_points, thermalize_time=thermalize_time, phi_variables=True, return_tc=True) print('It took ',time.time()-start_time, 'seconds to fit the generalized Ising model') makedir(save_path) to_save_results(temperature_parameters, Jij, E, M, S, H, simulated_fc, critical_temperature, save_path) save_file(spin_mean,save_path,'spin_mean') save_file(tc,save_path,'time_course') ts = np.linspace(temperature_parameters[0], temperature_parameters[1], temperature_parameters[2]) phi_temperature, phi_sum, phi_sus = [], [], [] cont = 0
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 projects.generalize_ising_model.core import generalized_ising import time from projects.generalize_ising_model.tools.utils import to_save_results, makedir, to_generate_randon_graph, save_graph from projects.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!')
temperature_parameters = (0.05, 1, 100) # Temperature parameters (initial tempeture, final tempeture, number of steps) no_simulations = 250 # Number of simulation after thermalization thermalize_time = 0.3 # dir_output_name = path_input + 'simulation_' + simulation_name for root, dirs, files in walk(path_input + 'data/'): if not os.path.exists(dir_output_name): os.mkdir(dir_output_name) np.save(dir_output_name + '/' + 'parameters', {'temperature_parameters': temperature_parameters, 'no_simulations': no_simulations, 'thermalize_time': thermalize_time}) for dir in sorted(dirs): print(dir) print (''.join('*' * temperature_parameters[2])) sub_dir_output_name = dir_output_name + '/' + dir + '/' if not os.path.exists(sub_dir_output_name): os.mkdir(sub_dir_output_name) J = to_normalize(np.loadtxt(root + dir + '/' + 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) to_save_results(temperature_parameters, J, E, M, S, H, simulated_fc, critical_temperature, sub_dir_output_name)
pickle.dump( { 'temperature_parameters': temperature_parameters, 'no_simulations': no_simulations, 'thermalize_time': thermalize_time }, output) output.close() else: print('Reading parameters') pkl_file = open( dir_output_name_case_exp + '/' + 'parameters.pkl', 'rb') temperature_parameters = pickle.load( pkl_file)['temperature_parameters'] pkl_file.close() 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, type='digital') 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) #gc.collect()