def run_simulation_NET(tauE_, wE_, tauI_, wI_, Group, Target, G_CPU1A, G_CPU1B,
                       G_PONTINE, G_MOTOR, S_TB1_CPU4, S_TN2_CPU4, S_TB1_CPU1A,
                       S_CPU4_PONTINE, S_CPU4_CPU1A, S_PONTINE_CPU1A,
                       S_TB1_CPU1B, S_CPU4_CPU1B, S_PONTINE_CPU1B,
                       S_CPU1A_MOTOR, S_CPU1B_MOTOR, time, dt_, delta,
                       rate_correction):

    restore('initialised')

    # set the parameters
    Group.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})
    print(f'taueE: {tauE_} - tauI {tauI_}')
    G_CPU1A.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})
    G_CPU1B.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})
    G_PONTINE.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})
    G_MOTOR.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})

    S_TB1_CPU4.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_TN2_CPU4.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_TB1_CPU1A.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU4_PONTINE.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU4_CPU1A.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_PONTINE_CPU1A.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_TB1_CPU1B.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU4_CPU1B.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_PONTINE_CPU1B.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU1A_MOTOR.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU1B_MOTOR.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})

    print(f'wE: {wE_} - wI {wI_}')

    _, model_spike_monitor_CPU4 = nc.add_monitors(Group)
    target_spike_monitor_CPU4 = SpikeMonitor(Target,
                                             name='CPU4_target_spike_monitor')

    _, model_spike_monitor_motor = nc.add_monitors(G_MOTOR)
    target_spike_monitor_motor = SpikeMonitor(
        Target, name='MOTOR_target_spike_monitor')

    run(time)

    gf_CPU4 = metric.compute_gamma_factor(model_spike_monitor_CPU4,
                                          target_spike_monitor_CPU4,
                                          time,
                                          dt_=dt_,
                                          delta=delta,
                                          rate_correction=rate_correction)
    gf_motor = metric.compute_gamma_factor(model_spike_monitor_motor,
                                           target_spike_monitor_motor,
                                           time,
                                           dt_=dt_,
                                           delta=delta,
                                           rate_correction=rate_correction)

    print(f'Gamma factor: {gf_CPU4} - {gf_motor}')

    gf = gf_CPU4 + gf_motor
    return gf
def run_simulation_TL2(tauE_, wE_, tauI_, wI_, Group, Synapses, Target, time,
                       dt_, delta, rate_correction):
    restore('initialised')

    # set the parameters
    Group.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})
    print(f'taueE: {tauE_} - tauI {tauI_}')

    Synapses.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    print(f'wE: {wE_} - wI {wI_}')

    _, model_spike_monitor = nc.add_monitors(Group)
    target_spike_monitor = SpikeMonitor(Target,
                                        name='TL2_target_spike_monitor')

    run(time)

    gf = metric.compute_gamma_factor(model_spike_monitor,
                                     target_spike_monitor,
                                     time,
                                     dt_=dt_,
                                     delta=delta,
                                     rate_correction=rate_correction)

    print(f'Gamma factor: {gf}')

    return gf
def run_simulation_NET(net, cx_log, tauE_, wE_, tauI_, wI_, Group, Target,
                       G_CPU1A, G_CPU1B, G_PONTINE, G_MOTOR, S_TB1_CPU1A,
                       S_CPU4_M_PONTINE, S_CPU4_M_CPU1A, S_PONTINE_CPU1A,
                       S_TB1_CPU1B, S_CPU4_M_CPU1B, S_PONTINE_CPU1B,
                       S_CPU1A_MOTOR, S_CPU1B_MOTOR, time, dt_, delta,
                       rate_correction):

    net.restore('initialised')
    global CPU4_memory, CPU4_memory_history, CPU4_memory_stimulus

    # set the parameters
    Group.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})
    print(f'taueE: {tauE_} - tauI {tauI_}')
    G_CPU1A.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})
    G_CPU1B.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})
    G_PONTINE.set_states({'tauE': tauE_ * ms, 'tauI': tauI_ * ms})
    #G_MOTOR.set_states({'tauE' : tauE_*ms, 'tauI' : tauI_*ms})

    S_TB1_CPU1A.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_TB1_CPU1B.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU4_M_PONTINE.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU4_M_CPU1A.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU4_M_CPU1B.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_PONTINE_CPU1A.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_PONTINE_CPU1B.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU1A_MOTOR.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})
    S_CPU1B_MOTOR.set_states({'wE': wE_ * nS, 'wI': wI_ * nS})

    print(f'wE: {wE_} - wI {wI_}')

    model_spike_monitor_motor = SpikeMonitor(Group,
                                             name='MOTOR_source_spike_monitor')
    target_spike_monitor_motor = SpikeMonitor(
        Target, name='MOTOR_target_spike_monitor')

    net.add(model_spike_monitor_motor, target_spike_monitor_motor)
    net.run(time)

    if np.sum(model_spike_monitor_motor.count) == 0 or np.sum(
            target_spike_monitor_motor.count) == 0:
        print('model count = ', model_spike_monitor_motor.count)
        print('target count = ', target_spike_monitor_motor.count)
        gf_motor = 10000
    else:
        gf_motor = metric.compute_gamma_factor(model_spike_monitor_motor,
                                               target_spike_monitor_motor,
                                               time,
                                               dt_=dt_,
                                               delta=delta,
                                               rate_correction=rate_correction)

    motors_rate_model = cx_spiking.inputs.compute_motors(cx_log.cpu1)
    rotations_rate_model = np.sign(motors_rate_model[0, :1500] -
                                   motors_rate_model[1, :1500])

    MOTOR_spikes = cx_spiking.inputs.get_spikes_rates(
        target_spike_monitor_motor, 2, 1500, 20)
    rotations_spike_model = np.sign(
        (MOTOR_spikes[0, :1500] - MOTOR_spikes[1, :1500]))

    measure = np.sum(np.abs(rotations_rate_model - rotations_spike_model))

    net.remove(model_spike_monitor_motor, target_spike_monitor_motor)
    print(f'Gamma factor: {gf_motor} - {measure}')

    gf = gf_motor
    return gf