Skip to content

Period filters for model fitting and allocation parameters; upsert into key-only tables - #84

Open
mmyrte wants to merge 6 commits into
developfrom
claude/gallant-dijkstra-93w9qx
Open

mmyrte wants to merge 6 commits into
developfrom
claude/gallant-dijkstra-93w9qx

Conversation

@mmyrte

@mmyrte mmyrte commented Oct 19, 2026

Copy link
Copy Markdown
Member

Two changes, both needed by the evoland-experiments 2026-05-ssp-ch rework: its backcast now holds the last observed transition out of calibration.

Period filters

Model fitting and allocation-parameter estimation can now be restricted to a subset of the observed periods, so the last observed transition can be held out and backcast out of sample.

  • trans_pred_data_v(id_trans, id_pred, id_period_anterior = NULL) restricts the training rows to these anterior periods. The filter is applied in inst/trans_pred_data.sql, after the existing "drop the last period" window.
  • fit_partial_models(..., id_period_anterior = NULL) and fit_full_models(..., id_period_anterior = NULL) pass it through, in direct-learner and score-select mode. In score-select mode it should match what was passed to fit_partial_models().
  • create_alloc_params_t(id_period_post = NULL) estimates only from the period pairs that end in these periods.

NULL keeps the current behaviour everywhere. The new arguments are checked with the is_integerish() predicate from #82.

commit_upsert on tables whose columns are all keys

For a table with no non-key columns, MERGE was generated with when matched then update set and an empty assignment list, which DuckDB rejects. Such a table now only inserts the unmatched rows. trans_preds_t is one: upserting a second run's predictor selection failed. Separately, trans_preds_t's active binding uses "overwrite", unlike the other per-run tables, so db$trans_preds_t <- x replaces every run's rows. That is left as is here; it may be worth a follow-up.

Tests

  • test_db_evoland.R: trans_pred_data_v() with id_period_anterior returns only those anterior periods; create_alloc_params_t() with an empty period selection errors.
  • test_integ_trans_models_t.R: fit_partial_models() with a hold-out scores fewer rows than without one.
  • test_db_ducklake.R: upserting into a key-only table inserts the new rows and keeps the matched ones.

tinytest::test_package("evoland", at_home = TRUE): all ok, 662 results. The branch has develop merged in, so the diff is just these two changes.


Generated by Claude Code

fit_partial_models(), fit_full_models() and trans_pred_data_v() take
id_period_anterior, create_alloc_params_t() takes id_period_post, so the
last observed transition can be held out of calibration and used for a
backcast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGUMMMQKK6iCRSBxmhR3xo
MERGE had a 'when matched then update set' with an empty assignment list,
which DuckDB rejects; such a table now only inserts the unmatched rows.
trans_preds_t is one such table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGUMMMQKK6iCRSBxmhR3xo
Comment thread R/pred_data_t.R Outdated
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGUMMMQKK6iCRSBxmhR3xo
@mmyrte mmyrte moved this to Backlog in evoland-plus Oct 22, 2026

This branch has not been deployed

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants