In [1]:
import nest
import matplotlib.pyplot as plt

nest.ResetKernel()

Creating nodes with spatial positions


In [2]:
pos_grid = nest.spatial.grid(shape=[10, 10], extent=[2., 2.])

nodes_grid = nest.Create('iaf_psc_alpha', positions=pos_grid)
nest.PlotLayer(nodes_grid, nodesize=50)
plt.gca().set_xticks((-1., -0.5, 0., 0.5, 1.))
plt.gca().set_yticks((-1., -0.5, 0., 0.5, 1.));



In [3]:
pos_free_1 = nest.spatial.free(nest.random.uniform(-0.75, 0.75), extent=[2., 2.])

nodes_free_1 = nest.Create('iaf_psc_alpha', 12, positions=pos_free_1)
nest.PlotLayer(nodes_free_1, nodesize=50)
plt.gca().set_xticks((-0.75, -0.25, 0.25, 0.75))
plt.gca().set_yticks((-0.75, -0.25, 0.25, 0.75));



In [4]:
pos_free_2 = nest.spatial.free([nest.random.uniform(-0.75, 0.75),
                           nest.random.uniform(-0.5, 0.5)],
                          extent=[2., 1.5])
nodes_free_2 = nest.Create('iaf_psc_exp', 50, positions=pos_free_2)
nest.PlotLayer(nodes_free_2, nodesize=50);
plt.gca().set_xticks((-0.75, -0.25, 0.25, 0.75))
plt.gca().set_yticks((-0.5, 0, 0.5));

pos_3 = nest.spatial.free([[-0.7, -0.7], [0.0, 0.0], [0.7, 0.7]])
nodes_free_3 = nest.Create('iaf_psc_alpha', positions=pos_3)
nest.PlotLayer(nodes_free_3, nodesize=50);
plt.gca().set_xticks((-0.75, 0, 0.75))
plt.gca().set_yticks((-0.75, 0, 0.75));



In [5]:
nest.PrintNodes()


  1 .. 112 iaf_psc_alpha
113 .. 162 iaf_psc_exp
163 .. 165 iaf_psc_alpha

Connecting nodes based on spatial information


In [6]:
conn_spec = {'rule': 'pairwise_bernoulli',
             'p': 0.5}

nest.Connect(nodes_free_1, nodes_free_2,
             conn_spec=conn_spec,
             syn_spec={'weight': nest.random.uniform(0.5, 2.)})

In [7]:
conns = nest.GetConnections()
print('src tgt wght delay')
for conn in conns:
    src = conn.source
    tgt = conn.target
    wght = conn.weight
    delay = conn.delay
    print('{} {} {:.2f} {}'.format(src, tgt, wght, delay))


