Skip to content

Better Z helper functions - #15

Merged
asgr merged 2 commits into
masterfrom
better_Z_gen
Sep 11, 2026
Merged

asgr merged 2 commits into
masterfrom
better_Z_gen

Conversation

@asgr

@asgr asgr commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Added functions to auto create Z inputs for relevant samplers (like AIES)

Copilot AI lite review requested due to automatic review settings September 2, 2026 09:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 a Lowlander result (and Iterations/Thinning) to auto-generate algorithm-specific Specs, including Z for AIES/DEMC and grids for GG/AGG.
  • Improved Lowlander() output validation (strict scalar return contract for likefunc) and added helper extractors (Lowlander_kept(), Lowlander_Z(), Lowlander_best()).
  • Added Lowlander support in Highlander() (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 '.... If Npar is NULL, paste0() returns character(0) and the warning becomes empty ("no message supplied"), which makes debugging much harder. The warning should render a placeholder when Npar is 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.

Comment thread R/Highlander.R Outdated
Comment on lines +165 to +167
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.')
}
Comment thread R/Specs_help.R Outdated
Comment on lines +428 to +429
!identical(dim(Specs_list$Z)[2], Npar) ||
(.sizeable && dim(Specs_list$Z)[1] != .z_rows(Iterations, Thinning))) {
Comment thread R/Specs_help.R
Comment on lines +137 to 139
} else if (is.null(dots$Nc)) {
message('AIES: using Nc = 2 * length(parm.names) = ', Nc, '.')
}
@asgr

asgr commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

@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>

Copilot AI commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@copilot Fix the code for all comments in this review thread.

When a review comment includes a suggested change, apply the s...

Implemented the requested fixes from that review thread in commit fd8ab5b.

@asgr
asgr merged commit a44df8d into master Sep 11, 2026
4 checks passed
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.

3 participants