Skip to content

Commit 785c6ac

Browse files
Make fixing mutation and migration a model parameter
Introduce gen_bias as a model parameter (was previously a TCL variable) Migration fix by accumulating as integral amounts between cells Fragmention pump model
1 parent 3a8d1b7 commit 785c6ac

6 files changed

Lines changed: 200 additions & 53 deletions

File tree

models/SAR.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def av(x):
3737
#mut_max=float(sys.argv[3]) # mutation rate
3838
#migration=float(sys.argv[4]) # initial migration rate
3939

40+
# for this experiment, do not mutate mutation or migration rates
41+
ecolab.fixMutation(True)
42+
ecolab.fixMigration(True)
43+
4044
print("Replicate, Area, Max mutation, Init. Mig, Init. num sp, Mutation rate, Migration rate, Number of species, Interaction strength^2",flush=True)
4145
for A in [1, 2, 4, 6, 9, 12, 16]:
4246
for mut_max in [1e-5, 1e-4, 1e-3]:

models/SAR.rvl

Lines changed: 70 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,64 @@
33
<minskyVersion>3.22.0</minskyVersion>
44
<wires>
55
<Wire>
6-
<id>46</id>
6+
<id>49</id>
77
<from>21</from>
88
<to>19</to>
99
</Wire>
1010
<Wire>
11-
<id>47</id>
11+
<id>50</id>
1212
<from>1</from>
1313
<to>24</to>
1414
</Wire>
1515
<Wire>
16-
<id>48</id>
17-
<from>23</from>
18-
<to>12</to>
19-
</Wire>
20-
<Wire>
21-
<id>49</id>
22-
<from>23</from>
23-
<to>18</to>
24-
</Wire>
25-
<Wire>
26-
<id>50</id>
16+
<id>51</id>
2717
<from>17</from>
2818
<to>27</to>
2919
</Wire>
3020
<Wire>
31-
<id>51</id>
21+
<id>52</id>
3222
<from>35</from>
3323
<to>33</to>
3424
</Wire>
3525
<Wire>
36-
<id>52</id>
26+
<id>53</id>
3727
<from>31</from>
3828
<to>38</to>
3929
</Wire>
4030
<Wire>
41-
<id>53</id>
31+
<id>54</id>
4232
<from>26</from>
4333
<to>39</to>
4434
</Wire>
4535
<Wire>
46-
<id>54</id>
36+
<id>55</id>
4737
<from>37</from>
4838
<to>42</to>
4939
</Wire>
5040
<Wire>
51-
<id>55</id>
52-
<from>44</from>
53-
<to>12</to>
41+
<id>56</id>
42+
<from>29</from>
43+
<to>32</to>
5444
</Wire>
5545
<Wire>
56-
<id>56</id>
46+
<id>57</id>
5747
<from>23</from>
48+
<to>48</to>
49+
</Wire>
50+
<Wire>
51+
<id>58</id>
52+
<from>47</from>
5853
<to>4</to>
5954
</Wire>
6055
<Wire>
61-
<id>57</id>
62-
<from>29</from>
63-
<to>32</to>
56+
<id>59</id>
57+
<from>47</from>
58+
<to>18</to>
59+
</Wire>
60+
<Wire>
61+
<id>60</id>
62+
<from>47</from>
63+
<to>12</to>
6464
</Wire>
6565
</wires>
6666
<items>
@@ -163,8 +163,8 @@
163163
<first>Mutation&#0032;rate</first>
164164
<second>
165165
<description>Mutation&#0032;rate</description>
166-
<x>-30.9017</x>
167-
<y>-95.1057</y>
166+
<x>58.7785</x>
167+
<y>-80.9017</y>
168168
<collapsed>false</collapsed>
169169
<displayFilterCaliper>false</displayFilterCaliper>
170170
<reductionOp>sum</reductionOp>
@@ -184,8 +184,8 @@
184184
<first>Replicate</first>
185185
<second>
186186
<description>Replicate</description>
187-
<x>11.7557</x>
188-
<y>-16.1803</y>
187+
<x>-6.18034</x>
188+
<y>-19.0211</y>
189189
<collapsed>true</collapsed>
190190
<displayFilterCaliper>false</displayFilterCaliper>
191191
<reductionOp>max</reductionOp>
@@ -209,16 +209,16 @@
209209
<y>58.7785</y>
210210
<collapsed>false</collapsed>
211211
<displayFilterCaliper>true</displayFilterCaliper>
212-
<reductionOp>max</reductionOp>
212+
<reductionOp>sum</reductionOp>
213213
<order>forward</order>
214214
<format></format>
215215
<customOrderIsInverted>false</customOrderIsInverted>
216216
<customOrder>
217217
</customOrder>
218218
<customOrderComplement>
219219
</customOrderComplement>
220-
<minLabel>0.006685</minLabel>
221-
<maxLabel>0.019880</maxLabel>
220+
<minLabel>0.000001</minLabel>
221+
<maxLabel>0.032921</maxLabel>
222222
<sliceLabel></sliceLabel>
223223
</second>
224224
</pair>
@@ -513,8 +513,8 @@
513513
<symbolEvery>1</symbolEvery>
514514
<id>16</id>
515515
<type>Operation:gather</type>
516-
<x>535.793</x>
517-
<y>417.47</y>
516+
<x>589.793</x>
517+
<y>389.47</y>
518518
<itemTabX>NaN</itemTabX>
519519
<itemTabY>NaN</itemTabY>
520520
<scaleFactor>1</scaleFactor>
@@ -541,8 +541,8 @@
541541
<symbolEvery>1</symbolEvery>
542542
<id>20</id>
543543
<type>VarConstant</type>
544-
<x>494.419</x>
545-
<y>436.588</y>
544+
<x>547.419</x>
545+
<y>398.588</y>
546546
<itemTabX>NaN</itemTabX>
547547
<itemTabY>NaN</itemTabY>
548548
<scaleFactor>1</scaleFactor>
@@ -573,8 +573,8 @@
573573
<symbolEvery>1</symbolEvery>
574574
<id>22</id>
575575
<type>Operation:mean</type>
576-
<x>412.906</x>
577-
<y>399.136</y>
576+
<x>350.906</x>
577+
<y>268.136</y>
578578
<itemTabX>NaN</itemTabX>
579579
<itemTabY>NaN</itemTabY>
580580
<scaleFactor>1</scaleFactor>
@@ -809,6 +809,39 @@
809809
</slider>
810810
<miniPlot>false</miniPlot>
811811
</Item>
812+
<Item>
813+
<name>:&lt;N_{sp}&gt;</name>
814+
<xmin>NaN</xmin>
815+
<xmax>NaN</xmax>
816+
<ymin>NaN</ymin>
817+
<ymax>NaN</ymax>
818+
<y1min>NaN</y1min>
819+
<y1max>NaN</y1max>
820+
<symbolEvery>1</symbolEvery>
821+
<id>46</id>
822+
<type>Variable:flow</type>
823+
<x>417</x>
824+
<y>270</y>
825+
<itemTabX>NaN</itemTabX>
826+
<itemTabY>NaN</itemTabY>
827+
<scaleFactor>1</scaleFactor>
828+
<rotation>0</rotation>
829+
<width>20</width>
830+
<height>20</height>
831+
<ports>
832+
<int>47</int>
833+
<int>48</int>
834+
</ports>
835+
<bookmark>false</bookmark>
836+
<slider>
837+
<stepRel>false</stepRel>
838+
<visible>true</visible>
839+
<min>-1</min>
840+
<max>1</max>
841+
<step>0.1</step>
842+
</slider>
843+
<miniPlot>false</miniPlot>
844+
</Item>
812845
</items>
813846
<groups>
814847
</groups>

