32
32
#include " connector_base.h"
33
33
#include " connector_model.h"
34
34
#include " kernel_manager.h"
35
+ #include " mask.h"
35
36
#include " nest_names.h"
36
37
#include " sp_manager_impl.h"
37
38
#include " spatial.h"
@@ -49,6 +50,8 @@ SPManager::SPManager()
49
50
, sp_conn_builders_()
50
51
, growthcurve_factories_()
51
52
, growthcurvedict_( new Dictionary() )
53
+ , structural_plasticity_max_distance_( std::numeric_limits< double >::infinity() )
54
+ , distance_mask_template_( nullptr )
52
55
{
53
56
}
54
57
@@ -274,7 +277,7 @@ SPManager::get_neuron_pair_index( int id1, int id2 )
274
277
{
275
278
int max_id = std::max ( id1, id2 );
276
279
int min_id = std::min ( id1, id2 );
277
- int index = ( ( max_id ) * ( max_id - 1 ) ) / 2 + ( min_id - 1 );
280
+ int index = ( ( max_id ) * ( max_id - 1 ) ) / 2 + ( min_id - 1 );
278
281
return index;
279
282
}
280
283
@@ -304,7 +307,7 @@ SPManager::roulette_wheel_selection( const std::vector< double >& probabilities,
304
307
305
308
// Perform binary search to find the selected index
306
309
auto it = std::lower_bound ( cumulative.begin (), cumulative.end (), randomValue );
307
- return static_cast < int >( std::distance ( cumulative.begin (), it ) );
310
+ return static_cast < int >( std::distance ( cumulative.begin (), it ) );
308
311
}
309
312
310
313
@@ -365,13 +368,12 @@ SPManager::build_probability_list()
365
368
continue ;
366
369
}
367
370
368
-
371
+
369
372
std::vector< double > pos_j (
370
373
global_positions.begin () + pos_dim * ( id_j - 1 ), global_positions.begin () + pos_dim * id_j );
371
374
372
375
double prob = gaussian_kernel ( pos_i, pos_j, structural_plasticity_gaussian_kernel_sigma_ );
373
376
probability_list[ index ] = prob;
374
-
375
377
}
376
378
}
377
379
}
@@ -905,6 +907,16 @@ SPManager::global_shuffle_spatial( std::vector< size_t >& pre_ids,
905
907
size_t pre_id = pre_ids.back ();
906
908
pre_ids.pop_back ();
907
909
910
+
911
+ // build an AnchoredMask about this pre‐neuron’s position
912
+ std::vector< double > pre_pos (
913
+ global_positions.begin () + ( pre_id - 1 ) * pos_dim, global_positions.begin () + pre_id * pos_dim );
914
+
915
+ AnchoredMask< 2 > distance_mask ( *distance_mask_template_, // the BallMask centered at 0
916
+ pre_pos // now anchored at pre_pos
917
+ );
918
+
919
+
908
920
std::vector< double > probabilities;
909
921
std::vector< size_t > valid_post_ids;
910
922
double rnd;
@@ -915,6 +927,16 @@ SPManager::global_shuffle_spatial( std::vector< size_t >& pre_ids,
915
927
continue ; // Skip self-connections
916
928
}
917
929
930
+ // fetch post position
931
+ std::vector< double > post_pos (
932
+ global_positions.begin () + ( post_id - 1 ) * pos_dim, global_positions.begin () + post_id * pos_dim );
933
+
934
+ // HARD cutoff via the Mask:
935
+ if ( !distance_mask.inside ( post_pos ) )
936
+ {
937
+ continue ; // distance > max_distance -> masked out entirely
938
+ }
939
+
918
940
double prob;
919
941
if ( structural_plasticity_cache_probabilities_ )
920
942
{
@@ -929,13 +951,14 @@ SPManager::global_shuffle_spatial( std::vector< size_t >& pre_ids,
929
951
}
930
952
else
931
953
{
954
+ /* *
932
955
size_t pre_index = pre_id - 1;
933
956
std::vector< double > pre_pos(
934
957
global_positions.begin() + pre_index * pos_dim, global_positions.begin() + ( pre_index + 1 ) * pos_dim );
935
958
936
959
size_t post_index = post_id - 1;
937
960
std::vector< double > post_pos(
938
- global_positions.begin () + post_index * pos_dim, global_positions.begin () + ( post_index + 1 ) * pos_dim );
961
+ global_positions.begin() + post_index * pos_dim, global_positions.begin() + ( post_index + 1 ) * pos_dim );* */
939
962
940
963
prob = gaussian_kernel ( pre_pos, post_pos, structural_plasticity_gaussian_kernel_sigma_ );
941
964
}
@@ -973,7 +996,8 @@ SPManager::global_shuffle_spatial( std::vector< size_t >& pre_ids,
973
996
void
974
997
nest::SPManager::enable_structural_plasticity ( bool use_gaussian_kernel,
975
998
double gaussian_kernel_sigma,
976
- bool cache_probabilities )
999
+ bool cache_probabilities,
1000
+ double max_distance )
977
1001
{
978
1002
if ( kernel ().vp_manager .get_num_threads () > 1 )
979
1003
{
@@ -996,6 +1020,7 @@ nest::SPManager::enable_structural_plasticity( bool use_gaussian_kernel,
996
1020
structural_plasticity_cache_probabilities_ = cache_probabilities;
997
1021
structural_plasticity_enabled_ = true ;
998
1022
1023
+ distance_mask_template_ = std::make_unique< BallMask< 2 > >( Position< 2 > { 0 , 0 }, max_distance );
999
1024
if ( use_gaussian_kernel )
1000
1025
{
1001
1026
gather_global_positions_and_ids ();
0 commit comments