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

Add spatial visualisations for decision matrices #893

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Rosejoycrocker
Copy link
Collaborator

Adds method to viz.map for plotting decision matrices and aggregate scores on a set of side-by-side maps.

@Rosejoycrocker
Copy link
Collaborator Author

Here is the plot from running the example code in analysis.md:

criteria_plots_hs

(any advice on what the grey boxes are appreciated, I'll try to remove)

@Zapiano
Copy link
Collaborator

Zapiano commented Oct 28, 2024

@Rosejoycrocker this PR has a conflict and the tests are not passing. About the tests, this could be due to a problem that was fixed yesterday, not sure.

@Rosejoycrocker
Copy link
Collaborator Author

@Rosejoycrocker this PR has a conflict and the tests are not passing. About the tests, this could be due to a problem that was fixed yesterday, not sure.

I'm looking into it now

Remove incorrect additions from rebase
@Rosejoycrocker
Copy link
Collaborator Author

Tests are passing and conflicts reolved now @Zapiano :)

@@ -131,6 +131,30 @@ Index of locations ordered by their rank
function rank_by_index(
dp::T, dm::YAXArray, method::Union{Function,DataType}
)::Vector{Int64} where {T<:DecisionPreference}
res = get_criteria_aggregate(dp, dm, method)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I imagine res comes from result, right? Everything any function returns is a result (the result of that function), so calling a variable result is a little bit vague (maybe with a few exceptions). Maybe calling it aggregate_score or something else that helps the reader would be better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its a result structure that the MCDA package uses, so it contains more than just the aggregate score. Maybe change it to decision_results or something?

@@ -131,6 +131,30 @@ Index of locations ordered by their rank
function rank_by_index(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function signature doesn't match the docstring (I know this wasn't updated by you, if you prefer just open an issue to fix that on a separate PR).

# Returns
Returns raw aggreagted score for a set of locations
"""
function get_criteria_aggregate(
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. You say this function returns a raw aggregated score for a set of locations, so maybe it could be called aggregated_scores or criteria_aggregated_scores? I just think this get part of the name may be a little redundant. And, since you are aggregating scores, adding the word scores at the end may clarify what this returns.

  2. The function signature doesn't match the docstring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for spotting, I'll fix the signature and change the name to criteria_aggregated_scores

@@ -251,6 +256,75 @@ function ADRIA.viz.map!(
axis_opts
)
end
function ADRIA.viz.map(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since map is a very generic name, I don't think we should make a method called map plot a specific kind of map only (only maps of decision matrix scores). What I mean is: it is interesting to have a map function that plots multiple maps like you did, but not only for decision matrix. I could plot the average of some different metrics for each location, for example.

So, I propose we have an intermediate function selection_criteria_map, for example, that receives this matrix and this vector, concatenate them to become just a single matrix; builds up a tuple of titles for each plot; and call a map function that receives this matrix and the titles_tuple (and whatever else it needs) and plots this grid of maps. Then, in the future, if we want to plot other multiple map figure, it can be easily reused.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer the current approach but I'm not 100% up on the context here, just latching onto the suggestion to create a separate map plotting function. Julia is not strictly an object oriented language and isn't intended to be used like Python or Java.

The advantage of having multiple dispatch (or something like it, as in R) is to prevent everyone from having to remember a lot of function names. Is it map or vizualize_selection_criteria_as_map or display_map or plot_selection_criteria_map or...

As a user I don't want to have to remember endless possible function names for specific use cases. I just want a map.

Instead, this behaviour of:

  1. You have a vector of results -> map() produces a single map.
  2. You have a matrix of results -> map() produces a series of maps.

is sensible to me.

But again, I don't have full context.

https://www.juliaopt.org/meetings/santiago2019/slides/stefan_karpinski.pdf

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand and I agree with what you said.

My problem with how this function is defined right now is that it doesn't plot selection criteria scores in particular. It plots multiple maps with whatever you pass as an argument. But still the names of variables and the plots default titles are related to this specific kind of plot (multiple maps with selection criteria scores). It's like having a function called sum and the arguments are called prime_number_a and prime_number_b. If it sums more than just prime numbers, they should be called number_a and number_b or whatever.

About the need for a specific function called selection_criteria_map, maybe we don't need one, I agree. depending on how this map function with multiple maps is defined we can just use this one and that's fine. My comment was more about making this map general than about the need of a specific function with a specific name for this kind of plot.

Copy link
Collaborator

@ConnectedSystems ConnectedSystems Nov 6, 2024

Choose a reason for hiding this comment

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

Incidentally @Rosejoycrocker the variable names/titles displayed in the figure should be run through human_readable() (this isn't the exact function name but you should be able to find it easily)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure what the outcome of this discssuion is, but I've separated this into a generic map() method which plots multiple maps in a grid given a matrix of inputs, and then a function in location_selection.jl that plots criteria and an aggregate score given a decision matrix input and vector of scores (using the generic map() function). Not sure what you think but I think being able to quickly plot criteria and an output score is useful, hence its inclusion in location_selection.jl.

@@ -251,6 +256,75 @@ function ADRIA.viz.map!(
axis_opts
)
end
function ADRIA.viz.map(
rs::Union{Domain,ResultSet},
M::YAXArray,
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. This doesn't match the docstring.
  2. I am against naming variables with a single letter except in very specific cases. You have little to gain and everyone that reads you code (including your future self) have a lot of time to lose with this. :)

One is generic matrix mapping, the other is specifically for mapping criteria and aggregate scores
Update function signatures
@Rosejoycrocker
Copy link
Collaborator Author

criteria_plots
Most recent version of the plotting output (grid has been removed)

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 17.94872% with 32 lines in your changes missing coverage. Please review.

Project coverage is 51.14%. Comparing base (ad39467) to head (1a677cc).

Files with missing lines Patch % Lines
ext/AvizExt/viz/spatial.jl 9.52% 19 Missing ⚠️
ext/AvizExt/viz/location_selection.jl 0.00% 11 Missing ⚠️
src/viz/viz.jl 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #893      +/-   ##
==========================================
- Coverage   51.44%   51.14%   -0.31%     
==========================================
  Files          72       72              
  Lines        4782     4818      +36     
==========================================
+ Hits         2460     2464       +4     
- Misses       2322     2354      +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Formatting

Put func docstrings on single lines
@Rosejoycrocker
Copy link
Collaborator Author

I think I've addressed your comments @Zapiano , let me know if you have others

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.

3 participants