23 #ifndef CONNECTION_CREATOR_IMPL_H
24 #define CONNECTION_CREATOR_IMPL_H
72 weight =
weight_->value(pos, rng);
73 delay =
delay_ ->value(pos, rng);
76 template<
typename Iterator,
int D>
83 const bool without_kernel = not
kernel_.valid();
84 for ( Iterator iter = from ; iter != to ; ++iter )
89 if ( without_kernel or
94 connect_(iter->second, tgt_ptr, tgt_thread,
112 delete masked_layer_;
118 assert(masked_layer_ == 0);
127 assert(masked_layer_ == 0);
136 return masked_layer_->begin(pos);
142 return masked_layer_->end();
148 return positions_->begin();
154 return positions_->end();
169 std::vector<Node*>::const_iterator target_begin;
170 std::vector<Node*>::const_iterator target_end;
187 #pragma omp parallel //default(none) shared(source, target, masked_layer, target_begin, target_end)
189 for ( std::vector<Node*>::const_iterator tgt_it = target_begin;
190 tgt_it != target_end;
227 std::vector<Node*>::const_iterator target_begin;
228 std::vector<Node*>::const_iterator target_end;
243 for (std::vector<Node*>::const_iterator tgt_it = target_begin;tgt_it != target_end;++tgt_it) {
248 index target_id = (*tgt_it)->get_gid();
292 for (std::vector<Node*>::const_iterator tgt_it = target_begin;tgt_it != target_end;++tgt_it) {
297 index target_id = (*tgt_it)->get_gid();
307 for(
typename std::vector<std::pair<
Position<D>,
index> >::iterator iter=positions->begin();iter!=positions->end();++iter) {
321 for(
typename std::vector<std::pair<
Position<D>,
index> >::iterator iter=positions->begin();iter!=positions->end();++iter) {
349 std::vector<Node*>::const_iterator target_begin;
350 std::vector<Node*>::const_iterator target_end;
361 for (std::vector<Node*>::const_iterator tgt_it = target_begin;tgt_it != target_end;++tgt_it) {
366 index target_id = (*tgt_it)->get_gid();
383 std::vector<double_t> probabilities;
386 for(
typename std::vector<std::pair<
Position<D>,
index> >::iterator iter=positions.begin();iter!=positions.end();++iter) {
392 if ( positions.empty() or
393 ((not
allow_autapses_) and (positions.size()==1) and (positions[0].second==target_id)) or
395 std::string msg = String::compose(
"Global target ID %1: Not enough sources found inside mask", target_id);
401 Vose lottery(probabilities);
405 std::vector<bool> is_selected(positions.size());
410 if ((not allow_multapses_) and (is_selected[random_id])) {
415 index source_id = positions[random_id].second;
416 if ((not allow_autapses_) and (source_id == target_id)) {
423 is_selected[random_id] =
true;
430 if ( positions.empty() or
431 ((not
allow_autapses_) and (positions.size()==1) and (positions[0].second==target_id)) or
433 std::string msg = String::compose(
"Global target ID %1: Not enough sources found inside mask", target_id);
439 std::vector<bool> is_selected(positions.size());
443 index random_id = rng->ulrand(positions.size());
444 if ((not allow_multapses_) and (is_selected[random_id])) {
448 index source_id = positions[random_id].second;
452 is_selected[random_id] =
true;
465 for (std::vector<Node*>::const_iterator tgt_it = target_begin;tgt_it != target_end;++tgt_it) {
470 index target_id = (*tgt_it)->get_gid();
475 if ( (positions->size()==0) or
476 ((not
allow_autapses_) and (positions->size()==1) and ((*positions)[0].second==target_id)) or
478 std::string msg = String::compose(
"Global target ID %1: Not enough sources found", target_id);
488 std::vector<double_t> probabilities;
491 for(
typename std::vector<std::pair<
Position<D>,
index> >::iterator iter=positions->begin();iter!=positions->end();++iter) {
497 Vose lottery(probabilities);
501 std::vector<bool> is_selected(positions->size());
506 if ((not allow_multapses_) and (is_selected[random_id])) {
511 index source_id = (*positions)[random_id].second;
512 if ((not allow_autapses_) and (source_id == target_id)) {
517 Position<D> source_pos = (*positions)[random_id].first;
521 is_selected[random_id] =
true;
530 std::vector<bool> is_selected(positions->size());
534 index random_id = rng->ulrand(positions->size());
535 if ((not allow_multapses_) and (is_selected[random_id])) {
540 index source_id = (*positions)[random_id].second;
541 if ((not allow_autapses_) and (source_id == target_id)) {
546 Position<D> source_pos = (*positions)[random_id].first;
550 is_selected[random_id] =
true;
574 for (
typename std::vector<std::pair<
Position<D>,
index> >::iterator src_it = sources->begin(); src_it != sources->end(); ++src_it) {
577 index source_id = src_it->second;
579 std::vector<Position<D> > displacements;
580 std::vector<double_t> probabilities;
592 targets.push_back(tgt_it->second);
593 displacements.push_back(target_displ);
596 probabilities.push_back(
kernel_->value(target_displ, rng));
598 probabilities.push_back(1.0);
601 if ( targets.empty() or
603 std::string msg = String::compose(
"Global source ID %1: Not enough targets found", source_id);
609 Vose lottery(probabilities);
613 std::vector<bool> is_selected(targets.size());
618 if ((not allow_multapses_) and (is_selected[random_id])) {
622 Position<D> target_displ = displacements[random_id];
623 index target_id = targets[random_id];
628 is_selected[random_id] =
true;
bool allow_multapses_
Definition: connection_creator.h:158
size_t index
Unsigned long type for enumerations.
Definition: nest.h:109
void connect_to_target_(Iterator from, Iterator to, Node *tgt_ptr, const Position< D > &tgt_pos, thread tgt_thread, const Layer< D > &source)
Definition: connection_creator_impl.h:77
Definition: connection_creator.h:68
double_t weight
Weight of a connection.
Definition: nest.h:170
std::vector< Node * >::iterator local_end(int_t depth)
End of local children at given depth.
Definition: layer.cpp:173
Ntree< D, index >::masked_iterator begin(const Position< D > &anchor)
Iterate over nodes inside mask.
Definition: layer.h:506
index get_gid() const
Return global Network ID.
Definition: node.h:753
lockPTR< Parameter > delay_
Definition: connection_creator.h:167
index synapse_model_
Definition: connection_creator.h:165
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
Iterator iterating the nodes in a Quadtree inside a Mask.
Definition: ntree.h:128
Vose's alias method for selecting a random number using a discrete probability distribution.
Definition: vose.h:41
Ntree< D, index >::masked_iterator end()
Definition: layer.h:517
std::vector< Node * >::iterator local_begin(int_t depth)
Start of local children at given depth.
Definition: layer.cpp:159
index number_of_connections_
Definition: connection_creator.h:162
void connect(Layer< D > &source, Layer< D > &target)
Connect two layers.
Definition: connection_creator_impl.h:38
void connect_(index s, Node *target, thread target_thread, double_t w, double_t d, index syn)
Definition: connection_creator.h:173
void convergent_connect_(Layer< D > &source, Layer< D > &target)
Definition: connection_creator_impl.h:337
librandom::RngPtr get_grng() const
Get global random number client.
Definition: network.h:1163
Class for applying masks to layers.
Definition: connection_creator.h:42
lockPTR< Parameter > weight_
Definition: connection_creator.h:166
bool allow_oversized_
Definition: connection_creator.h:159
~PoolWrapper_()
Definition: connection_creator_impl.h:109
void divergent_connect_(Layer< D > &source, Layer< D > &target)
Definition: connection_creator_impl.h:561
void connect(index s, Node *target, thread target_thread, index syn, double_t d=NAN, double_t w=NAN)
Connect two nodes.
Definition: network.cpp:867
lockPTR< AbstractMask > mask_
Definition: connection_creator.h:163
Wrapper for masked and unmasked pools.
Definition: connection_creator.h:109
bool valid(void) const
< returns true if and only if obj->pointee != NULL
Definition: lockptr.h:307
const Name w("w")
Specific to Brette & Gerstner 2005 (aeif_cond-*)
Definition: nest_names.h:343
bool select_depth() const
Definition: selector.h:58
Selector target_filter_
Definition: connection_creator.h:161
Abstract base class for Layer of given dimension (D=2 or 3).
Definition: connection_creator.h:39
int get_thread_id() const
Gets ID of local thread.
Definition: network.h:1264
index get_random_id(librandom::RngPtr rng) const
Definition: vose.cpp:81
PoolWrapper_()
Definition: connection_creator_impl.h:103
Network & net_
Definition: connection_creator.h:169
Base class for all Kernel exceptions.
Definition: exceptions.h:54
Definition: connection_creator.h:68
long_t model
The model to select, or -1 if all models are allowed.
Definition: selector.h:69
const Name source("source")
Connection parameters.
Definition: nest_names.h:260
virtual Position< D > get_position(index sind) const =0
Get position of node.
const Name target("target")
Connection parameters.
Definition: nest_names.h:282
const Name positions("positions")
Definition: topology_names.h:53
void target_driven_connect_(Layer< D > &source, Layer< D > &target)
Definition: connection_creator_impl.h:159
const Name sources("sources")
Definition: topology_names.h:56
librandom::RngPtr get_rng(thread thrd=0) const
Get random number client of a thread.
Definition: network.h:1157
virtual Position< D > compute_displacement(const Position< D > &from_pos, const Position< D > &to_pos) const
Returns displacement of a position from another position.
Definition: layer_impl.h:43
Node * get_node(index, thread thr=0)
Return pointer of the specified Node.
Definition: network.cpp:619
Definition: connection_creator.h:68
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition: exceptions.h:420
std::vector< std::pair< Position< D >, index > >::iterator end() const
Definition: connection_creator_impl.h:152
void get_parameters_(const Position< D > &pos, librandom::RngPtr rng, double &weight, double &delay)
Calculate parameter values for this position.
Definition: connection_creator_impl.h:68
long_t depth
The depth to select, or -1 if all depths are allowed.
Definition: selector.h:73
void define(MaskedLayer< D > *)
Definition: connection_creator_impl.h:116
lockPTR< Parameter > kernel_
Definition: connection_creator.h:164
std::vector< std::pair< Position< D >, index > >::iterator begin() const
Definition: connection_creator_impl.h:146
bool allow_autapses_
Definition: connection_creator.h:157
const Name target_thread("target_thread")
Connection parameters.
Definition: nest_names.h:283
Ntree< D, index >::masked_iterator masked_end() const
Definition: connection_creator_impl.h:140
thread get_thread() const
Retrieve the number of the thread to which the node is assigned.
Definition: node.h:825
Selector source_filter_
Definition: connection_creator.h:160
long_t delay
Delay of a connection.
Definition: nest.h:178
Ntree< D, index >::masked_iterator masked_begin(const Position< D > &pos) const
Definition: connection_creator_impl.h:134
void source_driven_connect_(Layer< D > &source, Layer< D > &target)
Definition: connection_creator_impl.h:215
Base class for all NEST network objects.
Definition: node.h:96
const Name targets("targets")
Connection parameters.
Definition: nest_names.h:284
std::vector< std::pair< Position< D >, index > > * get_global_positions_vector(Selector filter=Selector())
Definition: layer_impl.h:184
bool select_model() const
Definition: selector.h:53
ConnectionType type_
Definition: connection_creator.h:156
Definition: connection_creator.h:68
int_t thread
Thread index type.
Definition: nest.h:133
long long_t
Integer number with at least 32 bit.
Definition: nest.h:96