BecksLab / EcologicalNetworksDynamics.jl

A simulator for ecological dynamics written in Julia.
GNU Affero General Public License v3.0
18 stars 3 forks source link

Loosen default tolerance `ΔC` for large richnesses. #115

Closed iago-lito closed 1 year ago

iago-lito commented 1 year ago

The following simple script fails:

using EcologicalNetworksDynamics
using Random

Random.seed!(12)
FoodWeb(nichemodel, 50, C=0.2)

with a misleading error message:

ERROR: Could not generate adequate network with C=0.2 and ΔC=0.0004 before the maximum number of iterations (100000.0) was reached. Is the constraint impossible to solve?

As it turns out, the constraint is not crazy to solve, but the default value for ΔC is too low to achieve such an "edge-perfect" (1 / S^2) connectance. Also, users can tweak this value with an argument named tol, but this is not easily discoverable from the message alone.

Suggestions:

Thomalpas commented 1 year ago

On the last point, isn't the purpose of using the probabilistic (I learnt this word on Monday 😊) niche model to generate the food webs because we don't want a random graph, we want the structure it provides?

ismael-lajaaiti commented 1 year ago

Yes @Thomalpas, the last point is not a possibility. We draw graph randomly using the niche model and we can't change this as it the standard model used to generate realistic trophic networks.

To complete your message @iago-lito there are actually two separate issues:

  1. poor default value of tolerance value (and wrong name in the error message) that is too restrictive in general and can lead to an error.
  2. while generating the food web, we check that resulting network has no cycles or disconnected species, however for high connectance it is very unlikely to generate network without cycles, to fix we can: a) expose keyword arguments to check or not for cycles and disconnected species, b) throw a warning message when the user gives a too high connectance for which it is very unlikely to generate a network without cycles.

EDIT: I've created a dedicated issue for 2 #116.

Thomalpas commented 1 year ago

Thank you @ismael-lajaaiti I could have phrased my point better. I agree we need to retain the potential to use the niche model as it is the standard model as you said.

But I was also raising the point that the niche model is not random but probabilistic (using the beta distribution I believe), which seemed to me another reason not to replace it with a random method

iago-lito commented 1 year ago

Yeah, sorry @Thomalpas I haven't been precise enough. My suggestion was to investigate some way to generate a niche model network according to their probabilistic rules, with an algorithm that would not only guarante that it be a correct "niche network", but also that its connectance be the one we need :)

This said, I would not be surprised that this algorithm be either impossible to write, or that it's still lying beyond the scope of science in 2023 ¯\_(ツ)_/¯