Last updated: 2 October 2026.
- The user writes one or more
discrepancy()and onesimulation(). - The package builds a calculator. For each posterior draw it gives two numbers per discrepancy: one for the data, one for a replicate.
runCalibration()turns those numbers into a PPP and then a CPPP.
- Five built-in discrepancies. A user discrepancy is a nimbleFunction with
contains = discrepancyBase, a setup(model, dataNodes, modelNodes)and arun()returning one number. simulation(mode, latentNodes). Conditional redraws the data. Marginal redraws the named latents and everything below them.completeNodes()works out every node list once. The calculator, the simulate function and the MCMC all use it.runCalibrationNIMBLE()compiles the model, the MCMC and the calculator in one call, on one model.- The calculator saves and restores only the nodes it changes.
makeDiscrepancyExtractor()reads discrepancies the MCMC already computed. Placeholder: nothing feeds it yet.
78a01efcompleteNodes()andsimulation(mode, latentNodes).ee625bdCalculator, simulate function andrunCalibrationNIMBLE()usecompleteNodes(). The calculator restores the model withmodelValues.afe7b6cDefaultcontrol$discentries filled from the nodes.
- Three layers.
runCalibration(): the engine, for models written in plain R.runCalibrationNIMBLE(): the advanced NIMBLE function.cppp_nimble(): a simple wrapper for new users. Later.
- No user simulation function in
runCalibrationNIMBLE(). Conditional and marginal cover the real cases. DropsimulateNewDataFun. Anything else goes throughrunCalibration(). - R discrepancies use the package's replicates. The package builds the
simulate function from
simulation()and passes it to the user'sdiscFun. - Same replicate for every discrepancy. For each draw, all discrepancies see the same replicate dataset.
print(),summary(),plot()for the result.- Update the docs (README, cheatsheet) for
simulation(mode, latentNodes).
- One
discrepanciesargument for both kinds? nimbleFunction and R function, told apart by the type offun.discFunwould then go too. What does an R discrepancy receive:function(data, theta)? Waiting for input. - The
controllist. It carries duplicates (names and nodes), an uncompiled model, and silently ignores top-level entries when sublists exist. Its shape depends on the question above. - Prior predictive. If wanted, a third mode of
simulation().
- Keep the shape of the nodes. Started: only data, parameters, latents
and the discrepancy nodes are still flattened, all in
simulationSpec.RanddiscrepancySpec.R. Data and parameters need it. Check the other three. - Run calibration replicates in parallel. One set of compiled objects per
core, built once.
futureis the suggested tool. The loop is inrunCalibration.R. - Reuse the long chain's sampler tuning in the short chains. Daniel Turek
has code on the nimble forum. Not the same as
transferAutocorrelation(). - An end-to-end test in marginal mode.
- After setting a draw, calculate the parameters' dependencies, never the
parameters (
self = FALSE). A parameter can be derived (sigmafromlog_sigma), and calculating it would overwrite the drawn value. - A discrepancy's data nodes must be among the data nodes.
- Compile everything in one
compileNimble(list(...))call. - Draws and replicates travel between pieces as R matrices and vectors. Using
modelValuesthere was considered and dropped: the copying is tiny next to the MCMC, and the engine works with R matrices.modelValuesis used only inside the calculator, to save and restore the model. - Calculator computes discrepancies after the MCMC. Extractor reads values
the MCMC computed. Neither makes the PPP: that is
runCalibration(). - Not everything compiles (
sort()does not). Wrap R code withnimbleRcall(). One defined inside the package must be exported. - Compiled code cannot pick columns by name. The wrapper orders the parameter columns first.
asymmin the Newcomb example hardcodes order statistics 6 and 61 (n = 66).
| File | Holds |
|---|---|
R/discrepancySpec.R |
discrepancy(), completeDiscrepancy(), makeDiscrepancyNimbleFun() |
R/builtinDiscrepancies.R |
discrepancyBase and the five built-ins |
R/simulationSpec.R |
simulation(), completeNodes() |
R/makeDiscrepancyCalculator.R |
the calculator |
R/makeSimulateNewDataFun.R |
makes one replicate from a draw |
R/makeDiscrepancyExtractor.R |
reads discrepancies from MCMC output |
R/makeDiscrFunction.R |
makeOfflineDiscFun(), the plain-R route |
R/runCalibration.R |
the engine |
R/runCalibrationNIMBLE.R |
the NIMBLE wrapper |
R/cpppResult-class.R |
the result object |
R/transferAutocorrelation.R |
placeholder |
inst/examples/newcomb_spec_offline.R |
worked example |