Analyse the Simulated Dynamics
Once the dynamics of the community have been simulated, we can analyse the results to better understand the behaviour of the community. To do so, we provide a few functions to compute various properties of the community dynamics.
Let's first simulate the dynamics of a species-rich community with the niche model:
using EcologicalNetworksDynamics, Plots
S = 20 # Number of species.
C = 0.1 # Connectance.
foodweb = Foodweb(:niche; S, C)
m = default_model(foodweb)
B0 = rand(S) # Vector of initial biomasses.
t = 100 # Simulation time.
sol = simulate(m, B0, t)
retcode: Success
Interpolation: 3rd order Hermite
t: 36-element Vector{Float64}:
0.0
0.06386844727462122
0.14627165536579728
0.22883174565162434
0.3172277066398547
0.437358837681323
0.5777264842673768
0.7770620279364578
1.0202435533210048
1.3650101440007452
⋮
44.7789145976874
48.81834107298829
52.6458811276706
59.83729272583517
66.19851380161774
74.13308881400377
81.97536401939114
91.64467801320588
100.0
u: 36-element Vector{Vector{Float64}}:
[0.7562704523721434, 0.7775119939252512, 0.4934712560266089, 0.15272995134848244, 0.8230440276144474, 0.24966857561705436, 0.49182090062124795, 0.8678731681961157, 0.29337440850120045, 0.36694042792262394, 0.904783966404354, 0.7282271304794009, 0.8563243773667578, 0.38898354159389137, 0.5163047180070125, 0.39414388642250386, 0.012660628010274344, 0.14279289241183168, 0.31588418466450296, 0.8276395298003312]
[0.7912686591172828, 0.7879079009923095, 0.4975812156396402, 0.15697530825632725, 0.8288528272673289, 0.2593884223416226, 0.4972152527352207, 0.8619073377356102, 0.30578820312807903, 0.3756651593752839, 0.9258450194377033, 0.7412605320634633, 0.8349146247216992, 0.39778178036592304, 0.5210495436831054, 0.39481693137523427, 0.013237628164211356, 0.14866386404480486, 0.25011888937669496, 0.5090158141965344]
[0.8137185189929851, 0.8016900370408259, 0.5029983792019891, 0.16254547223770216, 0.8359662697774156, 0.26425668802446695, 0.4958178084511365, 0.8458437763698899, 0.32253586240741244, 0.3870103252633543, 0.9241850542297907, 0.7386228336878488, 0.809906742384554, 0.40869503253295775, 0.5265602915097131, 0.39199667751739214, 0.013599041514764824, 0.1559089140448133, 0.19281104107533095, 0.28468042793946796]
[0.8183778098418905, 0.8158522791304397, 0.5084996299538272, 0.16818767966705625, 0.8422140858518621, 0.26325260432651043, 0.4903487472925322, 0.8239704932228227, 0.3398590895848868, 0.3983022525995576, 0.9013750349647032, 0.7240406280934689, 0.7870996626586325, 0.41901707071837785, 0.5312805808349914, 0.38665669954632487, 0.01366145567714041, 0.16299368283755777, 0.1566519759597893, 0.18608223032243013]
[0.8149432351003132, 0.8313700942523103, 0.5144232019956166, 0.1742520114457628, 0.8476348073998293, 0.2594919087307624, 0.4830185046785365, 0.7970040119731369, 0.3587656303829598, 0.41016751837544696, 0.8679687314739543, 0.7034199206665586, 0.7646732409344034, 0.4292989891723141, 0.5354035928612563, 0.3794349347876384, 0.013587269568426916, 0.17049838953948027, 0.13179279075938924, 0.1357909452790837]
[0.8049019907605592, 0.8530117842982382, 0.5224616046331049, 0.18245478556753572, 0.8526934567540065, 0.2527967654356643, 0.47234095889894573, 0.7573636840896636, 0.38473410898613036, 0.42573978281625163, 0.8183801100356931, 0.6727316622332324, 0.7369701449456065, 0.4419121001380982, 0.5395143110183057, 0.36838844270926707, 0.013397207954681014, 0.18059699619005376, 0.11061971369058814, 0.10166768073186036]
[0.790160274415936, 0.8790646851004753, 0.5317323649455624, 0.19184968968859653, 0.8551489045081464, 0.24425734886785397, 0.4597598406557148, 0.7092956094855558, 0.41501841472708284, 0.44288478614966614, 0.7603906400162227, 0.6363993372949991, 0.7080732311091696, 0.4546238739909057, 0.5423410435394771, 0.35475486126306804, 0.013126175579770265, 0.19221445810407242, 0.09569102831138758, 0.08132306579641542]
[0.7673496384661407, 0.9173862238955074, 0.5444209810604891, 0.2045076651323329, 0.8523880747111766, 0.2319900835375098, 0.4424172394998848, 0.6411794375123483, 0.45693273169081755, 0.46481357742632856, 0.6826727970792711, 0.5868425180168357, 0.6725362911960115, 0.4690532127394976, 0.5433344106894926, 0.33525461256352124, 0.012712736239731452, 0.2082326364917451, 0.08364444892765106, 0.06655347248542762]
[0.7388893279183215, 0.9660321008245155, 0.5586287909203169, 0.21819316694710522, 0.8399003624373137, 0.21749633193051235, 0.4224869195308487, 0.5621305131141522, 0.5046891969130665, 0.487058878617678, 0.5980461727220172, 0.5315411953627632, 0.6366447630393238, 0.4815717454649488, 0.541129664874759, 0.31231162035700155, 0.012202315315973038, 0.22675368127275605, 0.07622295099107562, 0.05772904987258389]
[0.699250264256208, 1.0379460039939856, 0.57507764890615, 0.23280183935487214, 0.8080433427353629, 0.19828222272364884, 0.3966332702738916, 0.46292913254316254, 0.5632979554947977, 0.5094817127316819, 0.49809927903807344, 0.4637969242487661, 0.5975328273954029, 0.49216256730394814, 0.5347739465401715, 0.2824614510564566, 0.011498700679254304, 0.2507052328330623, 0.07238722887929064, 0.052320699599023926]
⋮
[0.25573069666685383, 1.5560289110121046, 0.040504835460067196, 0.0025159637619173755, 0.3723843167386513, 0.019625071757510305, 0.19630236435726417, 0.08262751761093516, 0.688832050858957, 0.5464572541674971, 0.025277404145423427, 0.09162533617377343, 0.5917856166865703, 0.5913796995984547, 0.5915668255389346, 0.14469367079532985, 0.003762779860593314, 0.4784102668445551, 0.22018121916251465, 0.19105131394518776]
[0.2592721901748465, 1.5574014240878304, 0.03903249660843011, 0.0018239364113985899, 0.3725991603105944, 0.018790273188513715, 0.19615443397293325, 0.0832085261564297, 0.6882747873038554, 0.5464318550032157, 0.02380494045020151, 0.09003084801617686, 0.592169858145832, 0.5909337858013967, 0.5915534656971488, 0.144878020903248, 0.0037813209833161684, 0.47801489706086814, 0.22024013199231413, 0.1908481380703142]
[0.26231337280129957, 1.55850322890013, 0.03782742623675526, 0.0013483876864972093, 0.37268674906757765, 0.018047942885426334, 0.19603074397986398, 0.08372156007963315, 0.6880757156598382, 0.5463570940370349, 0.022545556034258247, 0.08866983202976624, 0.592761205244325, 0.5902891076144149, 0.5918018344640124, 0.14502204696537235, 0.0037936451614537185, 0.4778126841582875, 0.22031333318624957, 0.19070892911904455]
[0.267350849123346, 1.5601178083549314, 0.03595133094069996, 0.0007625412944829235, 0.3728104086087963, 0.016773708754427866, 0.19588972014148254, 0.08456778652775629, 0.6879352762113279, 0.546145752606593, 0.02047926746906156, 0.08646294226985428, 0.5917735789992853, 0.5922751508661425, 0.5919730443978889, 0.14525363610909084, 0.0038057031198773963, 0.47719528189449684, 0.2204030906931301, 0.1904667312471503]
[0.2711824128466479, 1.5612471498687024, 0.034624865698659434, 0.00046339199084182694, 0.37302259010455174, 0.015766093502391002, 0.19567107431215752, 0.08518904739500062, 0.6878382502422521, 0.5461044587705722, 0.0189225275869276, 0.08484257468097567, 0.5919180138732174, 0.591817825508189, 0.5918783404263399, 0.14544167142113998, 0.0038064394410060303, 0.47739737299545154, 0.22041543478442557, 0.19023720237148664]
[0.2752601566772351, 1.5623890204446755, 0.03329760921555121, 0.00024905490716866914, 0.37320031043161506, 0.014644306163958593, 0.19547529156803073, 0.0858026248969031, 0.6877209487125207, 0.5459977921724977, 0.017260576799165366, 0.08316269084052942, 0.5918338765153833, 0.5918546052744884, 0.591842093834322, 0.14564202938239068, 0.0037967124322977235, 0.47743853821821014, 0.22045672879117187, 0.1900278339436279]
[0.2786777964187318, 1.56329058063884, 0.03225589933780135, 0.00013530145934132458, 0.3733490923085627, 0.01366445904056742, 0.19532300873182176, 0.0862697158951426, 0.6876205665345622, 0.54593632727748, 0.015864266214472088, 0.08181293021444853, 0.5918063897895905, 0.5918021019679568, 0.5918046903888844, 0.14582527752685254, 0.0037782611762427975, 0.47749497276508224, 0.22049074394961204, 0.18986208460767218]
[0.2822237742733296, 1.5641766247995488, 0.03124520167639319, 6.353713688254111e-5, 0.3734895893338572, 0.012605652381398965, 0.19517839964151326, 0.08669818191106952, 0.6875301215740698, 0.5458724196909229, 0.014407768353726697, 0.08048296826854924, 0.591769381061175, 0.5917702585552373, 0.5917697288593176, 0.14602998824281174, 0.0037465339154981736, 0.477541259582201, 0.2205290896625908, 0.1897036808862585]
[0.28481049843205225, 1.5647876519967168, 0.03055660717125213, 3.3269226623737364e-5, 0.37358617262117255, 0.011803374785560677, 0.19508165104783115, 0.08697036196673992, 0.6874664253402204, 0.5458320989972734, 0.013337610478294824, 0.0795708695966052, 0.5917460744804744, 0.5917458927633371, 0.5917460024567938, 0.14618930062903987, 0.003713236422996831, 0.477573236788737, 0.22055728700562563, 0.18959718135243928]
When running the dynamics of a rich initial pool of species, we generally observe the extinction of some species. You can access the number of surviving species at the end of the simulation with:
richness(sol[end]) # Number of surviving species at the end of the simulation.
20
You can also get the trajectory of the species richness through time with:
richness(sol) # Richness at each time step.
36-element Vector{Int64}:
20
20
20
20
20
20
20
20
20
20
⋮
20
20
20
20
20
20
20
20
20
Similarly, you can compute the persistence, that is the proportion of species that are present at each time step:
persistence(sol) # Equivalent to: richness(sol) ./ S
36-element Vector{Float64}:
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
⋮
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
Or the total biomass of the community:
total_biomass(sol)
36-element Vector{Float64}:
10.360450017306036
10.099254914018081
9.879349194203812
9.737723693084803
9.622939729377178
9.492677291887485
9.358109633550077
9.18422278936172
8.989658748427034
8.739482250587212
⋮
6.690743115143095
6.689244490338865
6.6886303953112405
6.6883936096298235
6.687786737820936
6.687352801221742
6.687064466243665
6.686834159806351
6.686704803559787
Or the shannon diversity index:
shannon_diversity(sol)
36-element Vector{Float64}:
17.003042156473537
17.018914051101156
16.84269041479207
16.701708835026928
16.625121833698028
16.58966794899239
16.58876088284237
16.599438744026422
16.58530224704094
16.486348020264284
⋮
12.00211083287161
11.974457671599753
11.95153868213353
11.915219824138523
11.888954620182508
11.861608176052352
11.839144418648377
11.816029237426255
11.799208783606419
For example, you can plot how a few of these properties evolve through time:
time = sol.t
plot(
time,
total_biomass(sol);
xlabel = "Time",
ylabel = "Observable",
label = "Total biomass",
)
plot!(time, richness(sol); label = "Richness")
plot!(time, shannon_diversity(sol); label = "Shannon diversity")