Skip to content

Commit 04436b0

Browse files
Added connectivity measure suitable for testing May stability criterion
1 parent d0fde15 commit 04436b0

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

models/ecolab_model.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,15 @@ EcolabPoint<B>::mutate(const E& mut_scale)
376376
#endif
377377
}
378378

379+
// Given by the variance of the offdiagonal components, when each diagonal component is normalised to 1
380+
double ModelData::connectivity() const
381+
{
382+
if (species.size()==0) return 0;
383+
array<double> v=interaction.val/sqrt(interaction.diag[interaction.row]*interaction.diag[interaction.col]);
384+
// divide by total number of offdiagonal components, as the data is sparse
385+
return sum(v*v)/(species.size()*(species.size()-1));
386+
}
387+
379388

380389
/* do the offdiagonal mutations */
381390
void do_row_or_col(array<double>& tmp, double range, double minval, double gdist)

models/ecolab_model.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ struct ModelData
5353
void condense(const array<bool>& mask, size_t mask_true);
5454
void mutate(const array<int>&);
5555
double complexity() {return ::complexity(foodweb);}
56+
/// May criterion connectivity σ²
57+
double connectivity() const;
5658
};
5759

5860
template <class E, class P> struct RoundArray;

models/panmictic_ecolab.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from ecolab_model import panmictic_ecolab as ecolab
22
from random import random
3+
import math
34
# initial number of species
45
nsp=100
56

@@ -41,14 +42,16 @@ def randomList(num, min, max):
4142
ecolab.updateConnectionPlot()
4243

4344
def step():
44-
ecolab.generate()
45+
ecolab.generate(100)
4546
ecolab.mutate()
4647
ecolab.updateConnectionPlot()
4748
ecolab.condense()
4849
nsp=len(ecolab.species)
4950
statusBar.configure(text=f't={ecolab.tstep()} nsp:{nsp}')
5051
plot('No. species',ecolab.tstep(),nsp)
5152
plot('Density',ecolab.tstep(),ecolab.density(), pens=ecolab.species())
53+
plot('Conn-Nsp',ecolab.connectivity(),nsp)
54+
plot('Conn*density',ecolab.tstep(),ecolab.connectivity()*nsp)
5255

5356
gui(step,ecolab)
5457

0 commit comments

Comments
 (0)