Exemplo n.º 1
0
# Make random matrices for speed testing

import scipy.io
import numpy as np
from generalize_ising_model.core import generalized_ising
import time
import matplotlib.pyplot as plt
import collections
from generalize_ising_model.ising_utils import distance_wei, to_normalize, 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

dir_output_name = '/home/user/Desktop/phiTest/speedTest'

size = int(input('Matrix size?'))
output_path = dir_output_name + '/' + 'phi/' + str(size) + '/'
makedir(output_path)

Jij = save_graph(output_path + 'Jij_' + str(size) + '.csv',
                 to_generate_randon_graph(size, isolate=False, weighted=True))

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

makedir(dir_output_name)

#i_l = []
#j_l = []
Exemplo n.º 2
0
# 'VIM': [4, 20, 12, 9, 73],
# 'VIO': [20, 10, 12, 4, 6]}

d = collections.OrderedDict(sorted(rsn_index.items()))
Jij = Jij['meanJ_prob']

D, B = distance_wei(1. / Jij)

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

makedir(dir_output_name)

for key, value in d.items():

    i_l = []
    j_l = []
    for v in value:
        for w in value:
            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)))
Exemplo n.º 3
0
import numpy as np
from networkx.utils import *
import os
from generalize_ising_model.ising_utils import save_graph, makedir

path_input = '/home/brainlab/Desktop/Rudas/Data/Ising/'
simulation_name = 'experiment_2'
default_size = 40
default_no_entities = 5

path_output_data = path_input + simulation_name

makedir(path_input + simulation_name)

# Degree
path_outputexp_degree = path_output_data + '/degree/'
if not os.path.exists(path_outputexp_degree):
    os.mkdir(path_outputexp_degree)

degrees_expected = np.linspace(5, 35, num=20).astype(np.int8)

for degree in degrees_expected:
    path_output_data_degree = path_outputexp_degree + 'degree_' + str(degree)
    if not os.path.exists(path_output_data_degree):
        os.mkdir(path_output_data_degree)

    for entity in range(default_no_entities):
        path_output_data_degree_entity = path_output_data_degree + '/' + 'entity_' + str(entity)
        if not os.path.exists(path_output_data_degree_entity):
            os.mkdir(path_output_data_degree_entity)
Exemplo n.º 4
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 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!')
Exemplo n.º 5
0
from generalize_ising_model.ising_utils import save_graph, makedir
import networkx as nx

default_size = 40
default_no_entities = 20
dim = 3

path_input = '/home/brainlab/Desktop/Rudas/Data/Ising/experiment_2/'

path_output_data = path_input + 'geometrics/'
makedir(path_output_data)

#Random geometric graph
path_output_data_type = path_output_data + 'geometricxxx_' + str(dim) + '/'
makedir(path_output_data_type)

for i in range(default_no_entities):

    while True:
        G = nx.random_geometric_graph(default_size, 0.2, dim=dim)
        if len(list(nx.isolates(G))) == 0:
            break

    makedir(path_output_data_type + 'entity_' + str(i))
    save_graph(path_output_data_type + 'entity_' + str(i) + '/' + 'J_ij.csv',
               G)
Exemplo n.º 6
0
from natsort import natsorted
from generalize_ising_model.ising_utils import makedir
from dipy.io.streamline import save_trk, load_trk
import nibabel as nib
from dipy.tracking.utils import connectivity_matrix
import matplotlib
import numpy as np
from nilearn import plotting

parcellations_path = '/home/brainlab/Desktop/rsn_parcellations/'
subjects_path = '/home/brainlab/Desktop/Rudas/Data/testkokokoko/subjects/'
output_path = '/home/brainlab/Desktop/Rudas/Data/testkokokoko/output/'

for subject in natsorted(os.listdir(subjects_path)):
    print(subject)
    makedir(output_path + subject)
    trk_file = nib.streamlines.load(subjects_path + subject + '/' + 'tractography.trk', lazy_load=True)

    for network in natsorted(os.listdir(parcellations_path)):
        print(network)
        makedir(output_path + subject + '/' + network)
        for size in natsorted(os.listdir(parcellations_path + network)):
            print(size)
            makedir(output_path + subject + '/' + network + '/' + size)
            parcellation_img = nib.load(parcellations_path + network + '/' + size)
            parcellation_data = parcellation_img.get_data()
            parcellation_affine = parcellation_img.affine

            M, grouping = connectivity_matrix(trk_file.streamlines, parcellation_data, affine=trk_file.affine,
                                              return_mapping=True,
                                              mapping_as_streamlines=True)
        thermalize_time=thermalize_time,
        external_field=external_field_sin_all[:, i_ef])
    f.add_subplot(2, 2, 1)
    plt.plot(ts, E1, marker='o', color=colors[i_ef])
    plt.xlabel("Temperature (T)", fontsize=20)
    plt.ylabel("Energy ", fontsize=20)
    plt.axis('tight')

    f.add_subplot(2, 2, 2)
    plt.plot(ts, abs(M1), marker='o', color=colors[i_ef])
    plt.xlabel("Temperature (T)", fontsize=20)
    plt.ylabel("Magnetization ", fontsize=20)
    plt.axis('tight')

    f.add_subplot(2, 2, 3)
    plt.plot(ts, H1, marker='o', color=colors[i_ef])
    plt.xlabel("Temperature (T)", fontsize=20)
    plt.ylabel("Specific Heat", fontsize=20)
    plt.axis('tight')

    f.add_subplot(2, 2, 4)
    plt.plot(ts, S1, marker='o', color=colors[i_ef])
    plt.xlabel("Temperature (T)", fontsize=20)
    plt.ylabel("Susceptibility", fontsize=20)
    plt.axis('tight')

plt.show()
makedir(path_output)
save_results(temperature_parameters, J, E, M, S, H, simulated_fc,
             critical_temperature, path_output)