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

feature representation in solutions #73

Closed
jeffreyhanson opened this Issue Apr 4, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@jeffreyhanson
Copy link
Contributor

jeffreyhanson commented Apr 4, 2018

A prioritizr user emailed me suggesting that we include a function to calculate how well features are represented in a solution.

Here's one idea for what the function definitions might look like, where x is the problem used to generate the solution and y is the solution.

# x=ConservationProblem, y=Raster
feature_representation(x, y, type = c("absolute", "relative")[1], ....)

# x=ConservationProblem, y=Spatial
feature_representation(x, y, solution_columns = grep("solution", names(y), value = TRUE), 
                                     type = c("absolute", "relative")[1], ...)

# x=ConservationProblem, y=data.frame
feature_representation(x, y, solution_columns = grep("solution", names(y), value = TRUE), 
                                     type = c("absolute", "relative")[1], ...)

# x=ConservationProblem, y=numeric
feature_representation(x, y, type = c("absolute", "relative")[1], ...)
@ricschuster

This comment has been minimized.

Copy link
Member

ricschuster commented Apr 5, 2018

That's a great idea!

The feature_representation function looks good to me. One question though, would it be easy to store the target type in x?

How did you envision this working with portfolio solutions? Just return the representation of the first solution, return a representation data.frame?

Final question, how would this work with Zones?

@jeffreyhanson

This comment has been minimized.

Copy link
Contributor

jeffreyhanson commented Apr 26, 2018

I'm sorry for closing this before I responded to your questions, I completely forgot to respond to them and I only just remembered this now after I closed the issue. I've patched in an implementation of the function, but if you think it could be improved, we can reopen this issue and I can take another stab at it.

Here's a link to the documentation with some examples of the implementation (https://prioritizr.github.io/prioritizr/reference/feature_representation.html), and with regards to your specific questions:

  1. Yeah, x contains information on the target types, but the function at the moment outputs both the amount and proportion of each feature held in the solution. I think user's will probably want both outputs even if the targets are only absolute or relative.

  2. I think user's will need to loop/lapply over each "solution" object and merge the results together. The rationale behind this is that handling solutions in data.frame objects is tricky, because when inputting a vector of column names, each column could correspond to a different solution or each column could contain correspond to the status of different zones in a single solution. So, while we could have the function accept a list of vectors to organise which column names are for different zones and which names are for different solutions, I think this implementation is a lot simpler.

  3. The version I've implemented outputs it in a long-format, so it includes a zone column for problems with multiple zones and doesn't include the column for problems with a single zone.

@ricschuster

This comment has been minimized.

Copy link
Member

ricschuster commented Apr 27, 2018

Thanks Jeff. Looks good to me and I have to admit that I forgot about zones in my response. So the way you implemented this makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment