Skip to content

Commit

Permalink
Better function names for output + corrected = false for std()
Browse files Browse the repository at this point in the history
  • Loading branch information
alaindanet authored and iago-lito committed Feb 21, 2023
1 parent 7470ef8 commit 9a44039
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/EcologicalNetworksDynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export cascademodel
export ClassicResponse
export connectance
export cpad
export cv
export coefficient_of_variation
export DefaultGrowthParams
export DefaultMaxConsumptionParams
export DefaultMetabolismParams
Expand Down Expand Up @@ -128,7 +128,6 @@ export shannon_diversity
export simpson
export simulate
export species_persistence
export species_richness
export trophic_levels
export trophic_structure

Expand Down
6 changes: 3 additions & 3 deletions src/measures/functioning.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ When applied to a vector of biomass, e.g.
species which biomass is above `threshold`.
When applied to a vector of biomass, e.g.
species_persistence(n::Vector; threshold = eps()), it returns the proportion of
`species_persistence(n::Vector; threshold = eps())`, it returns the proportion of
species which biomass is above `threshold`.
# Examples
Expand Down Expand Up @@ -134,8 +134,8 @@ Returns a named tuple of total and species biomass, averaged over the last `last
Can also handle a species x time biomass matrix, e.g. `biomass(mat::Matrix;)` or a
vector, e.g. `biomass(vec::Vector;)`.
Can also handle a species x time biomass matrix, e.g. biomass(mat::Matrix;) or a
vector, e.g. biomass(vec::Vector;).
Can also handle a species x time biomass matrix, e.g. `biomass(mat::Matrix;)` or a
vector, e.g. `biomass(vec::Vector;)`.
# Examples
Expand Down
6 changes: 0 additions & 6 deletions src/measures/stability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ Thibaut, L. M., & Connolly, S. R. (2013). Understanding diversity–stability
relationships : Towards a unified model of portfolio effects. Ecology Letters,
16(2), 140‑150. https://doi.org/10.1111/ele.12019
# Reference
Thibaut, L. M., & Connolly, S. R. (2013). Understanding diversity–stability
relationships : Towards a unified model of portfolio effects. Ecology Letters,
16(2), 140‑150. https://doi.org/10.1111/ele.12019
# Examples
```jldoctest
Expand Down
32 changes: 14 additions & 18 deletions test/measures/test-functioning.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ end
sim_zero = simulates(params, [0, 0]; verbose = false)

# Total biomass should converge to K
@test biomass(sim_one_sp; last = 1).total get_parameters(sim_one_sp).environment.K[2] rtol =
0.001
@test biomass(sim_one_sp; last = 1).total
get_parameters(sim_one_sp).environment.K[2] rtol = 0.001

# Species sub selection works
@test biomass(sim_one_sp; last = 1, idxs = [1]).sp[1]
Expand All @@ -73,34 +73,30 @@ end
# Other hill diversity numbers
## Shannon
@test shannon_diversity(sim_two_sp[:, end]) ==
shannon_diversity(sim_two_sp; last = 1) ==
log(2)
shannon_diversity(sim_two_sp; last = 1) == log(2)

@test shannon_diversity(sim_one_sp[:, end]) ==
shannon_diversity(sim_one_sp; last = 1)
0.0 # 0 entropy if 1 species only
shannon_diversity(sim_one_sp; last = 1) 0.0 # 0 entropy if 1 species only

@test isnan(shannon_diversity(sim_zero[:, end])) ==
isnan(shannon_diversity(sim_zero; last = 1)) # Not defined for 0 species
isnan(shannon_diversity(sim_zero; last = 1)) # Not defined for 0 species

## Simpson
@test simpson(sim_two_sp[:, end]) ==
simpson(sim_two_sp; last = 1) ==
1 / sum(2 .^ [1 / 2, 1 / 2])
@test simpson(sim_one_sp[:, end]) ==
simpson(sim_one_sp; last = 1) ==
1 / sum(2 .^ 1) ==
0.5# 0.5 if 1 species only

# Not defined for 0 species
@test isnan(simpson(sim_zero[:, end])) == isnan(simpson(sim_zero; last = 1))
1 / sum(2 .^ 1) == 0.5# 0.5 if 1 species only
@test isnan(simpson(sim_zero[:, end])) ==
isnan(simpson(sim_zero; last = 1)) # Not defined for 0 species

# Community evenness
# Maximum equity of species biomass
@test evenness(sim_two_sp[:, end]) == evenness(sim_two_sp; last = 1) 1.0
# Should be NaN if 1 species
@test isnan(evenness(sim_one_sp[:, end])) == isnan(evenness(sim_one_sp; last = 1))
# Should be NaN if 0 species
@test isnan(evenness(sim_zero[:, end])) == isnan(evenness(sim_zero; last = 1))
@test evenness(sim_two_sp[:, end]) ==
evenness(sim_two_sp; last = 1) 1.0 # Maximum equity of species biomass
@test isnan(evenness(sim_one_sp[:, end])) ==
isnan(evenness(sim_one_sp; last = 1))# Should be NaN if 1 species
@test isnan(evenness(sim_zero[:, end])) ==
isnan(evenness(sim_zero; last = 1))# Should be NaN if 0 species

end

0 comments on commit 9a44039

Please sign in to comment.