Skip to content

Commit

Permalink
feat: add kw version of linearfilter
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisot committed Oct 10, 2024
1 parent 3be9001 commit e2196f0
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/random/linearfilter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ function linearfilter(N::SpeciesInteractionNetwork{<:Partiteness, <:Binary}; α:
return SpeciesInteractionNetwork(copy(N.nodes), edges)
end

"""
linearfilter(N::SpeciesInteractionNetwork{<:Partiteness, <:Binary}; interaction::T=1.0, generality::T=1.0, vulnerability::T=1.0, connectance::T=1.0) where {T <: AbstractFloat}
Keyword version of `linearfilter` where the parameters are all set to 1.0 by default.
"""
function linearfilter(
N::SpeciesInteractionNetwork{<:Partiteness, <:Binary};
interaction::T = 1.0,
generality::T = 1.0,
vulnerability::T = 1.0,
connectance::T = 1.0,
) where {T <: AbstractFloat}
α = [interaction, generality, vulnerability, connectance]
return linearfilter(N; α = α)
end

@testitem "The linearfilter function returns the correct type" begin
nodes = Unipartite([:A, :B, :C, :D, :E, :F])
edges = Binary(rand(Bool, (richness(nodes, 1), richness(nodes, 2))))
Expand Down Expand Up @@ -84,6 +100,18 @@ end
end
end

@testitem "We can use the keyword version of linearfilter" begin
import Statistics
nodes = Unipartite([:A, :B, :C, :D, :E, :F])
edges = Binary(rand(Bool, (richness(nodes, 1), richness(nodes, 2))))
N = SpeciesInteractionNetwork(nodes, edges)
R = linearfilter(N; α = [1.0, 0.0, 0.0, 0.0])
S = linearfilter(N; generality=0.0, vulnerability=0.0, connectance=0.0)
for interaction in interactions(N)
@test R[interaction[1], interaction[2]] == S[interaction[1], interaction[2]]
end
end

"""
nullmodel(::Type{Degree}, N::SpeciesInteractionNetwork{<:Partiteness, <:Binary})
Expand Down Expand Up @@ -203,4 +231,4 @@ end
@test R[:B, :b] == 3 / 3
@test R[:B, :c] == 1 / 3
@test R[:C, :c] == 1 / 3
end
end

0 comments on commit e2196f0

Please sign in to comment.