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

Bug fixes, compartmentalisation and documentation for priority predecessor and zones criteria #634

Open
wants to merge 24 commits into
base: mcda-restructure
Choose a base branch
from

Conversation

Rosejoycrocker
Copy link
Collaborator

Closes #633

Separates the priority locations and priority zones criteria into their own functions for ease of testing. Also add further documentation for these criteria in the function docs.

Adds a testset for these criteria constructor functions. Also adds updates for the mcda decision matrix construction tests which were previously not included in the test suite.

@Rosejoycrocker Rosejoycrocker added the bug Something isn't working label Dec 19, 2023
test/mcda.jl Outdated Show resolved Hide resolved
@ConnectedSystems
Copy link
Collaborator

Could you give an overview of what bugs were fixed?

@Rosejoycrocker
Copy link
Collaborator Author

Could you give an overview of what bugs were fixed?

Sure, it's briefly summarized in #633, but I'll describe it more here. In the Matlab version the strong_pred variable is a 2*nsites matrix : https://github.com/open-AIMS/ADRIA_repo/blob/bc29474555015b88fa0a10f7f935408f0b4f0e76/ADRIAfunctions/siteConnectivity.m#L197
where the first column is the site ids. In the Julia version it is a vector :

strong_pred = zeros(Int64, size(C1)...)

When strong_pred is used in predec, the structure used to calculate the priority sites criteria, it is still used in the same way as the matlab version-

Matlab: https://github.com/open-AIMS/ADRIA_repo/blob/bc29474555015b88fa0a10f7f935408f0b4f0e76/ADRIAfunctions/ADRIA_DMCDA.m#L66-L69

Julia:

