void sync_network::calculate_phases(const solve_type solver, const double t, const double step, const double int_step) { std::vector<double> next_phases(size(), 0); std::vector<void *> argv(2, NULL); argv[0] = (void *) this; unsigned int number_int_steps = (unsigned int) (step / int_step); for (unsigned int index = 0; index < size(); index++) { argv[1] = (void *) &index; switch(solver) { case solve_type::FAST: { double result = m_oscillators[index].phase + phase_kuramoto(t, m_oscillators[index].phase, argv); next_phases[index] = phase_normalization(result); break; } case solve_type::RK4: { differ_state<double> inputs(1, m_oscillators[index].phase); differ_result<double> outputs; runge_kutta_4(m_callback_solver, inputs, t, t + step, number_int_steps, false, argv, outputs); next_phases[index] = phase_normalization( outputs[0].state[0] ); break; } case solve_type::RKF45: { differ_state<double> inputs(1, m_oscillators[index].phase); differ_result<double> outputs; runge_kutta_fehlberg_45(m_callback_solver, inputs, t, t + step, 0.00001, false, argv, outputs); next_phases[index] = phase_normalization( outputs[0].state[0] ); break; } default: { throw std::runtime_error("Unknown type of solver"); } } } /* store result */ for (unsigned int index = 0; index < size(); index++) { m_oscillators[index].phase = next_phases[index]; } }
void legion_network::calculate_states(const legion_stimulus & stimulus, const solve_type solver, const double t, const double step, const double int_step) { std::vector<void *> argv(2, NULL); std::vector<differ_result<double> > next_states(size()); argv[0] = (void *) this; unsigned int number_int_steps = (unsigned int) (step / int_step); for (unsigned int index = 0; index < size(); index++) { argv[1] = (void *) &index; differ_state<double> inputs { m_oscillators[index].m_excitatory, m_oscillators[index].m_inhibitory }; if (m_params.ENABLE_POTENTIAL) { inputs.push_back(m_oscillators[index].m_potential); } switch(solver) { case solve_type::FAST: { throw std::runtime_error("Forward Euler first-order method is not supported due to low accuracy."); } case solve_type::RK4: { if (m_params.ENABLE_POTENTIAL) { runge_kutta_4(&legion_network::adapter_neuron_states, inputs, t, t + step, number_int_steps, false /* only last states */, argv, next_states[index]); } else { runge_kutta_4(&legion_network::adapter_neuron_simplify_states, inputs, t, t + step, number_int_steps, false /* only last states */, argv, next_states[index]); } break; } case solve_type::RKF45: { if (m_params.ENABLE_POTENTIAL) { runge_kutta_fehlberg_45(&legion_network::adapter_neuron_states, inputs, t, t + step, 0.00001, false /* only last states */, argv, next_states[index]); } else { runge_kutta_fehlberg_45(&legion_network::adapter_neuron_simplify_states, inputs, t, t + step, 0.00001, false /* only last states */, argv, next_states[index]); } break; } default: { throw std::runtime_error("Unknown type of solver"); } } std::vector<unsigned int> * neighbors = get_neighbors(index); double coupling = 0.0; for (std::vector<unsigned int>::const_iterator index_neighbor_iterator = neighbors->begin(); index_neighbor_iterator != neighbors->end(); index_neighbor_iterator++) { coupling += m_dynamic_connections[index][*index_neighbor_iterator] * heaviside(m_oscillators[*index_neighbor_iterator].m_excitatory - m_params.teta_x); } delete neighbors; m_oscillators[index].m_buffer_coupling_term = coupling - m_params.Wz * heaviside(m_global_inhibitor - m_params.teta_xz); } differ_result<double> inhibitor_next_state; differ_state<double> inhibitor_input { m_global_inhibitor }; switch (solver) { case solve_type::RK4: { runge_kutta_4(&legion_network::adapter_inhibitor_state, inhibitor_input, t, t + step, number_int_steps, false /* only last states */, argv, inhibitor_next_state); break; } case solve_type::RKF45: { runge_kutta_fehlberg_45(&legion_network::adapter_inhibitor_state, inhibitor_input, t, t + step, 0.00001, false /* only last states */, argv, inhibitor_next_state); break; } } m_global_inhibitor = inhibitor_next_state[0].state[0]; for (unsigned int i = 0; i < size(); i++) { m_oscillators[i].m_excitatory = next_states[i][0].state[0]; m_oscillators[i].m_inhibitory = next_states[i][0].state[1]; if (m_params.ENABLE_POTENTIAL) { m_oscillators[i].m_potential = next_states[i][0].state[2]; } m_oscillators[i].m_coupling_term = m_oscillators[i].m_buffer_coupling_term; m_oscillators[i].m_noise = m_noise_distribution(m_generator); } }