import numpy as np
import time
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')
from projects.generalize_ising_model.tools.utils import to_normalize, save_results, makedir
import os
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

path_input = '/home/brainlab/Desktop/Rudas/Data/Ising/HCP/data/hcp_mean/J_ij.csv'
path_output = '/home/brainlab/Desktop/Rudas/Data/Ising/HCP/data/hcp_mean/results/'

# Ising Parameters
temperature_parameters = (
    0.05, 5, 5
)  # Temperature parameters (initial tempeture, final tempeture, number of steps)
no_simulations = 150  # Number of simulation after thermalization
thermalize_time = 0.3  #

J = to_normalize(np.loadtxt(path_input, delimiter=','))

ts = np.linspace(temperature_parameters[0],
                 temperature_parameters[1],
                 num=temperature_parameters[2])
colors = ['red', 'green', 'black', 'blue', 'purple']

f = plt.figure(figsize=(18, 10))  # plot the calculated values

simulated_fc, critical_temperature, E, M, S, H = generalized_ising(
    J,
    temperature_parameters=temperature_parameters,
    no_simulations=no_simulations,
    thermalize_time=thermalize_time)

makedir(path_output)
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)
示例#4
0
main_path = '/home/brainlab/Desktop/Popiel/Ising_HCP/'

parcels = ['Aud', 'CinguloOperc', 'CinguloParietal', 'DMN', 'Dorsal', 'FrontoParietal', 'Retrosplenial', 'SMhand',
           'SMmouth', 'Ventral', 'Visual']


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)
示例#5
0
    for dir in natsorted(os.listdir((path_input_aux + '/' + dirs))):
        print(dir)
        print(''.join('*' * no_temperature))

        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)

        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=','))

                #temperature_parameters = (0.05, 5, no_temperature)  # Temperature parameters (initial tempeture, final tempeture, number of steps)

                if not os.path.exists(dir_output_name_case_exp + '/' +
                                      'parameters.pkl'):
                    temperature_parameters = (
                        0.005, J.shape[-1] * (np.mean(J) + 0.45),
                        no_temperature
                    )  # Temperature parameters (initial tempeture, final tempeture, number of steps)
                    #temperature_parameters = (0.005, 8, no_temperature)  # Temperature parameters (initial tempeture, final tempeture, number of steps)
                    output = open(
                        dir_output_name_case_exp + '/' + 'parameters.pkl',
                        'wb')
                    pickle.dump(