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

Time trend for expected values #491

Merged
merged 17 commits into from
Aug 16, 2024
Merged

Time trend for expected values #491

merged 17 commits into from
Aug 16, 2024

Conversation

jamesturner246
Copy link
Contributor

@jamesturner246 jamesturner246 commented Aug 14, 2024

Resolves #492

This change adds new StaticLinear.json params: ExpectedTrend, which are raised to the power of the iteration number and used to multiply risk factor expected values, to simulate (exponentially) changing population average of nutrients over time.

These are passed into adjustable models as shared pointers rather than references -- see https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.html

All adjustable RF model code is updated to use the new trends.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

@jamesturner246 jamesturner246 marked this pull request as ready for review August 15, 2024 12:08
@jamesturner246 jamesturner246 changed the title Time trend Time trend for expected values Aug 15, 2024
@alexdewar
Copy link
Contributor

@jamesturner246 I'm guessing you meant to tag us as reviewers rather than assigning this to us?

@jamesturner246
Copy link
Contributor Author

Oh whoops. Thanks!

Copy link
Contributor

@alexdewar alexdewar left a comment

Choose a reason for hiding this comment

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

Besides my question about the use of pow(), it all looks fine to me. I've made a few small suggestions.

MEASURE_FUNCTION();

const auto &info = config.modelling.baseline_adjustment;
if (!hgps::core::case_insensitive::equals(info.format, "CSV")) {
throw hgps::core::HgpsException{"Unsupported file format: " + info.format};
}

auto table = hgps::RiskFactorSexAgeTable{};
auto table = std::make_unique<hgps::RiskFactorSexAgeTable>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change table to a std::unique_ptr btw? Not a problem; just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noted clang-tidy began complaining about model members as const and reference complicating automatic ctor generation -- see https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.htmlv and links therein.

I suppose I could have made it into a shared pointer within the model class, but thought this way we only std move a pointer to the definition ctor. 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok. That's interesting.

I think it's the right decision to return it as a std::unique_ptr. Out of interest, is it actually shared though? Or could it be left as a std::unique_ptr?

Copy link
Contributor Author

@jamesturner246 jamesturner246 Aug 16, 2024

Choose a reason for hiding this comment

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

It's shared once it enters the risk factor model definition class (with the risk factor model class), since it's technically a factory. I keep it unique here and move it into a shared pointer inside the definition class. Not sure if that's good practice or not..

double expected = expected_->at(sex, factor).at(age);
if (expected_trend_->contains(factor)) {
int elapsed_time = context.time_now() - context.start_time();
expected *= pow(expected_trend_->at(factor), elapsed_time);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these arguments the wrong way round? I'm trying to wrap my head round why you'd raise to the power of elapsed_time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it' look a bit strange, but it's basically an exponential trend in time, With time factor t, we have with_trend = without_trend * t^elapsed. So for year zero, we have with_trend = without_trend * t^0 = without_trend, and t factor changes exponentially with years.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That reminds me, I need to bound these values...

@jamesturner246 jamesturner246 merged commit e766691 into main Aug 16, 2024
5 checks passed
@jamesturner246 jamesturner246 deleted the time_trend branch August 16, 2024 11:58
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.

Add time trend to expected RF values
4 participants