Skip to content

Commit

Permalink
Fix typo in priority_zone_criteria docs function docs and format fu…
Browse files Browse the repository at this point in the history
…nction docs
  • Loading branch information
Rosejoycrocker committed Jan 11, 2024
1 parent d0a8a07 commit 2246d40
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
35 changes: 23 additions & 12 deletions src/decision/dMCDA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ function rank_sites!(
end

"""
retrieve_ranks(S::Matrix, site_ids::Vector, weights::Vector{Float64}, mcda_func::Function)::Matrix{Union{Float64,Int64}}
retrieve_ranks(S::Matrix, site_ids::Vector, weights::Vector{Float64}, mcda_func::Type{<:MCDMMethod})::Matrix{Union{Float64,Int64}}
retrieve_ranks(S::Matrix, site_ids::Vector, weights::Vector{Float64}, mcda_func::Function)
::Matrix{Union{Float64,Int64}}
retrieve_ranks(S::Matrix, site_ids::Vector, weights::Vector{Float64}, mcda_func::
Type{<:MCDMMethod})::Matrix{Union{Float64,Int64}}
retrieve_ranks(site_ids::Vector, scores::Vector, maximize::Bool)::Matrix{Union{Float64,Int64}}
Get location ranks using mcda technique specified in mcda_func, weights and a decision matrix S.
Expand Down Expand Up @@ -307,7 +309,8 @@ function retrieve_ranks(
end

"""
create_decision_matrix(site_ids, in_conn, out_conn, leftover_space, wave_stress, heat_stress, predec, risk_tol)
create_decision_matrix(site_ids, in_conn, out_conn, leftover_space, wave_stress,
heat_stress, predec, risk_tol)
Creates criteria matrix `A`, where each column is a selection criterium and each row is a site.
Sites are then filtered based on heat and wave stress risk.
Expand All @@ -333,7 +336,8 @@ Columns indicate:
- `wave_stress` : Probability of wave damage.
- `heat_stress` : Probability of site being affected by heat stress
- `predec` : List of priority predecessors (sites strongly connected to priority sites).
- `risk_tol` : Tolerance for wave and heat risk (∈ [0,1]). Sites with heat or wave risk> risk_tol are filtered out.
- `risk_tol` : Tolerance for wave and heat risk (∈ [0,1]). Sites with heat or wave
risk> risk_tol are filtered out.
"""
function create_decision_matrix(
site_ids::Vector{Int64},
Expand Down Expand Up @@ -916,18 +920,20 @@ function within_depth_bounds(
end

"""
priority_location_criteria(strong_pred::Vector{Int64}, priority_locations::Vector{Int64}, location_ids::Vector{Int64})::Vector{Float64}
priority_location_criteria(strong_pred::Vector{Int64}, priority_locations::Vector{Int64},
location_ids::Vector{Int64})::Vector{Float64}
Calculates the priority location criteria, which prioritises priority locations and locations which are larval sources for these.
Calculates the priority location criteria, which prioritises priority locations and locations
which are larval sources for these.
# Arguments
- `strong_pred` : Strongest predecessor locations for each location.
- `priority_locations` : Priority locations
- `location_ids` : Full set of location indices (same size as `strong_pred`)
# Returns
Priority criteria value for each location, the larger the value the better that location contributes to prioritising locations
in the `priority_locations` list.
Priority criteria value for each location, the larger the value the better that location
contributes to prioritising locations in the `priority_locations` list.
"""
function priority_location_criteria(
strong_pred::Vector{Int64},
Expand All @@ -938,6 +944,7 @@ function priority_location_criteria(

# Work out which priority predecessors are connected to priority locations
predprior = strong_pred[in.(location_ids, [priority_locations'])]

# Find index of these locations in location_ids
pred_idx = dropdims(sum(predprior .== location_ids'; dims = 1); dims = 1) .> 0

Expand All @@ -946,17 +953,19 @@ function priority_location_criteria(
end

"""
priority_zones_criteria(strong_pred::Vector{Int64}, zones::Vector{String}, priority_zones::Vector{String},
location_ids::Vector{Int64}; pred_w::Float64=0.2)::Vector{Float64}
priority_zones_criteria(strong_pred::Vector{Int64}, zones::Vector{String},
priority_zones::Vector{String}, location_ids::Vector{Int64}; pred_w::Float64=0.5)::Vector{Float64}
Calculates the priority zone criteria, which prioritises priority GBRMPA zones and zones which are larval sources for these.
Calculates the priority zone criteria, which prioritises priority GBRMPA zones and zones which
are larval sources for these.
# Arguments
- `strong_pred` : Strongest predecessor locations for each location.
- `zones` : Zone classification for each location
- `priority_zones` : Zones to prioritse (in order of priority)
- `location_ids` : Full set of location indices (same size as `strong_pred`)
- `pred_w` : Weight designating importance of locations being in the zone vs. larval sources for the zone.
- `pred_w` : Weight designating importance of locations being in the zone vs. larval sources
for the zone.
# Returns
Priority zones value for each location, the larger the value the better that location contributes to prioritising
Expand All @@ -970,6 +979,7 @@ function priority_zones_criteria(
pred_w::Float64 = 0.5,
)::Vector{Float64}
n_sites = length(zones)

# Find set of priority zones and scoring system depending on zone priority
zone_ids = intersect(priority_zones, unique(zones))
zone_weights = mcda_normalize(collect(length(zone_ids):-1:1))
Expand All @@ -979,6 +989,7 @@ function priority_zones_criteria(
for (k::Int64, z_name::String) in enumerate(zone_ids)
# Find locations which are strongest predecessors of locations in the zone
add_zone_weight = strong_pred[zones .== z_name]

# Positional indices of locations in location_ids
pred_zone_idx =
dropdims(sum(add_zone_weight .== location_ids'; dims = 1); dims = 1) .> 0
Expand Down
24 changes: 16 additions & 8 deletions src/decision/location_selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ using NamedDims, AxisKeys
using ADRIA: connectivity_strength, relative_leftover_space, site_k_area

"""
_location_selection(domain::Domain, sum_cover::AbstractArray, mcda_vars::DMCDA_vars, guided::Int64)::Matrix
_location_selection(domain::Domain, sum_cover::AbstractArray, mcda_vars::DMCDA_vars,
guided::Int64)::Matrix
Select locations for a given domain and criteria/weightings/thresholds, using a chosen
MCDA method.
Expand Down Expand Up @@ -57,9 +58,12 @@ function _location_selection(
end

"""
rank_locations(domain::Domain, scenarios::DataFrame, sum_cover::NamedDimsArray, area_to_seed::Float64; target_seed_sites=nothing, target_fog_sites=nothing)::NamedDimsArray
rank_locations(domain::Domain,scenarios::DataFrame, sum_cover::NamedDimsArray, area_to_seed::Float64, agg_func::Function,
iv_type::Union{String,Int64}; target_seed_sites=nothing, target_fog_sites=nothing)::AbstractArray
rank_locations(domain::Domain, scenarios::DataFrame, sum_cover::NamedDimsArray,
area_to_seed::Float64; target_seed_sites=nothing, target_fog_sites=nothing)
::NamedDimsArray
rank_locations(domain::Domain,scenarios::DataFrame, sum_cover::NamedDimsArray,
area_to_seed::Float64, agg_func::Function,iv_type::Union{String,Int64};
target_seed_sites=nothing, target_fog_sites=nothing)::AbstractArray
Return location ranks for a given domain and scenarios.
Expand Down Expand Up @@ -184,8 +188,10 @@ end

"""
ranks_to_frequencies(ranks::NamedDimsArray, n_ranks::Int64)
ranks_to_frequencies(ranks::NamedDimsArray{D,T,3,A}; n_ranks=length(ranks.sites), agg_func=x -> dropdims(sum(x; dims=:timesteps); dims=:timesteps),) where {D,T,A}
ranks_to_frequencies(ranks::NamedDimsArray{D,T,2,A}; n_ranks=length(ranks.sites), agg_func=nothing) where {D,T,A}
ranks_to_frequencies(ranks::NamedDimsArray{D,T,3,A}; n_ranks=length(ranks.sites),
agg_func=x -> dropdims(sum(x; dims=:timesteps); dims=:timesteps),) where {D,T,A}
ranks_to_frequencies(ranks::NamedDimsArray{D,T,2,A}; n_ranks=length(ranks.sites),
agg_func=nothing) where {D,T,A}
Returns the frequency with which each location was ranked across scenarios.
Uses the results from `rank_locations()`.
Expand Down Expand Up @@ -243,7 +249,8 @@ end

"""
location_selection_frequencies(ranks::NamedDimsArray; n_iv_locs::Int64=5)
location_selection_frequencies(iv_log::NamedDimsArray{D,T,4,A}; dims::Union{Symbol,Vector{Symbol}}=:coral_id) where {D,T,A}
location_selection_frequencies(iv_log::NamedDimsArray{D,T,4,A}; dims::Union{Symbol,
Vector{Symbol}}=:coral_id) where {D,T,A}
Determines the count of times each location was selected for a specific intervention over a
set of scenarios.
Expand Down Expand Up @@ -281,7 +288,8 @@ end
_drop_single(x::AbstractMatrix) = dropdims(x; dims = (findall(size(x) .== 1)...,))

"""
selection_score(ranks::NamedDimsArray{D,T,3,A}; dims::Vector{Symbol}=[:scenarios, :timesteps]) where {D,T,A}
selection_score(ranks::NamedDimsArray{D,T,3,A}; dims::Vector{Symbol}=[:scenarios,
:timesteps]) where {D,T,A}
selection_score(ranks::NamedDimsArray{D,T,2,A}) where {D,T,A}
selection_score(ranks::NamedDimsArray, dims::Vector{Symbol})
Expand Down
3 changes: 2 additions & 1 deletion src/ecosystem/connectivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ end

"""
connectivity_strength(TP_base::AbstractArray)::NamedTuple
connectivity_strength(area_weighted_TP::AbstractMatrix{Float64}, cover::Vector{Float64}, TP_cache::AbstractMatrix{Float64})::NamedTuple
connectivity_strength(area_weighted_TP::AbstractMatrix{Float64}, cover::Vector{Float64},
TP_cache::AbstractMatrix{Float64})::NamedTuple
Create in/out degree centralities for all nodes, and vector of their strongest predecessors.
Expand Down

0 comments on commit 2246d40

Please sign in to comment.