models/ecolab_model.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,15 @@ double ModelData::connectivity() const
387387

388388

389389
/* do the offdiagonal mutations */
390-
void do_row_or_col(array<double>& tmp, double range, double minval, double gdist)
390+
void do_row_or_col(array<double>& tmp, Float range, Float minval, Float gdist, Float gen_bias)
391391
{
392392
double r;
393393
unsigned ntrue;
394394
int j, pos;
395-
//tclvar gen_bias("generalization_bias"); /* gen \in [-1,1] */
396-
double gen= /*exists(gen_bias)? (double)gen_bias:*/0.0;
397395

398396
/* create or delete some connections */
399-
r = (2.0*rand())/RAND_MAX - 1+gen;
400-
r = (r>0)? r/(1+gen): r/(1-gen);
397+
r = (2.0*rand())/RAND_MAX - 1+gen_bias;
398+
r = (r>0)? r/(1+gen_bias): r/(1-gen_bias);
401399
if (r!=0) ntrue=(int)(1/fabs(r))-1;
402400
else ntrue = tmp.size();
403401

@@ -448,12 +446,14 @@ void ModelData::mutate(const array<int>& new_sp)
448446
repro_rate <<= new_repro_rate;
449447

450448
array<double> new_mutation(mutation[new_sp]);
451-
//lgspread( new_mutation, gdist );
449+
if (!fixMutation)
450+
lgspread( new_mutation, gdist );
452451
/* limit mutation rate to mut_max */
453452
mutation <<= merge( new_mutation < mut_max, new_mutation, mut_max);
454453

455454
array<double> new_migration(migration[new_sp]);
456-
//lgspread( new_migration, gdist );
455+
if (!fixMigration)
456+
lgspread( new_migration, gdist );
457457
/* limit mutation rate to mut_max */
458458
migration <<= new_migration;
459459

@@ -483,7 +483,7 @@ void ModelData::mutate(const array<int>& new_sp)
483483
pack(interaction.val,mask,ntrue);
484484
tmp1[ new_sp[i] ] = interaction.diag[new_sp[i]];
485485

486-
do_row_or_col(tmp1,range,odiag_min,gdist[i]);
486+
do_row_or_col(tmp1,range,odiag_min,gdist[i],gen_bias);
487487

488488
/* project out connections for col[new_sp[i]] */
489489
mask = interaction.col==unsigned(new_sp[i]);
@@ -492,7 +492,7 @@ void ModelData::mutate(const array<int>& new_sp)
492492
pack( interaction.val, mask, ntrue);
493493
tmp2[ new_sp[i] ] = interaction.diag[new_sp[i]];
494494

495-
do_row_or_col(tmp2,range,odiag_min,gdist[i]);
495+
do_row_or_col(tmp2,range,odiag_min,gdist[i],gen_bias);
496496

497497
/* adjust offdiag vals so that n.\beta n<0 for all positive n */
498498
/* construct list of offdiag vals that sum positively */
@@ -670,7 +670,7 @@ unsigned SpatialModel::migrate()
670670
{
671671
auto& nbr=*n->as<EcolabCell>();
672672
Float salt=&c<&nbr? c.salt: nbr.salt;
673-
array<Float> m=capped_migration * (nbr.density-c.density);
673+
array<int> m=capped_migration * (nbr.density-c.density);
674674
delta[c.idx()]+=m;//*(1 + salt * (abs(m)<cap*array_ns::min(nbr.density,c.density)));
675675
assert(all(c.density>=-delta[c.idx()]));
676676
}

models/ecolab_model.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ struct ModelData
4646
sparse_mat_graph foodweb;
4747
unsigned long long tstep=0, last_mut_tstep=0, last_mig_tstep=0;
4848
//mutation parameters
49-
float sp_sep=0.1, mut_max=0, repro_min=0, repro_max=1, odiag_min=0, odiag_max=1;
50-
49+
Float sp_sep=0.1, mut_max=0, repro_min=0, repro_max=1, odiag_min=0, odiag_max=1, gen_bias=0;
50+
/// flags to disable mutation of mutation and migration rates
51+
bool fixMutation=false, fixMigration=false;
52+
5153
void makeConsistent(size_t nsp);
5254
void random_interaction(unsigned conn, double sigma);
5355
void condense(const array<bool>& mask, size_t mask_true);

0 commit comments

Comments
 (0)