Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for loops & disconnected species. #83

Merged
merged 5 commits into from
Jan 9, 2023

Conversation

ismael-lajaaiti
Copy link
Collaborator

@ismael-lajaaiti ismael-lajaaiti commented Jan 4, 2023

Answer #76.

When creating a FoodWeb with a structural model (e.g. niche model), we check that the generated FoodWeb:

  1. does not have cycle
  2. does not have disconnected species
  3. has a number of links in $[L - \Delta L; L + \Delta L]$ where $L$ is the value given by the user and $\Delta L$ is the tolerance controlled by the tol keyword argument (the same applies if the user provides a connectance instead of a number of links)

For point 1. and 2. I used functions from Graphs.jl as these operations are not trivial (see also #77).

For now, the checks for cycle(s) and disconnected species are only if the user use a structural model. However if the user build the FoodWeb with another method, for instance by providing directly an adjacency matrix, I don't check for cycle(s) and disconnected species. Should I add these checks and throw a warning if they do not pass? (Throwing an error would be too rough IMO, an informed user might want to model a food web with cycles).

@andbeck
Copy link
Collaborator

andbeck commented Jan 5, 2023

I think yes to the warning for users delivering non-niche model networks.

Copy link
Collaborator

@iago-lito iago-lito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is your review! That's a good job again, and I find that the quality of your code is improving PR after PR :)

I see no major concern with your implementation, and my comments only points to possible minor ameliorations.

I agree that it would make sense that the error thrown in case of a cyclic/disconnected structural model be downgraded to a simple warning because a user inputting A or a graph directly possibly knows what they are doing. For instance, I would be glad to "paralellize" the simulation of two small systems by merging them into a single disconnected network.

I hear you are crafting a new commit to add the warning rn. Let's see this when it's ready :)

src/measures/structure.jl Show resolved Hide resolved
test/measures/test-structure.jl Outdated Show resolved Hide resolved
test/measures/test-structure.jl Outdated Show resolved Hide resolved
src/inputs/foodwebs.jl Show resolved Hide resolved
src/inputs/foodwebs.jl Outdated Show resolved Hide resolved
src/inputs/foodwebs.jl Outdated Show resolved Hide resolved
src/inputs/foodwebs.jl Show resolved Hide resolved
src/inputs/foodwebs.jl Outdated Show resolved Hide resolved
src/inputs/foodwebs.jl Show resolved Hide resolved
test/inputs/test-foodwebs.jl Show resolved Hide resolved
@ismael-lajaaiti
Copy link
Collaborator Author

ismael-lajaaiti commented Jan 6, 2023

Here is the commit to throw a warning if the food web has cycle(s) or disconnected species, when not using structural models. Note that the warning can be silent with the quiet kwarg. For instance :

FoodWeb([0 0; 0 0]) # throw a warning, because sp. are disconnected
FoodWeb([0 0; 0 0], quiet = true) # do not throw a warning thanks to 'quiet'

@ismael-lajaaiti
Copy link
Collaborator Author

ismael-lajaaiti commented Jan 6, 2023

@iago-lito here is the commit integrating your suggestions, everything should be in there (hope I missed nothing). ✨

@iago-lito
Copy link
Collaborator

Great! Let's land this now. Congratulations :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect loops and disconnected species & improve structural models.
3 participants