src tgt wght delay
101 113 1.56 1.0
101 121 1.92 1.0
101 123 1.79 1.0
101 125 0.56 1.0
101 120 1.21 1.0
101 127 1.11 1.0
101 128 1.59 1.0
101 119 0.81 1.0
101 135 1.46 1.0
101 140 1.00 1.0
101 141 0.93 1.0
101 142 0.60 1.0
101 143 1.40 1.0
101 144 0.82 1.0
101 145 0.85 1.0
101 146 1.91 1.0
101 147 1.40 1.0
101 115 1.18 1.0
101 148 1.95 1.0
101 162 1.53 1.0
101 159 1.38 1.0
101 157 0.68 1.0
101 154 0.75 1.0
102 145 0.59 1.0
102 113 1.27 1.0
102 162 1.38 1.0
102 125 2.00 1.0
102 161 1.50 1.0
102 126 0.77 1.0
102 127 0.59 1.0
102 158 0.91 1.0
102 131 1.09 1.0
102 135 1.11 1.0
102 137 0.98 1.0
102 138 0.93 1.0
102 139 1.15 1.0
102 153 0.90 1.0
102 140 0.86 1.0
102 152 1.02 1.0
102 148 0.73 1.0
102 143 1.33 1.0
102 147 1.33 1.0
102 120 1.68 1.0
102 118 0.56 1.0
102 115 0.54 1.0
102 116 1.35 1.0
102 117 1.89 1.0
102 119 0.99 1.0
103 132 0.67 1.0
103 149 0.53 1.0
103 148 0.73 1.0
103 126 0.98 1.0
103 147 0.86 1.0
103 145 1.97 1.0
103 143 1.29 1.0
103 116 0.53 1.0
103 142 0.66 1.0
103 128 1.66 1.0
103 140 0.59 1.0
103 117 0.61 1.0
103 130 1.84 1.0
103 139 1.76 1.0
103 137 1.84 1.0
103 136 1.02 1.0
103 135 1.06 1.0
103 162 1.96 1.0
103 122 1.72 1.0
103 114 1.61 1.0
103 151 1.78 1.0
103 160 1.22 1.0
103 157 1.08 1.0
103 152 1.12 1.0
103 150 1.30 1.0
103 155 1.32 1.0
104 156 1.96 1.0
104 123 1.63 1.0
104 127 1.44 1.0
104 153 1.75 1.0
104 131 1.25 1.0
104 120 0.57 1.0
104 122 1.23 1.0
104 138 1.29 1.0
104 130 1.60 1.0
104 144 1.29 1.0
104 136 1.00 1.0
104 145 1.68 1.0
104 113 0.89 1.0
104 152 1.43 1.0
104 147 1.77 1.0
104 121 1.30 1.0
104 149 1.34 1.0
104 133 0.86 1.0
105 160 1.53 1.0
105 136 1.80 1.0
105 141 0.76 1.0
105 133 1.57 1.0
105 137 1.77 1.0
105 155 1.61 1.0
105 159 0.62 1.0
105 157 0.77 1.0
105 139 0.90 1.0
105 140 1.43 1.0
105 156 0.79 1.0
105 142 0.65 1.0
105 144 1.61 1.0
105 115 0.82 1.0
105 152 1.58 1.0
105 151 0.56 1.0
105 148 1.32 1.0
105 149 1.53 1.0
105 150 0.52 1.0
105 125 1.15 1.0
105 121 0.93 1.0
105 132 1.45 1.0
105 129 1.54 1.0
105 128 0.61 1.0
105 126 1.99 1.0
105 127 0.69 1.0
105 120 1.18 1.0
105 123 1.94 1.0
106 127 1.43 1.0
106 125 1.67 1.0
106 146 1.48 1.0
106 143 1.77 1.0
106 162 1.50 1.0
106 116 1.65 1.0
106 141 1.55 1.0
106 117 1.20 1.0
106 138 1.64 1.0
106 149 1.62 1.0
106 114 1.66 1.0
106 124 0.89 1.0
106 123 1.09 1.0
106 152 1.93 1.0
106 156 0.95 1.0
106 122 1.57 1.0
106 158 1.08 1.0
106 121 1.12 1.0
106 160 0.85 1.0
106 161 0.83 1.0
106 113 0.61 1.0
106 126 0.85 1.0
106 136 0.97 1.0
106 134 1.06 1.0
106 118 1.60 1.0
106 135 0.96 1.0
107 161 1.69 1.0
107 141 1.39 1.0
107 142 1.31 1.0
107 131 0.77 1.0
107 145 1.50 1.0
107 126 1.86 1.0
107 148 0.81 1.0
107 150 1.88 1.0
107 124 1.91 1.0
107 152 0.83 1.0
107 154 1.55 1.0
107 155 0.63 1.0
107 156 0.75 1.0
107 160 1.33 1.0
107 113 0.82 1.0
107 149 1.72 1.0
107 139 1.42 1.0
107 138 1.30 1.0
108 135 1.56 1.0
108 131 0.87 1.0
108 115 0.56 1.0
108 146 1.91 1.0
108 134 1.26 1.0
108 151 1.01 1.0
108 157 0.53 1.0
108 147 0.71 1.0
108 130 0.52 1.0
108 113 1.68 1.0
108 144 1.77 1.0
108 158 1.36 1.0
108 119 1.97 1.0
108 133 0.94 1.0
108 139 1.50 1.0
108 148 0.87 1.0
108 156 0.94 1.0
108 149 1.53 1.0
108 127 1.52 1.0
108 137 1.66 1.0
108 125 1.92 1.0
108 116 1.59 1.0
108 162 0.78 1.0
108 141 0.90 1.0
109 157 1.26 1.0
109 122 1.01 1.0
109 135 1.28 1.0
109 150 1.26 1.0
109 130 1.62 1.0
109 158 1.40 1.0
109 125 1.24 1.0
109 145 1.80 1.0
109 126 1.82 1.0
109 162 1.67 1.0
109 134 1.98 1.0
109 155 0.89 1.0
109 144 1.97 1.0
109 133 0.58 1.0
109 121 0.51 1.0
109 137 1.30 1.0
109 132 0.85 1.0
110 149 1.13 1.0
110 153 1.26 1.0
110 117 0.83 1.0
110 123 0.53 1.0
110 131 1.35 1.0
110 156 1.28 1.0
110 122 0.53 1.0
110 124 1.95 1.0
110 113 1.95 1.0
110 128 1.87 1.0
110 127 1.98 1.0
110 120 0.90 1.0
110 142 0.62 1.0
110 136 1.24 1.0
110 119 0.85 1.0
110 160 1.26 1.0
110 115 1.81 1.0
110 154 0.90 1.0
110 133 0.50 1.0
110 145 0.71 1.0
110 138 1.44 1.0
110 134 0.66 1.0
110 132 1.01 1.0
110 159 1.53 1.0
110 121 1.68 1.0
110 125 1.51 1.0
110 137 1.54 1.0
111 113 1.82 1.0
111 155 1.84 1.0
111 122 0.69 1.0
111 162 1.83 1.0
111 159 0.90 1.0
111 133 1.09 1.0
111 117 1.02 1.0
111 160 1.55 1.0
111 137 0.60 1.0
111 151 0.51 1.0
111 126 0.59 1.0
111 154 0.77 1.0
111 145 1.51 1.0
111 153 1.26 1.0
111 134 1.81 1.0
111 152 1.03 1.0
111 114 1.08 1.0
111 139 0.64 1.0
111 148 1.91 1.0
111 135 0.92 1.0
111 129 1.13 1.0
111 142 0.53 1.0
111 124 1.43 1.0
111 130 1.59 1.0
112 118 0.53 1.0
112 126 0.56 1.0
112 137 1.19 1.0
112 144 1.47 1.0
112 115 1.92 1.0
112 139 1.75 1.0
112 161 0.70 1.0
112 128 0.51 1.0
112 132 1.89 1.0
112 141 1.59 1.0
112 117 1.41 1.0
112 120 0.99 1.0
112 162 0.57 1.0
112 119 0.73 1.0
112 145 1.36 1.0
112 135 1.90 1.0
112 122 1.04 1.0
112 147 1.94 1.0
112 114 1.54 1.0
112 157 0.55 1.0
112 124 1.18 1.0
112 121 1.95 1.0
112 130 1.32 1.0
112 151 1.25 1.0
112 131 1.16 1.0
112 138 0.82 1.0
112 113 1.32 1.0
112 154 0.97 1.0

In [8]:
conns.weight


Out[8]:
[1.5570436180569232,
 1.9231376238167286,
 1.7901425585150719,
 0.5574303781613708,
 1.2095678322948515,
 1.1085848337970674,
 1.5944749917834997,
 0.8075163154862821,
 1.4626674437895417,
 1.0014257333241403,
 0.9345086277462542,
 0.599301228299737,
 1.4008159539662302,
 0.8226278014481068,
 0.8516589002683759,
 1.907325889915228,
 1.3951202048920095,
 1.175722180865705,
 1.9527603900060058,
 1.5345481866970658,
 1.3763260068371892,
 0.6829642839729786,
 0.7459781258367002,
 0.592737406026572,
 1.2724072984419763,
 1.3760560117661953,
 1.9961549346335232,
 1.502572554629296,
 0.772745733615011,
 0.5886735687963665,
 0.9075049799866974,
 1.0881214523687959,
 1.109858684707433,
 0.9820320601575077,
 0.926760429982096,
 1.1511889691464603,
 0.9006226705387235,
 0.8648714479058981,
 1.015542107168585,
 0.7265165452845395,
 1.3299417505040765,
 1.3283692691475153,
 1.679827966261655,
 0.5583133613690734,
 0.5391455958597362,
 1.3508049291558564,
 1.887396520934999,
 0.9926226185634732,
 0.6680618119426072,
 0.5256094872020185,
 0.7261005137115717,
 0.9821544457226992,
 0.859385569114238,
 1.9725638781674206,
 1.2921301876194775,
 0.5284128845669329,
 0.6590200867503881,
 1.6634366838261485,
 0.5864194612950087,
 0.609433623496443,
 1.8360942625440657,
 1.762179332319647,
 1.8446628446690738,
 1.0196183524094522,
 1.0639049215242267,
 1.9627381823956966,
 1.7238366571255028,
 1.6078142863698304,
 1.7811735225841403,
 1.215669920668006,
 1.0834113243035972,
 1.1180100617930293,
 1.295749089680612,
 1.3166386168450117,
 1.958800378255546,
 1.6341626243665814,
 1.443269723560661,
 1.7505120276473463,
 1.247389892116189,
 0.571631966624409,
 1.234584144782275,
 1.2865857905708253,
 1.5991619410924613,
 1.2917208322323859,
 1.0047161136753857,
 1.6830055848695338,
 0.8922892273403704,
 1.4348903656937182,
 1.7674946645274758,
 1.3046427094377577,
 1.335670777130872,
 0.8557128035463393,
 1.5302621661685407,
 1.7984279999509454,
 0.7623836994171143,
 1.5705196647904813,
 1.7720373766496778,
 1.6105231889523566,
 0.6206345912069082,
 0.7666203379631042,
 0.8976117637939751,
 1.430227025412023,
 0.789940710645169,
 0.6494279652833939,
 1.611701532267034,
 0.8203587937168777,
 1.5838837837800384,
 0.5641838284209371,
 1.3180419807322323,
 1.529820698313415,
 0.5215395228005946,
 1.1514918813481927,
 0.9342937367036939,
 1.4487907909788191,
 1.5369570325128734,
 0.6103924391791224,
 1.986593761947006,
 0.6913686017505825,
 1.1808318393304944,
 1.9408715111203492,
 1.4345485167577863,
 1.6694287289865315,
 1.4837716077454388,
 1.7669991850852966,
 1.5011404952965677,
 1.6461782627739012,
 1.5473282015882432,
 1.2045035450719297,
 1.6398242660798132,
 1.6172079243697226,
 1.6649532201699913,
 0.8864504215307534,
 1.093610942363739,
 1.9318426242098212,
 0.945767187513411,
 1.5663661160506308,
 1.0773862055502832,
 1.1214499277994037,
 0.8533170600421727,
 0.8324692468158901,
 0.6140642715618014,
 0.8536789724603295,
 0.9703527959063649,
 1.060747113544494,
 1.6004631840623915,
 0.9617507196962833,
 1.690479730721563,
 1.3871060563251376,
 1.310777793172747,
 0.7717236164025962,
 1.5044573778286576,
 1.8570893500000238,
 0.811273206025362,
 1.8774680895730853,
 1.9061306933872402,
 0.8326195287518203,
 1.5467853671871126,
 0.6281488598324358,
 0.751784578897059,
 1.331242362037301,
 0.8188589653000236,
 1.7174735604785383,
 1.4181044367142022,
 1.3031052183359861,
 1.5625055371783674,
 0.8686580508947372,
 0.5632142755202949,
 1.905984680633992,
 1.264715577941388,
 1.0142221921123564,
 0.5330098918639123,
 0.7119750482961535,
 0.515366178471595,
 1.6841972707770765,
 1.7689544805325568,
 1.3592843250371516,
 1.97427098127082,
 0.9354207562282681,
 1.495503042358905,
 0.8730083690024912,
 0.9363248464651406,
 1.528115221299231,
 1.5201137629337609,
 1.6617486411705613,
 1.9203892536461353,
 1.5875123012810946,
 0.7799013238400221,
 0.9038038863800466,
 1.2552865068428218,
 1.008844705298543,
 1.2752124755643308,
 1.2553691915236413,
 1.615417041350156,
 1.3955174232833087,
 1.2414363520219922,
 1.799081427976489,
 1.8230235478840768,
 1.6677962122485042,
 1.9776256745681167,
 0.8928591925650835,
 1.9660537685267627,
 0.5770945562981069,
 0.5119937462732196,
 1.2952880249358714,
 0.8482484701089561,
 1.1266261148266494,
 1.2563218646682799,
 0.8329325648956001,
 0.5256567010655999,
 1.3510017739608884,
 1.2801041179336607,
 0.5270068510435522,
 1.9492660122923553,
 1.9511034777387977,
 1.8743989034555852,
 1.9829432182013988,
 0.9005999639630318,
 0.6248951307497919,
 1.2417716952040792,
 0.8452380648814142,
 1.2582245049998164,
 1.8072463069111109,
 0.9007271216250956,
 0.5046797813847661,
 0.7068718578666449,
 1.4441280234605074,
 0.6565404725261033,
 1.0136329429224133,
 1.5259463912807405,
 1.67713981308043,
 1.5057660429738462,
 1.541835970710963,
 1.8212670711800456,
 1.8361779195256531,
 0.6858837218023837,
 1.8317585457116365,
 0.896547136362642,
 1.0915169124491513,
 1.022804467473179,
 1.5503619560040534,
 0.6022784831002355,
 0.5055263871327043,
 0.5892879399470985,
 0.7685799403116107,
 1.5052629499696195,
 1.2595970095135272,
 1.8096316806040704,
 1.0304828565567732,
 1.0825043395161629,
 0.638382893987,
 1.9127351231873035,
 0.923012625426054,
 1.1285538799129426,
 0.5325617045164108,
 1.4255164489150047,
 1.5877406718209386,
 0.5277997776865959,
 0.5617146077565849,
 1.190439567901194,
 1.4703361042775214,
 1.9241656879894435,
 1.749972043093294,
 0.7030041292309761,
 0.5075595462694764,
 1.8866533101536334,
 1.5900342022068799,
 1.4073120043613017,
 0.990500820800662,
 0.5696369758807123,
 0.7336427820846438,
 1.358357026707381,
 1.9026528517715633,
 1.0444779638200998,
 1.9434448350220919,
 1.5427778898738325,
 0.5543921212665737,
 1.1807316741906106,
 1.9548583831638098,
 1.3207659651525319,
 1.2516467981040478,
 1.1622336800210178,
 0.8236827407963574,
 1.3156220093369484,
 0.9745872663334012]

