from nest_elephant_tvb.Tvb import tvb_sim
import numpy as np
import numpy.random as rgn

weight = np.array([[5,2,4,0],[8,5,4,1],[6,1,7,9],[10,0,5,6]])
delay = np.array([[0.1,0.1,0.1,0.1],[0.1,0.1,0.1,0.1],[0.1,0.1,0.1,0.1],[0.1,0.1,0.1,0.1]])*10
init_value = np.array([[0.1,0.1,0.2,0.2]]*2)
initial_condition = init_value.reshape(2,1,weight.shape[0],1)
resolution_simulation = 0.1
time_synchronize = 0.1*10
proxy_id =  [0,1,2]
not_proxy_id = np.where(np.logical_not(np.isin(np.arange(0,weight.shape[0],1), proxy_id)))[0]

# full simulation
rgn.seed(42)
sim_ref = tvb_sim(weight, delay,[], resolution_simulation, time_synchronize,initial_condition=initial_condition)
time,result_ref = sim_ref(time_synchronize)
delai_input = [time,result_ref[:,proxy_id][:,:,0]]

# simulation with one or more proxy
rgn.seed(42)
sim = tvb_sim(weight, delay,proxy_id, resolution_simulation,time_synchronize,initial_condition=initial_condition)
time,result = sim(time_synchronize,delai_input)

diff = np.where(np.squeeze(result_ref,axis=2)[0] != np.squeeze(result,axis=2)[0])
if diff[0].size != 0:
    print("Fail S compare")
    print(diff)
    print(result_ref)
    print(result)
else:
Beispiel #2
0
import numpy.random as rgn

weight = np.array([[5, 2, 4, 0], [8, 5, 4, 1], [6, 1, 7, 9], [10, 0, 5, 6]])
delay = np.array([[7, 8, 5, 1], [0, 3, 7, 9], [4, 3, 2, 8], [9, 10, 11, 5]])
resolution_simulation = 0.1
time_synchronize = 0.1 * 10
proxy_id_1 = [1]
not_proxy_id_1 = np.where(
    np.logical_not(np.isin(np.arange(0, weight.shape[0], 1), proxy_id_1)))[0]
proxy_id_2 = [0, 2]
not_proxy_id_2 = np.where(
    np.logical_not(np.isin(np.arange(0, weight.shape[0], 1), proxy_id_2)))[0]

# full simulation
rgn.seed(42)
sim_ref = tvb_sim(weight, delay, [], resolution_simulation, time_synchronize)
time, result_ref = sim_ref(time_synchronize)

# simulation with one proxy
rgn.seed(42)
sim_1 = tvb_sim(weight, delay, proxy_id_1, resolution_simulation,
                time_synchronize)
time, result_1 = sim_1(time_synchronize,
                       [time, result_ref[:, proxy_id_1][:, :, 0]])

# simulation_2 with one proxy
rgn.seed(42)
sim_2 = tvb_sim(weight, delay, proxy_id_2, resolution_simulation,
                time_synchronize)
time, result_2 = sim_2(time_synchronize,
                       [time, result_1[:, proxy_id_2][:, :, 0]])
Beispiel #3
0
# "Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements; and to You under the Apache License, Version 2.0. "

from nest_elephant_tvb.Tvb import tvb_sim
import numpy as np

weight = np.array([[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]])
delay = np.array([[1.5, 1.5, 1.5, 1.5], [1.5, 1.5, 1.5, 1.5],
                  [1.5, 1.5, 1.5, 1.5], [1.5, 1.5, 1.5, 1.5]])
resolution_simulation = 0.1
time_synchronize = 1.0
proxy_id = [0, 1]
firing_rate = np.array(
    [[20.0, 10.0]]) * 10**-3  # units time in tvb is ms so the rate is in KHz

# Test the the update function
sim = tvb_sim(weight, delay, proxy_id, resolution_simulation, time_synchronize)
time, result = sim(resolution_simulation,
                   [np.array([resolution_simulation]), firing_rate])
for i in range(0, 100):
    time, result = sim(time_synchronize, [
        np.arange(i * time_synchronize,
                  (i + 1) * time_synchronize, resolution_simulation),
        np.repeat(firing_rate.reshape(1, 2),
                  int(time_synchronize / resolution_simulation),
                  axis=0)
    ])
print('test succeeds')

# Test a fail function due to the time of simulation too long
try:
    sim(time_synchronize, [np.array([resolution_simulation]), firing_rate])