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

Energy Score Functions for Model Evaluation #289

Merged
merged 12 commits into from
Feb 3, 2025
Merged

Conversation

trobacker
Copy link
Collaborator

R script containing functions to get energy scores from model output and produce basic summaries of scores.

@trobacker trobacker changed the title Energy Scores Functions for Model Evaluation Energy Score Functions for Model Evaluation Jan 24, 2025
@rogersbw rogersbw self-assigned this Jan 24, 2025
Double braket.

Co-authored-by: Zhian N. Kamvar <[email protected]>
Copy link
Collaborator

@rogersbw rogersbw left a comment

Choose a reason for hiding this comment

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

I believe the scoring procedure used here is slightly different from what is discussed here:

https://github.com/reichlab/variant-nowcast-hub?tab=readme-ov-file#background

Happy to meet and discuss on Monday! Overall great coding though!

src/model_scoring_functions.R Outdated Show resolved Hide resolved
src/model_scoring_functions.R Outdated Show resolved Hide resolved
… * 100 samples of multinomial counts, on each day/date.
@trobacker
Copy link
Collaborator Author

trobacker commented Jan 26, 2025

Hi @rogersbw, I modified the ES calculation to include 10000 samples, 100 (posterior draws) * 100 (samples of multinomial counts) = 10000 total on each day/date. Do you mind reviewing that piece (last commit) and confirming that's correct?
(I left a few debugging comments if you want to print a few things locally - I'll remove these later)

It certainly takes longer to run now and I'll plan on optimizing the code next - i.e. replacing for loops with say functional programming techniques. I want to be sure the ES algorithm is correct first. Thanks!

Copy link
Collaborator

@rogersbw rogersbw left a comment

Choose a reason for hiding this comment

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

I have one question about handling location date combinations with 0 observed counts. See the comment within the code.


## Generate 100 multinomial observations for samp_props
# Need the N for each loc/day from the validation data
N <- sum(subset(targets,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be moved outside of the loop, as for each combination of loc and day, the N will stay constant through this loop.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, how are day/loc combinations with 0 observations handled? As I'm running through this, it seems to be keeping in the 0 observation days and giving them an energy score of 0 (perfect score). I believe we will want these to be NA values instead.

Copy link
Collaborator Author

@trobacker trobacker Jan 27, 2025

Choose a reason for hiding this comment

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

Thanks for the comments, Ben! I modified the energy scores to have NA when the observed counts sum to 0. I also moved the N assignment. I'll focus on code optimization next.

Copy link
Collaborator

@rogersbw rogersbw left a comment

Choose a reason for hiding this comment

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

Sorry to keep sending it back! I had not well thought about handling the unscored location/dates until I saw your message on slack. I believe these corrections should do what we want?

df_scores <- rbind(df_scores, df_temp)
next
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good, when we're doing code optimization, could initialize an array of the correct size filled with NA, and then replace only for positive counts.

src/model_scoring_functions.R Outdated Show resolved Hide resolved
src/model_scoring_functions.R Outdated Show resolved Hide resolved
src/model_scoring_functions.R Outdated Show resolved Hide resolved
@trobacker
Copy link
Collaborator Author

trobacker commented Jan 29, 2025

As discussed in our modeling meeting today, I'm going to have the energy scores available for all dates/locs and build another function that will filter for ones we've generally agreed to use for final model scoring according to the hub evaluation scheme.
The motivation for this is that some modelers express interest in getting scores for all data used though we will exclude some locs/dates for final scoring on the hub.

@trobacker
Copy link
Collaborator Author

trobacker commented Feb 3, 2025

FWIW, I wrote a different version that I was hoping to be computationally faster which uses expand.grid to avoid nested for-loops, and an apply to sample the multinomials faster, but it actually took 5 seconds longer than my latest commit.

@rogersbw
Copy link
Collaborator

rogersbw commented Feb 3, 2025

Looks good, merge away!

@trobacker trobacker merged commit 825c125 into main Feb 3, 2025
@trobacker trobacker deleted the model-scoring-functions branch February 3, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants