Skip to content

Commit 2836355

Browse files
committed
Fix autapse support in SPManager’s probability cache
1 parent 2a1caf7 commit 2836355

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

nestkernel/sp_manager.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,10 @@ SPManager::build_probability_list()
330330
throw std::runtime_error( "Mismatch in global positions dimensionality." );
331331
}
332332

333+
333334
// Resize the probability list to accommodate all neuron pairs.
334335
size_t total_pairs = ( num_neurons * ( num_neurons + 1 ) ) / 2;
335-
probability_list.resize( total_pairs, -1.0 );
336+
probability_list.resize( total_pairs, 0.0 );
336337

337338
// Calculate probabilities for connections between all pairs of neurons.
338339
for ( size_t i = 0; i < num_neurons; ++i )
@@ -364,18 +365,13 @@ SPManager::build_probability_list()
364365
continue;
365366
}
366367

367-
if ( id_i == id_j )
368-
{
369-
probability_list[ index ] = 0.0; // Assign zero probability for self-connections
370-
}
371-
else
372-
{
373-
std::vector< double > pos_j(
374-
global_positions.begin() + pos_dim * ( id_j - 1 ), global_positions.begin() + pos_dim * id_j );
368+
369+
std::vector< double > pos_j(
370+
global_positions.begin() + pos_dim * ( id_j - 1 ), global_positions.begin() + pos_dim * id_j );
375371

376-
double prob = gaussian_kernel( pos_i, pos_j, structural_plasticity_gaussian_kernel_sigma_ );
377-
probability_list[ index ] = prob;
378-
}
372+
double prob = gaussian_kernel( pos_i, pos_j, structural_plasticity_gaussian_kernel_sigma_ );
373+
probability_list[ index ] = prob;
374+
379375
}
380376
}
381377
}
@@ -648,7 +644,8 @@ SPManager::create_synapses( std::vector< size_t >& pre_id,
648644
}
649645
else
650646
{
651-
global_shuffle_spatial( pre_id_rnd, post_id_rnd, pre_ids_results, post_ids_results );
647+
global_shuffle_spatial(
648+
pre_id_rnd, post_id_rnd, pre_ids_results, post_ids_results, sp_conn_builder->allows_autapses() );
652649
}
653650

654651
// create synapse
@@ -893,7 +890,8 @@ void
893890
SPManager::global_shuffle_spatial( std::vector< size_t >& pre_ids,
894891
std::vector< size_t >& post_ids,
895892
std::vector< size_t >& pre_ids_results,
896-
std::vector< size_t >& post_ids_results )
893+
std::vector< size_t >& post_ids_results,
894+
bool allow_autapse )
897895
{
898896
size_t maxIterations = std::min( pre_ids.size(), post_ids.size() );
899897

@@ -912,7 +910,7 @@ SPManager::global_shuffle_spatial( std::vector< size_t >& pre_ids,
912910
double rnd;
913911
for ( size_t post_id : post_ids )
914912
{
915-
if ( post_id == pre_id )
913+
if ( post_id == pre_id && !allow_autapse )
916914
{
917915
continue; // Skip self-connections
918916
}

nestkernel/sp_manager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ class SPManager : public ManagerInterface
221221
void global_shuffle_spatial( std::vector< size_t >& pre_ids,
222222
std::vector< size_t >& post_ids,
223223
std::vector< size_t >& pre_ids_results,
224-
std::vector< size_t >& post_ids_results );
224+
std::vector< size_t >& post_ids_results,
225+
bool allow_autapse );
225226

226227
/**
227228
* Build a probability list for neuron connections based on spatial properties.

0 commit comments

Comments
 (0)