32#include <unordered_map>
36#include <boost/multi_index/hashed_index.hpp>
37#include <boost/multi_index/member.hpp>
38#include <boost/multi_index_container.hpp>
72template <
class SynapseType>
92 using Synapse = std::tuple<SynapseParameters, size_t, size_t>;
104 template <
typename SynapseT>
118 template <
template <
typename>
typename Rule,
typename SynapseT>
124 enum class ProcessingType
139 using ContainerType = std::unordered_map<core::UID, ProcessingType, core::uid_hash>;
143 ContainerType stdp_populations_;
148 knp::synapse_traits::shared_synapse_parameters<knp::synapse_traits::STDP<Rule, SynapseT>>
synapses_parameters_;
169 Projection(UID uid, UID presynaptic_uid, UID postsynaptic_uid);
195 [[nodiscard]]
const UID &
get_uid()
const {
return base_.uid_; }
202 [[nodiscard]]
auto &
get_tags() {
return base_.tags_; }
209 [[nodiscard]]
const auto &
get_tags()
const {
return base_.tags_; }
231 [[nodiscard]]
auto begin()
const {
return parameters_.cbegin(); }
237 [[nodiscard]]
auto begin() {
return parameters_.begin(); }
243 [[nodiscard]]
auto end()
const {
return parameters_.cend(); }
249 [[nodiscard]]
auto end() {
return parameters_.end(); }
256 [[nodiscard]]
size_t size()
const {
return parameters_.size(); }
364 void reindex()
const;
371 UID presynaptic_uid_;
376 UID postsynaptic_uid_;
381 bool is_locked_ =
true;
386 std::vector<Synapse> parameters_;
393 bool operator==(
const Connection &connection)
const
395 return from_ == connection.from_ && to_ == connection.to_ && index_ == connection.index_;
399 typedef boost::multi_index::multi_index_container<
401 boost::multi_index::indexed_by<
402 boost::multi_index::hashed_non_unique<
403 boost::multi_index::tag<struct mi_presynaptic>, BOOST_MULTI_INDEX_MEMBER(Connection,
size_t, from_)>,
404 boost::multi_index::hashed_non_unique<
405 boost::multi_index::tag<struct mi_postsynaptic>, BOOST_MULTI_INDEX_MEMBER(Connection,
size_t, to_)>,
406 boost::multi_index::hashed_unique<
407 boost::multi_index::tag<struct mi_synapse_index>,
408 BOOST_MULTI_INDEX_MEMBER(Connection,
size_t, index_)>>>
410 using ByPresynaptic = mi_presynaptic;
411 using ByPostsynaptic = mi_postsynaptic;
413 mutable Index index_;
414 mutable bool is_index_updated_ =
false;
427using AllProjections = boost::mp11::mp_transform<knp::core::Projection, knp::synapse_traits::AllSynapses>;
The Projection class is a definition of similar connections between the neurons of two populations.
Synapse & operator[](size_t index)
Get parameter values of a synapse with the given index.
const UID & get_postsynaptic() const
Get UID of the associated population to which this projection sends signals.
Projection(UID presynaptic_uid, UID postsynaptic_uid, SynapseGenerator generator, size_t num_iterations)
Construct a projection by running a synapse generator a given number of times.
std::vector< size_t > find_synapses(size_t neuron_index, Search search_method) const
Find synapses that originate from a neuron with the given index.
const UID & get_presynaptic() const
Get UID of the associated population from which this projection receives spikes.
auto begin()
Get an iterator pointing to the first element of the projection.
void remove_synapse(size_t index)
Remove a synapse with the given index from the projection.
auto end() const
Get an iterator pointing to the last element of the projection.
void clear()
Remove all synapses from the projection.
SynapseType ProjectionSynapseType
Type of the projection synapses.
const SharedSynapseParameters & get_shared_parameters() const
Get parameters shared between all synapses.
Projection< SynapseType > ProjectionType
Projection of synapses with the specified synapse type.
auto begin() const
Get an iterator pointing to the first element of the projection.
size_t remove_synapse_if(std::function< bool(const Synapse &)> predicate)
Remove synapses according to a given criterion.
size_t remove_presynaptic_neuron_synapses(size_t neuron_index)
Remove all synapses that receive signals from a neuron with the given index.
size_t size() const
Count number of synapses in the projection.
auto end()
Get an iterator pointing to the last element of the projection.
typename synapse_traits::synapse_parameters< SynapseType > SynapseParameters
Parameters of the specified synapse type.
size_t remove_postsynaptic_neuron_synapses(size_t neuron_index)
Remove all synapses that lead to a neuron with the given index.
std::function< std::optional< Synapse >(size_t)> SynapseGenerator
Synapse generation function type.
void lock_weights()
Lock the possibility to change synapses weights.
size_t add_synapses(SynapseGenerator generator, size_t num_iterations)
Append connections to the existing projection.
Projection(UID presynaptic_uid, UID postsynaptic_uid)
Construct an empty projection.
SharedSynapseParameters & get_shared_parameters()
Get parameters shared between all synapses.
std::tuple< SynapseParameters, size_t, size_t > Synapse
Synapse description structure that contains synapse parameters and indexes of the associated neurons.
void unlock_weights()
Unlock the possibility to change synapses weights.
Search
Types of synapse search.
@ by_presynaptic
Search by presynaptic neuron index.
@ by_postsynaptic
Search by postsynaptic neuron index.
Projection(UID uid, UID presynaptic_uid, UID postsynaptic_uid, SynapseGenerator generator, size_t num_iterations)
Construct a projection by running a synapse generator a given number of times.
const Synapse & operator[](size_t index) const
Get parameter values of a synapse with the given index.
const UID & get_uid() const
Get projection UID.
Projection(UID uid, UID presynaptic_uid, UID postsynaptic_uid)
Construct an empty projection.
const auto & get_tags() const
Get tags used by the projection.
auto & get_tags()
Get tags used by the projection.
SharedSynapseParametersT< SynapseType > SharedSynapseParameters
Type of shared synapse parameters.
bool is_locked() const
Determine if the synapse weight change is locked.
Class definition for core library basic entities.
boost::mp11::mp_transform< knp::core::Projection, knp::synapse_traits::AllSynapses > AllProjections
List of projection types based on synapse types specified in knp::synapse_traits::AllSynapses.
boost::mp11::mp_rename< AllProjections, std::variant > AllProjectionsVariant
Projection variant that contains any projection type specified in AllProjections.
SynapseElementAccess
Enumeration used to access connection.
@ target_neuron_id
Getting target neuron index.
@ synapse_data
Getting synapse parameters.
@ source_neuron_id
Getting source neuron index.
Shared synapse parameters for the non-STDP variant of the projection.
knp::synapse_traits::shared_synapse_parameters< SynapseT > synapses_parameters_
Shared synapse parameters.
Delta synapse type traits.