In [9]:
p = 1.0 - 1.5 * nest.spatial.distance + 0.2*nest.random.uniform()
conn_spec = {'rule': 'pairwise_bernoulli',
             'p': p}

center_node = nest.Create('iaf_psc_exp', 12, positions=nest.spatial.free([[0., 0.]]))
nest.Connect(center_node, nodes_free_2,
             conn_spec=conn_spec,
             syn_spec={'weight': nest.random.uniform(0.5, 2.)})

fig = plt.figure(figsize=(12, 6))
print(nest.GetConnections(source=center_node, target=nodes_free_2))
nest.PlotTargets(center_node, nodes_free_2, probability_parameter=p, fig=fig);


*--------*-------------------------------------------------------------------------------------------*
| source | 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, |
*--------*-------------------------------------------------------------------------------------------*
| target | 113, 121, 126, 127, 132, 133, 135, 136, 138, 141, 143, 145, 147, 149, 154, 156, 159, 161, |
*--------*-------------------------------------------------------------------------------------------*

In [10]:
p = nest.logic.conditional(nest.spatial.target_pos.x > 0.0,
                           nest.spatial_distributions.exponential(nest.spatial.distance, beta=0.5),
                           0.8*nest.math.exp(nest.spatial.target_pos.x))

conn_spec = {'rule': 'pairwise_bernoulli',
             'p': p}

nest.Connect(center_node, nodes_free_1,
             conn_spec=conn_spec,
             syn_spec={'weight': nest.random.uniform(0.5, 2.)})

fig = plt.figure(figsize=(12, 6))
nest.PlotTargets(center_node, nodes_free_1, probability_parameter=p, fig=fig);



In [ ]: