Repository navigation
Better Z helper functions - #15
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
There are confirmed logic issues that can break runs (NA-unsafe if(any(...)) in Highlander and DEMC Z validation/diagnostics in Specs_help).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR enhances the ergonomics and robustness of running LaplacesDemon algorithms by adding “auto-fill” helpers for Specs (especially ensemble / grid-based samplers) and by allowing Highlander() to seed starts and sampler inputs from a prior Lowlander() run to avoid out-of-bounds initialization failures.
Changes:
- Expanded
Specs_help()to optionally use aLowlanderresult (andIterations/Thinning) to auto-generate algorithm-specificSpecs, includingZfor AIES/DEMC and grids for GG/AGG. - Improved
Lowlander()output validation (strict scalar return contract forlikefunc) and added helper extractors (Lowlander_kept(),Lowlander_Z(),Lowlander_best()). - Added
Lowlandersupport inHighlander()(argument + seeding logic + parallel-dispatch safety) and updated documentation/vignette accordingly.
File summaries
| File | Description |
|---|---|
| vignettes/LD-Algorithms.Rmd | Documents Specs_help() usage and Lowlander-based seeding patterns for restricted-likelihood models. |
| R/Specs_help.R | Implements Lowlander-seeded auto-generation/repair for Specs (notably AIES/DEMC Z, grids, and additional validation/warnings). |
| R/Lowlander.R | Makes Lowlander’s likefunc contract enforcement strict and preserves alignment by validating per-sample outputs before unlisting. |
| R/Lowlander_Z.R | Adds helper functions to extract kept samples and build Z/best start vectors from Lowlander results. |
| R/Highlander.R | Adds Lowlander argument, validates it early, seeds parm/lower/upper and (when defaulted) Specs, and adjusts multicore dispatch forwarding. |
| NAMESPACE | Adds imports for approx/rnorm used by the new helper logic. |
| man/Specs_help.Rd | Documents new Specs_help() arguments and Lowlander-seeding behavior. |
| man/Lowlander.Rd | Documents stricter likefunc return contract and new helper links. |
| man/Lowlander_helpers.Rd | Adds man page for the new Lowlander helper functions. |
| man/Highlander.Rd | Documents Highlander(Lowlander=...) behavior and interactions with Specs/LDargs. |
| DESCRIPTION | Adds testthat (suggested) and sets testthat edition config. |
| .github/workflows/main.yml | Adds testthat to CI dependencies. |
Review details
Suppressed comments (1)
R/Specs_help.R:465
- The warning message concatenates
' x ', Npar, ' x '.... IfNparisNULL,paste0()returnscharacter(0)and the warning becomes empty ("no message supplied"), which makes debugging much harder. The warning should render a placeholder whenNparis unknown.
warning(paste0('DEMC: Z must be a 3-D array of dim ',
if (.sizeable) .z_rows(Iterations, Thinning) else 'floor(Iterations/Thinning)+1',
' x ', Npar, ' x ', Nc, '. Set to NULL so LaplacesDemon ',
'regenerates it. Pass Iterations and Thinning to Specs_help ',
'to have the array built for you.'))
- Files reviewed: 12/12 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if(any(parm < Lowlander$lower | parm > Lowlander$upper)){ | ||
| message('Highlander: parm sits outside the Lowlander plausible region; LaplacesDemon evaluates the model there first and stops if the posterior is not finite, so this can abort the run regardless of the seeded Specs. Consider parm = Lowlander(...)$best.') | ||
| } |
| !identical(dim(Specs_list$Z)[2], Npar) || | ||
| (.sizeable && dim(Specs_list$Z)[1] != .z_rows(Iterations, Thinning))) { |
| } else if (is.null(dots$Nc)) { | ||
| message('AIES: using Nc = 2 * length(parm.names) = ', Nc, '.') | ||
| } |
|
@copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |
Co-authored-by: asgr <5617132+asgr@users.noreply.github.com>
Implemented the requested fixes from that review thread in commit fd8ab5b. |
Added functions to auto create Z inputs for relevant samplers (like AIES)