predec::Matrix{Float64} = zeros(n_sites, 3)
predec[:, 1:2] .= strong_pred
predprior = predec[in.(predec[:, 1], [priority_sites']), 2]

This means L599 above in the Julia version is using predec[1,:] assuming it is a list of site ids, when it is filled with strong_pred on L598, where 2 copies of the vector strong_pred are added to predec.

This difference informed assumptions in how the zone criteria are calculated also, so this PR includes changes to the zone criteria.

@ConnectedSystems
Copy link
Collaborator

Ah okay, sorry I somehow missed the linked issue. But the additional info is nice.

@ConnectedSystems
Copy link
Collaborator

Please format all files to conform to the style guide

@Rosejoycrocker Rosejoycrocker force-pushed the separate-zone-predec-crit branch 4 times, most recently from 2246d40 to d1e96de Compare January 11, 2024 21:36
@Rosejoycrocker
Copy link
Collaborator Author

Rosejoycrocker commented Jan 11, 2024

Please format all files to conform to the style guide

I just formatted, so should be good to go

@Rosejoycrocker Rosejoycrocker force-pushed the separate-zone-predec-crit branch 2 times, most recently from d18662a to 8a68c7a Compare January 23, 2024 22:48
rcps::Vector{Symbol} = Symbol.(:RCP, Int64.(scenarios[:, :RCP]))
return Dict(rcp => rcps .== rcp for rcp in unique(rcps))
end

function scenario_types(scenarios::DataFrame)::Dict{Symbol,BitVector}
function scenario_types(scenarios::DataFrame)::Dict{Symbol, BitVector}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you standardise this formatting rule as well please?

Dict{Symbol, BitVector} should have no space between the types.

@@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo

Suggested change
risk> risk_tol are filtered out.
risk > risk_tol are filtered out.

@@ -187,7 +188,7 @@ function connectivity_strength(TP_base::AbstractMatrix{Float64})::NamedTuple
C2 = outdegree_centrality(g)

# For each node, find strongly connected predecessor (by number of connections)
strong_pred = zeros(Int64, size(C1)...)
strong_pred = zeros(Int64, (size(C1)...))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you add the parenthesis in or was this the formatter?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this would work without the splat or parenthesis

Suggested change
strong_pred = zeros(Int64, (size(C1)...))
strong_pred = zeros(Int64, size(C1))

@Rosejoycrocker Rosejoycrocker force-pushed the separate-zone-predec-crit branch 2 times, most recently from 3e2f8c3 to 8fd18dc Compare February 6, 2024 05:10
@ConnectedSystems
Copy link
Collaborator

Hi Rose, could I get an update on this?

I still see style issues but perhaps you've addressed these and have not yet pushed the changes?

@Rosejoycrocker
Copy link
Collaborator Author

Hi Rose, could I get an update on this?

I still see style issues but perhaps you've addressed these and have not yet pushed the changes?

Hi Takuya, I recently pushed formatting changes but I just copied from the formatting setup guide you and Dan just added because I've noticed some things are a bit different. I'm just about to go and reformat all my PRs

@ConnectedSystems
Copy link
Collaborator

Hi Rose, could you rebase this onto main please?

@Rosejoycrocker Rosejoycrocker force-pushed the separate-zone-predec-crit branch 3 times, most recently from 098c952 to 7829620 Compare February 12, 2024 22:24
@Rosejoycrocker
Copy link
Collaborator Author

Rosejoycrocker commented Feb 13, 2024

In priority sites we use strong_pred to favour sites that are the strongest sources of the listed priority sites, and in the priority zones criteria we use strong_pred to favour sites which are the strongest sources to a zone. strong_pred is not used directly as a criteria. Do you mean not appropriate as a measure of larval connectivity?

@ConnectedSystems
Copy link
Collaborator

ConnectedSystems commented Feb 13, 2024

In priority sites we use strong_pred to favour sites that are the strongest sources of the listed priority sites, and in the priority zones criteria we use strong_pred to favour sites which are the strongest sources to a zone. strong_pred is not used directly as a criteria. Do you mean not appropriate as a measure of larval connectivity?

No no, I missed that it wasn't using strong_pred directly inside guided_site_selection(), but was going through two additional steps.

@Rosejoycrocker
Copy link
Collaborator Author

Yeah it's a bit confusing because strong_pred is what is stored in mcda_vars. This PR separates the processing of strong_pred to create the zone and priority sites criteria into 2 functions (previously it was just done inside guided_site_selection). So priority_location_criteria() adds proportional value to sites that are the strongest sources of sites in the priority list by indexing strong_pred at the priority site locations and then using those resulting indices to add value to the priority criteria. It's similar for the zones criteria (calculated in priority_zones_criteria()) but value is added to the whole zone and to any sites which are the strongest source for sites in the zone.

It also fixes a bug which was occuring because strong_pred used to be a matrix with site ids in the first column and strongest source sites in the second column. The methods were still assuming it had this structure when it no longer does so I've made changes to account for this.

Rosejoycrocker and others added 24 commits February 16, 2024 08:05
…er exists, to be updated shortly in another PR)
Remove `factors` input from `rsa()` and use scenario dataframe column names instead
…ity locations functions

`strong_pred` and `zones` must be the same size
Zones criteria was incorrectly indexing using `strong_pred` - should have been using sites in `strong_pred` which contain priority zone sites, not values of `strong_pred` at sites in priority zones
`strong_pred` should be a matrix, with site ids in the first column. Without this, calcs in priority predecessor and zones criteria are incorrect
Simplify and fix how `strong_pred` is used in zoning criteria

Add to docs
Remove unnecessary findall

Remove unnecessary findall
…priority zone have the highest criteria value
Was checking column 6 which is priority predecessors, instead of 8 which is leftover space
Formatting
@ConnectedSystems
Copy link
Collaborator

I'll be merging this into the changes for MCDA Rose

@ConnectedSystems ConnectedSystems changed the base branch from main to mcda-restructure February 21, 2024 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Priority sites criteria expecting different structure for strong_pred than what is implemented
3 participants