| Title: | Multivariate Normal CDF and SUN Density with CppAD Derivatives |
|---|---|
| Description: | Evaluates the cumulative distribution function of the multivariate normal distribution using specialized bivariate/trivariate algorithms for dimension <= 3 and Genz quasi-Monte Carlo for higher dimensions, with gradient and Hessian with respect to the upper integration limits computed via CppAD automatic differentiation. Also provides the SUN(2,2), SUN(3,3) and SUN(4,4) densities with gradient and Hessian with respect to a block-Cholesky parameter vector, Gauss-Hermite utilities, and KL minimisation of SUN approximations on weighted quadrature. |
| Authors: | Patrick Brown [aut, cre, cph] |
| Maintainer: | Patrick Brown <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.2.0 |
| Built: | 2026-10-16 21:43:15 UTC |
| Source: | https://github.com/eborgnine/adlaplace |
Genz quasi-Monte Carlo MVN probabilities with gradient and Hessian, SUN(3,3)/SUN(4,4) log-densities with derivatives with respect to a block-Cholesky parameter vector, and KL minimisation of SUN approximations on weighted Gauss-Hermite quadrature.
Maintainer: Patrick Brown [email protected] [copyright holder]
Authors:
Patrick Brown [email protected] [copyright holder]
Evaluates the log-density (or density) of a SUN(3,3) distribution using the
block-Cholesky parameterization from make_sun_params(). For a matrix
of observations the returned value is the summed log-likelihood, or a
weighted sum if weights is supplied. Derivatives are with respect to
the 21-component parameter vector only; the data are treated as fixed.
dsun( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric vector of length 3 or an |
par |
Numeric vector of length 21; see |
log |
If |
deriv |
Integer derivative order: |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for the orthant probabilities in the SUN density. |
n_threads |
Number of OpenMP threads for parallel shard evaluation.
Defaults to |
weights |
Optional numeric vector of length |
A list with value and error. If deriv >= 1,
also gradient (length 21). If deriv >= 2, also
hessian ().
Builds per-observation CppAD shard tapes for the summed SUN log-likelihood
with the data x fixed and the independent variables equal to the
21-parameter vector. Use this for MLE: build once, then call
$eval(par) at new parameter values. Pass weights for a
weighted sum (e.g. Gauss–Hermite KL objectives).
dsun_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric vector of length 3 or |
par_seed |
Seed parameter vector used when building the tape. |
n_points, n_shifts, seed
|
QMC settings passed to |
n_threads |
Default number of OpenMP threads for |
weights |
Optional numeric vector of length |
An object of class "admvn_sun_tape" with components
eval(par, log = TRUE, deriv = 0, n_threads = 0) and
optim_fns() for optim(): fn/gr share one
deriv = 1 evaluation cached by parameter value.
Like dsun(), but the length-21 parameter vector uses the joint
hyperspherical map of make_sun_hs_params() instead of the block-Cholesky
layout of make_sun_params().
dsun_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric vector of length 3 or an |
par |
Numeric vector of length 21; see |
log |
If |
deriv |
Integer derivative order: |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for the orthant probabilities in the SUN density. |
n_threads |
Number of OpenMP threads for parallel shard evaluation.
Defaults to |
weights |
Optional numeric vector of length |
A list with value and error. If deriv >= 1,
also gradient. If deriv >= 2, also hessian.
make_sun_hs_params(), dsun_hs_fun(), dsun()
Like dsun_fun(), for the joint hyperspherical parameterization of
make_sun_hs_params().
dsun_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric vector of length 3 or |
par_seed |
Seed parameter vector (length 21) for |
n_points, n_shifts, seed
|
QMC settings passed to |
n_threads |
Default number of OpenMP threads for |
weights |
Optional numeric vector of length |
An object of class "admvn_sun_tape" with eval() and
optim_fns() (same interface as dsun_fun()).
Evaluates the log-density (or density) of a SUN(2,2) distribution using the
block-Cholesky parameterization from make_sun22_params(). For a matrix
of observations the returned value is the summed log-likelihood, or a
weighted sum if weights is supplied. Derivatives are with respect to
the 10-component parameter vector only.
dsun22( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun22( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric vector of length 2 or an |
par |
Numeric vector of length 10; see |
log |
If |
deriv |
Integer derivative order: |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for orthant CDFs. |
n_threads |
Number of OpenMP threads for parallel shard evaluation. |
weights |
Optional numeric vector of length |
A list with value and error. If deriv >= 1,
also gradient (length 10). If deriv >= 2, also
hessian ().
make_sun22_params(), dsun22_fun(), dsun()
Builds per-observation CppAD shard tapes for the (weighted) SUN(2,2)
log-likelihood with data x fixed. Use for KL / MLE: build once, then
call $eval(par) or $optim_fns().
dsun22_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun22_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric vector of length 2 or an |
par_seed |
Seed parameter vector used when building the tape. |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for orthant CDFs. |
n_threads |
Default OpenMP threads for |
weights |
Optional numeric vector of length |
An object of class "admvn_sun22_tape" with
eval() and optim_fns() (cached fn/gr).
SUN(2,2) density with joint hyperspherical parameterization
dsun22_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun22_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric vector of length 2 or an |
par |
Numeric vector of length 10; see |
log |
If |
deriv |
Integer derivative order: |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for orthant CDFs. |
n_threads |
Number of OpenMP threads for parallel shard evaluation. |
weights |
Optional numeric vector of length |
Create a reusable SUN(2,2) hyperspherical likelihood tape
dsun22_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun22_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric vector of length 2 or an |
par_seed |
Seed vector for |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for orthant CDFs. |
n_threads |
Default OpenMP threads for |
weights |
Optional numeric vector of length |
SUN(3,2) density with joint hyperspherical parameterization
dsun32_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun32_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric matrix with 3 columns (observations in rows). |
par |
Numeric vector of length 16; see |
log |
Logical; return log-density / log-likelihood if |
deriv |
Integer 0, 1, or 2 for value / gradient / Hessian. |
n_points, n_shifts
|
Orthant QMC settings. |
seed |
QMC seed. |
n_threads |
OpenMP threads. |
weights |
Optional observation weights (length |
Create a reusable SUN(3,2) hyperspherical likelihood tape
dsun32_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun32_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric matrix with 3 columns. |
par_seed |
Seed vector for |
n_points, n_shifts
|
Orthant QMC settings. |
seed |
QMC seed. |
n_threads |
OpenMP threads (default from package helper). |
weights |
Optional observation weights. |
SUN(4,2) density with joint hyperspherical parameterization
dsun42_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun42_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric matrix with 4 columns (observations in rows). |
par |
Numeric vector of length 23; see |
log |
Logical; return log-density / log-likelihood if |
deriv |
Integer 0, 1, or 2 for value / gradient / Hessian. |
n_points, n_shifts
|
Orthant QMC settings. |
seed |
QMC seed. |
n_threads |
OpenMP threads. |
weights |
Optional observation weights (length |
Create a reusable SUN(4,2) hyperspherical likelihood tape
dsun42_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun42_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric matrix with 4 columns. |
par_seed |
Seed vector for |
n_points, n_shifts
|
Orthant QMC settings. |
seed |
QMC seed. |
n_threads |
OpenMP threads (default from package helper). |
weights |
Optional observation weights. |
SUN(4,3) density with joint hyperspherical parameterization
dsun43_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun43_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric matrix with 4 columns (observations in rows). |
par |
Numeric vector of length 29; see |
log |
Logical; return log-density / log-likelihood if |
deriv |
Integer 0, 1, or 2 for value / gradient / Hessian. |
n_points, n_shifts
|
Orthant QMC settings. |
seed |
QMC seed. |
n_threads |
OpenMP threads. |
weights |
Optional observation weights (length |
Create a reusable SUN(4,3) hyperspherical likelihood tape
dsun43_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun43_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric matrix with 4 columns. |
par_seed |
Seed vector for |
n_points, n_shifts
|
Orthant QMC settings. |
seed |
QMC seed. |
n_threads |
OpenMP threads (default from package helper). |
weights |
Optional observation weights. |
Evaluates the log-density (or density) of a SUN(4,4) distribution using the
block-Cholesky parameterization from make_sun44_params(). For a matrix
of observations the returned value is the summed log-likelihood, or a
weighted sum if weights is supplied. Derivatives are with respect to
the 36-component parameter vector only.
dsun44( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun44( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric vector of length 4 or an |
par |
Numeric vector of length 36; see |
log |
If |
deriv |
Integer derivative order: |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for orthant CDFs. |
n_threads |
Number of OpenMP threads for parallel shard evaluation. |
weights |
Optional numeric vector of length |
Orthant probabilities use Genz QMC with CppAD (dimension 4), so prefer a
modest n_points/n_shifts budget for speed.
A list with value and error. If deriv >= 1,
also gradient (length 36). If deriv >= 2, also
hessian ().
make_sun44_params(), dsun44_fun(), dsun()
Builds per-observation CppAD shard tapes for the (weighted) SUN(4,4)
log-likelihood with data x fixed. Use for KL / MLE: build once, then
call $eval(par) or $optim_fns().
dsun44_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun44_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric vector of length 4 or an |
par_seed |
Seed parameter vector used when building the tape. |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for orthant CDFs. |
n_threads |
Default OpenMP threads for |
weights |
Optional numeric vector of length |
An object of class "admvn_sun44_tape" with
eval() and optim_fns() (cached fn/gr).
SUN(4,4) density with joint hyperspherical parameterization
dsun44_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun44_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric vector of length 4 or an |
par |
Numeric vector of length 36; see |
log |
If |
deriv |
Integer derivative order: |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for orthant CDFs. |
n_threads |
Number of OpenMP threads for parallel shard evaluation. |
weights |
Optional numeric vector of length |
Create a reusable SUN(4,4) hyperspherical likelihood tape
dsun44_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun44_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric vector of length 4 or an |
par_seed |
Seed vector for |
n_points, n_shifts, seed
|
Quasi-Monte Carlo settings for orthant CDFs. |
n_threads |
Default OpenMP threads for |
weights |
Optional numeric vector of length |
SUN(5,2) density with joint hyperspherical parameterization
dsun52_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )dsun52_hs( x, par, log = TRUE, deriv = 0L, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = 1L, weights = NULL )
x |
Numeric matrix with 5 columns (observations in rows). |
par |
Numeric vector of length 31; see |
log |
Logical; return log-density / log-likelihood if |
deriv |
Integer 0, 1, or 2 for value / gradient / Hessian. |
n_points, n_shifts
|
Orthant QMC settings. |
seed |
QMC seed. |
n_threads |
OpenMP threads. |
weights |
Optional observation weights (length |
Create a reusable SUN(5,2) hyperspherical likelihood tape
dsun52_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )dsun52_hs_fun( x, par_seed, n_points = 1021L, n_shifts = 8L, seed = 1L, n_threads = NULL, weights = NULL )
x |
Numeric matrix with 5 columns. |
par_seed |
Seed vector for |
n_points, n_shifts
|
Orthant QMC settings. |
seed |
QMC seed. |
n_threads |
OpenMP threads (default from package helper). |
weights |
Optional observation weights. |
Uses dsun22_fun() (not sn) so the score matches the AD optim objective.
evaluate_sun22_slice(par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L)evaluate_sun22_slice(par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L)
par |
Length-10 SUN(2,2) parameter vector. |
quad |
List with |
n_points, n_shifts
|
Orthant QMC settings (defaults |
n_threads |
OpenMP threads for the density tape. |
Named vector c(kl, neg_Elq). kl is NA if
logp is missing.
Slice KL / cross-entropy of a SUN(3,2) hyperspherical fit
evaluate_sun32_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )evaluate_sun32_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )
par |
Length-21 hyperspherical parameter vector
(see |
quad |
List with |
n_points, n_shifts
|
Orthant QMC settings (defaults |
n_threads |
OpenMP threads for the density tape. |
Like evaluate_sun33_slice(), but uses dsun_hs_fun() and
make_sun_hs_params().
evaluate_sun33_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )evaluate_sun33_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )
par |
Length-21 hyperspherical parameter vector
(see |
quad |
List with |
n_points, n_shifts
|
Orthant QMC settings (defaults |
n_threads |
OpenMP threads for the density tape. |
Uses dsun_fun() (not sn) so the score matches the AD optim objective.
evaluate_sun33_slice(par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L)evaluate_sun33_slice(par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L)
par |
Length-21 SUN(3,3) parameter vector. |
quad |
List with |
n_points, n_shifts
|
Orthant QMC settings (defaults |
n_threads |
OpenMP threads for the density tape. |
Named vector c(kl, neg_Elq). kl is NA if
logp is missing.
Slice KL / cross-entropy of a SUN(4,2) hyperspherical fit
evaluate_sun42_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )evaluate_sun42_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )
par |
Length-21 hyperspherical parameter vector
(see |
quad |
List with |
n_points, n_shifts
|
Orthant QMC settings (defaults |
n_threads |
OpenMP threads for the density tape. |
Slice KL / cross-entropy of a SUN(4,3) hyperspherical fit
evaluate_sun43_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )evaluate_sun43_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )
par |
Length-21 hyperspherical parameter vector
(see |
quad |
List with |
n_points, n_shifts
|
Orthant QMC settings (defaults |
n_threads |
OpenMP threads for the density tape. |
Uses dsun44_fun() (not sn).
evaluate_sun44_slice(par, quad, n_points = 256L, n_shifts = 4L, n_threads = 1L)evaluate_sun44_slice(par, quad, n_points = 256L, n_shifts = 4L, n_threads = 1L)
par |
Length-36 SUN(4,4) parameter vector. |
quad |
List with |
n_points, n_shifts
|
Defaults |
n_threads |
OpenMP threads for the density tape. |
Slice KL / cross-entropy of a SUN(5,2) hyperspherical fit
evaluate_sun52_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )evaluate_sun52_hs_slice( par, quad, n_points = 64L, n_shifts = 2L, n_threads = 1L )
par |
Length-21 hyperspherical parameter vector
(see |
quad |
List with |
n_points, n_shifts
|
Orthant QMC settings (defaults |
n_threads |
OpenMP threads for the density tape. |
Minimises the weighted cross-entropy with
analytic gradients from dsun22_fun().
fit_sun22_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )fit_sun22_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )
quad |
List with |
start |
Length-10 start (see |
lower, upper
|
Box constraints (defaults from |
obj_scale |
Scale applied to the optim objective (default |
mc.cores |
OpenMP threads for the density tape. |
verbose |
If |
mvquad_opts |
Named list; used keys |
optim_opts |
Named list merged into |
A list with fit, par, dp, start,
gradient (objective-scale at par), KL / cross-entropy
summaries, and engine.
Fit SUN(3,2) hyperspherical by minimising KL on a weighted quadrature
fit_sun32_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )fit_sun32_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )
quad |
List with |
start |
Length-16 hyperspherical start
(see |
lower, upper
|
Box constraints (defaults from |
obj_scale |
Scale applied to the optim objective (default |
mc.cores |
OpenMP threads for the density tape. |
verbose |
If |
mvquad_opts |
Named list; used keys |
optim_opts |
Named list merged into |
Like fit_sun33_quad(), but uses dsun_hs_fun() and defaults from
sun33_hs_bounds() / make_sun33_hs_start_from_normal().
fit_sun33_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )fit_sun33_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )
quad |
List with |
start |
Length-21 hyperspherical start
(see |
lower, upper
|
Box constraints (defaults from |
obj_scale |
Scale applied to the optim objective (default |
mc.cores |
OpenMP threads for the density tape. |
verbose |
If |
mvquad_opts |
Named list; used keys |
optim_opts |
Named list merged into |
Minimises the weighted cross-entropy with
analytic gradients from dsun_fun().
fit_sun33_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )fit_sun33_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )
quad |
List with |
start |
Length-21 start (see |
lower, upper
|
Box constraints (defaults from |
obj_scale |
Scale applied to the optim objective (default |
mc.cores |
OpenMP threads for the density tape. |
verbose |
If |
mvquad_opts |
Named list; used keys |
optim_opts |
Named list merged into |
A list with fit, par, dp, start,
gradient (objective-scale at par), KL / cross-entropy
summaries, and engine.
Fit SUN(4,2) hyperspherical by minimising KL on a weighted quadrature
fit_sun42_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )fit_sun42_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )
quad |
List with |
start |
Length-23 hyperspherical start
(see |
lower, upper
|
Box constraints (defaults from |
obj_scale |
Scale applied to the optim objective (default |
mc.cores |
OpenMP threads for the density tape. |
verbose |
If |
mvquad_opts |
Named list; used keys |
optim_opts |
Named list merged into |
Fit SUN(4,3) hyperspherical by minimising KL on a weighted quadrature
fit_sun43_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )fit_sun43_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )
quad |
List with |
start |
Length-29 hyperspherical start
(see |
lower, upper
|
Box constraints (defaults from |
obj_scale |
Scale applied to the optim objective (default |
mc.cores |
OpenMP threads for the density tape. |
verbose |
If |
mvquad_opts |
Named list; used keys |
optim_opts |
Named list merged into |
Like fit_sun33_quad() for SUN(4,4) via dsun44_fun(). Default QMC
budget is n_points = 256, n_shifts = 4.
fit_sun44_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )fit_sun44_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )
quad |
List with |
start |
Length-36 start (see |
lower, upper
|
Box constraints (defaults from |
obj_scale |
Scale applied to the optim objective (default |
mc.cores |
OpenMP threads for the density tape. |
verbose |
If |
mvquad_opts |
Named list; used keys |
optim_opts |
Named list merged into |
Fit SUN(5,2) hyperspherical by minimising KL on a weighted quadrature
fit_sun52_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )fit_sun52_hs_quad( quad, start, lower = NULL, upper = NULL, obj_scale = 10000, mc.cores = 1L, verbose = FALSE, mvquad_opts = list(), optim_opts = list() )
quad |
List with |
start |
Length-31 hyperspherical start
(see |
lower, upper
|
Box constraints (defaults from |
obj_scale |
Scale applied to the optim objective (default |
mc.cores |
OpenMP threads for the density tape. |
verbose |
If |
mvquad_opts |
Named list; used keys |
optim_opts |
Named list merged into |
Product Gauss-Hermite quadrature for , returned as
abscissae in the original scale and corresponding product weights.
gh_points(mu, Sigma, n = 15)gh_points(mu, Sigma, n = 15)
mu |
Mean vector. |
Sigma |
Covariance matrix (made symmetric; Cholesky used for the map). |
n |
Number of univariate GH nodes per dimension (default 15). |
A list with x ( matrix) and w
(length weights).
Alternative to make_sun_params(): the latent joint correlation of
is
with unit-row Cholesky factor from fifteen
unconstrained coordinates via .
Then , , , and
with .
make_sun_hs_params(par)make_sun_hs_params(par)
par |
Numeric vector of length 21:
|
The leading six parameters match the block-Cholesky layout
(xi, nu), so the C++ sun_mle() driver works
unchanged on hyperspherical tapes.
Independent skew-normals. Only the pair slots
nonzero (equal to )
yields with
. All recovers a Gaussian.
Fill order. For dimension , free entries are filled by rows
, columns .
A list with components xi, Omega, Delta,
tau (fixed at zero), and Gamma.
make_sun_params(), dsun_hs(), sun33_hs_bounds()
par <- c( xi1 = 0, xi2 = 0, xi3 = 0, nu1 = 1, nu2 = 1, nu3 = 1, z21 = 0, z31 = 0, z32 = 0, z41 = atanh(0.4), z42 = 0, z43 = 0, z51 = 0, z52 = atanh(0.3), z53 = 0, z54 = 0, z61 = 0, z62 = 0, z63 = atanh(0.2), z64 = 0, z65 = 0 ) dp <- make_sun_hs_params(par) diag(dp$Gamma)par <- c( xi1 = 0, xi2 = 0, xi3 = 0, nu1 = 1, nu2 = 1, nu3 = 1, z21 = 0, z31 = 0, z32 = 0, z41 = atanh(0.4), z42 = 0, z43 = 0, z51 = 0, z52 = atanh(0.3), z53 = 0, z54 = 0, z61 = 0, z62 = 0, z63 = atanh(0.2), z64 = 0, z65 = 0 ) dp <- make_sun_hs_params(par) diag(dp$Gamma)
Converts the SUN(3,3) block-Cholesky parameterization used in the
supervision notes into the dp list expected by the sn package
(xi, Omega, Delta, tau, Gamma).
make_sun_params(par)make_sun_params(par)
par |
Numeric vector of length 21:
|
Correlation-scale SUN, then scale. With correlation from the
unit-row Cholesky of and
marginal standard deviations , writing
,
Skew loadings multiply (not ):
Free build residual
correlation . With
,
so is a correlation matrix. Then
and
.
Skew loadings. All nine entries of are free:
A list with components xi, Omega, Delta,
tau (fixed at zero), and Gamma.
par <- c( xi1 = 0, xi2 = 0, xi3 = 0, nu1 = 1, nu2 = 1, nu3 = 1, omega12 = 0.2, omega13 = 0.1, omega23 = 0.2, L11 = 0.4, L12 = 0.1, L13 = 0.1, L21 = 0.1, L22 = 0.4, L23 = 0.1, L31 = 0, L32 = 0.1, L33 = 0.35, gamma12 = 0.3, gamma13 = 0.2, gamma23 = 0.3 ) make_sun_params(par)par <- c( xi1 = 0, xi2 = 0, xi3 = 0, nu1 = 1, nu2 = 1, nu3 = 1, omega12 = 0.2, omega13 = 0.1, omega23 = 0.2, L11 = 0.4, L12 = 0.1, L13 = 0.1, L21 = 0.1, L22 = 0.4, L23 = 0.1, L31 = 0, L32 = 0.1, L33 = 0.35, gamma12 = 0.3, gamma13 = 0.2, gamma23 = 0.3 ) make_sun_params(par)
The joint correlation of is formed from six unconstrained
unit-row Cholesky coordinates in row-major order.
make_sun22_hs_params(par)make_sun22_hs_params(par)
par |
Numeric vector of length 10: |
A SUN dp list with xi, Omega, Delta,
zero tau, and Gamma.
dsun22_hs(), make_sun22_params(), sun22_hs_bounds()
SUN(2,2) hyperspherical start from weighted sample moments
make_sun22_hs_start_from_gh(quad, skew_strength = 0.01)make_sun22_hs_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-10 parameter vector.
Map mean and covariance to a SUN(2,2) hyperspherical start
make_sun22_hs_start_from_normal(mu, Sigma, skew_strength = 0)make_sun22_hs_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-2 mean. |
Sigma |
|
skew_strength |
Diagonal loading for |
Named length-10 vector for make_sun22_hs_params().
Converts the SUN(2,2) block-Cholesky parameterization into the dp
list expected by the sn package
(xi, Omega, Delta, tau, Gamma).
make_sun22_params(par)make_sun22_params(par)
par |
Numeric vector of length 10:
|
As in make_sun_params(): with
,
, , and
with unit diagonal.
A list with components xi, Omega, Delta,
tau (fixed at zero), and Gamma.
make_sun_params(), dsun22(), dsun22_fun()
SUN(2,2) start from weighted sample moments on a quadrature
make_sun22_start_from_gh(quad, skew_strength = 0.01)make_sun22_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-10 parameter vector.
Uses marginal standard deviations and unconstrained correlation free
parameters for (nu, omega). Skew loadings and residual-correlation
free parameters are zero, or a tiny diagonal loading if
skew_strength > 0.
make_sun22_start_from_normal(mu, Sigma, skew_strength = 0)make_sun22_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-2 mean. |
Sigma |
|
skew_strength |
Diagonal loading for |
Named length-10 parameter vector for make_sun22_params().
The joint correlation of is formed from ten
unconstrained unit-row Cholesky coordinates in row-major order.
make_sun32_hs_params(par)make_sun32_hs_params(par)
par |
Numeric vector of length 16: |
A SUN dp list with xi, Omega (),
Delta (), zero tau (length 2), and
Gamma ().
dsun32_hs(), sun32_hs_bounds()
SUN(3,2) hyperspherical start from weighted sample moments
make_sun32_hs_start_from_gh(quad, skew_strength = 0.01)make_sun32_hs_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-16 parameter vector.
Exact Gaussian start on the joint hyperspherical layout of
make_sun32_hs_params(): the three -block free coordinates come from
inverting cov2cor(Sigma); all cross / coordinates are zero.
Optional skew_strength sets pair slots z41,z52 to
atanh(skew_strength).
make_sun32_hs_start_from_normal(mu, Sigma, skew_strength = 0)make_sun32_hs_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-3 mean. |
Sigma |
|
skew_strength |
Pair-slot |
Named length-16 parameter vector for make_sun32_hs_params().
SUN(3,3) hyperspherical start from weighted sample moments
make_sun33_hs_start_from_gh(quad, skew_strength = 0.01)make_sun33_hs_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-21 parameter vector.
Exact Gaussian start on the joint hyperspherical layout of
make_sun_hs_params(): the three -block free coordinates come from
inverting cov2cor(Sigma); all cross / coordinates are zero
(so ). Optional
skew_strength sets the independent-SN pair slots to
atanh(skew_strength).
make_sun33_hs_start_from_normal(mu, Sigma, skew_strength = 0)make_sun33_hs_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-3 mean. |
Sigma |
|
skew_strength |
Pair-slot |
Named length-21 parameter vector for make_sun_hs_params().
SUN(3,3) start from weighted sample moments on a quadrature
make_sun33_start_from_gh(quad, skew_strength = 0.01)make_sun33_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-21 parameter vector.
Uses marginal standard deviations and unconstrained correlation free
parameters for (nu, omega). Skew loadings and residual-correlation
free parameters are zero, or a tiny diagonal loading if
skew_strength > 0.
make_sun33_start_from_normal(mu, Sigma, skew_strength = 0)make_sun33_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-3 mean. |
Sigma |
|
skew_strength |
Diagonal loading for |
Named length-21 parameter vector for make_sun_params().
The joint correlation of is formed from 15
unconstrained unit-row Cholesky coordinates in row-major order.
make_sun42_hs_params(par)make_sun42_hs_params(par)
par |
Numeric vector of length 23: |
A SUN dp list with xi, Omega (),
Delta (), zero tau (length 2), and
Gamma ().
dsun42_hs(), sun42_hs_bounds()
SUN(4,2) hyperspherical start from weighted sample moments
make_sun42_hs_start_from_gh(quad, skew_strength = 0.01)make_sun42_hs_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-23 parameter vector.
Exact Gaussian start on the joint hyperspherical layout of
make_sun42_hs_params(): the six -block free coordinates come from
inverting cov2cor(Sigma); all cross / coordinates are zero.
Optional skew_strength sets pair slots z51,z62 to
atanh(skew_strength).
make_sun42_hs_start_from_normal(mu, Sigma, skew_strength = 0)make_sun42_hs_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-4 mean. |
Sigma |
|
skew_strength |
Pair-slot |
Named length-23 parameter vector for make_sun42_hs_params().
The joint correlation of is formed from 21
unconstrained unit-row Cholesky coordinates in row-major order.
make_sun43_hs_params(par)make_sun43_hs_params(par)
par |
Numeric vector of length 29: |
A SUN dp list with xi, Omega (),
Delta (), zero tau (length 3), and
Gamma ().
dsun43_hs(), sun43_hs_bounds()
SUN(4,3) hyperspherical start from weighted sample moments
make_sun43_hs_start_from_gh(quad, skew_strength = 0.01)make_sun43_hs_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-29 parameter vector.
Exact Gaussian start on the joint hyperspherical layout of
make_sun43_hs_params(): the six -block free coordinates come from
inverting cov2cor(Sigma); all cross / coordinates are zero.
Optional skew_strength sets pair slots z51,z62,z73 to
atanh(skew_strength).
make_sun43_hs_start_from_normal(mu, Sigma, skew_strength = 0)make_sun43_hs_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-4 mean. |
Sigma |
|
skew_strength |
Pair-slot |
Named length-29 parameter vector for make_sun43_hs_params().
The joint correlation of is formed from 28 unconstrained
unit-row Cholesky coordinates in row-major order.
make_sun44_hs_params(par)make_sun44_hs_params(par)
par |
Numeric vector of length 36: |
A SUN dp list with xi, Omega, Delta,
zero tau, and Gamma.
dsun44_hs(), make_sun44_params(), sun44_hs_bounds()
SUN(4,4) hyperspherical start from weighted sample moments
make_sun44_hs_start_from_gh(quad, skew_strength = 0.01)make_sun44_hs_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-36 parameter vector.
Map mean and covariance to a SUN(4,4) hyperspherical start
make_sun44_hs_start_from_normal(mu, Sigma, skew_strength = 0)make_sun44_hs_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-4 mean. |
Sigma |
|
skew_strength |
Diagonal loading for |
Named length-36 vector for make_sun44_hs_params().
Converts the SUN(4,4) block-Cholesky parameterization into the dp
list expected by the sn package
(xi, Omega, Delta, tau, Gamma).
make_sun44_params(par)make_sun44_params(par)
par |
Numeric vector of length 36:
|
As in make_sun_params(): with
,
, , and
with unit diagonal.
A list with components xi, Omega, Delta,
tau (fixed at zero), and Gamma.
make_sun_params(), dsun44(), dsun44_fun()
SUN(4,4) start from weighted sample moments on a quadrature
make_sun44_start_from_gh(quad, skew_strength = 0.01)make_sun44_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-36 parameter vector.
Map mean and covariance to a SUN(4,4) start (zero / tiny skewness)
make_sun44_start_from_normal(mu, Sigma, skew_strength = 0)make_sun44_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-4 mean. |
Sigma |
|
skew_strength |
Diagonal loading for |
Named length-36 parameter vector for make_sun44_params().
The joint correlation of is formed from 21
unconstrained unit-row Cholesky coordinates in row-major order.
make_sun52_hs_params(par)make_sun52_hs_params(par)
par |
Numeric vector of length 31: |
A SUN dp list with xi, Omega (),
Delta (), zero tau (length 2), and
Gamma ().
dsun52_hs(), sun52_hs_bounds()
SUN(5,2) hyperspherical start from weighted sample moments
make_sun52_hs_start_from_gh(quad, skew_strength = 0.01)make_sun52_hs_start_from_gh(quad, skew_strength = 0.01)
quad |
List with |
skew_strength |
Passed to |
Named length-31 parameter vector.
Exact Gaussian start on the joint hyperspherical layout of
make_sun52_hs_params(): the ten -block free coordinates come from
inverting cov2cor(Sigma); all cross / coordinates are zero.
Optional skew_strength sets pair slots z61,z72 to
atanh(skew_strength).
make_sun52_hs_start_from_normal(mu, Sigma, skew_strength = 0)make_sun52_hs_start_from_normal(mu, Sigma, skew_strength = 0)
mu |
Length-5 mean. |
Sigma |
|
skew_strength |
Pair-slot |
Named length-31 parameter vector for make_sun52_hs_params().
Converts a covariance matrix into the Genz reordered correlation Cholesky
factor and marginal scales used by the CppAD tape. The permutation perm
must match the frozen order from pmvn_fun().
pack_genz_ch(sigma, perm)pack_genz_ch(sigma, perm)
sigma |
Positive-definite covariance matrix. |
perm |
Integer permutation vector from a tape object. |
A list with components scale and ch.
Evaluates for
using Genz's quasi-Monte Carlo
algorithm. Returns the probability, a Monte Carlo error estimate, and
derivatives of the approximation with respect to upper.
pmvn( upper, lower = -Inf, mean = 0, sigma, n_points = 1021L, n_shifts = 8L, seed = 1L )pmvn( upper, lower = -Inf, mean = 0, sigma, n_points = 1021L, n_shifts = 8L, seed = 1L )
upper |
Numeric vector of upper integration limits. |
lower |
Numeric vector of lower integration limits. Defaults to
|
mean |
Numeric mean vector. Defaults to zero. |
sigma |
Positive-definite covariance matrix. |
n_points |
Number of quasi-Monte Carlo points per random shift. |
n_shifts |
Number of random shifts for the QMC rule. |
seed |
Random seed for generating QMC shifts. |
A list with components value, error, gradient,
and hessian. The gradient and Hessian are with respect to
upper.
sigma <- matrix(c(1, 0.5, 0.5, 1), 2, 2) pmvn(c(1, 1), lower = c(-Inf, -Inf), sigma = sigma)sigma <- matrix(c(1, 0.5, 0.5, 1), 2, 2) pmvn(c(1, 1), lower = c(-Inf, -Inf), sigma = sigma)
Builds a CppAD tape for the multivariate normal CDF over upper,
mean, marginal scales, and the Genz Cholesky factor. The tape is built
once; subsequent evaluations pass new parameter values without re-taping.
Derivatives with respect to upper use sparse inner patterns (as in
adlaplace).
pmvn_fun( lower = -Inf, mean = 0, sigma, n_points = 1021L, n_shifts = 8L, seed = 1L )pmvn_fun( lower = -Inf, mean = 0, sigma, n_points = 1021L, n_shifts = 8L, seed = 1L )
lower, mean, sigma
|
Seed integration parameters used to fix the Genz
permutation and build the tape (see |
n_points, n_shifts, seed
|
QMC settings passed to |
eval(upper, mean = NULL, sigma = NULL, inner = TRUE) evaluates the
taped function. When mean or sigma are omitted, build-time
values are used. inner = TRUE (default) returns the gradient and
Hessian with respect to upper only; inner = FALSE also returns
gradient_mean and includes mean, scale, and Cholesky blocks in the
sparse derivatives.
An object of class "admvn_tape" with components perm
(frozen Genz permutation) and eval().
sigma <- matrix(c(1, 0.3, 0.3, 1), 2, 2) f <- pmvn_fun(lower = c(-Inf, -Inf), mean = c(0, 0), sigma = sigma) f$eval(c(0.5, 0.5))sigma <- matrix(c(1, 0.3, 0.3, 1), 2, 2) f <- pmvn_fun(lower = c(-Inf, -Inf), mean = c(0, 0), sigma = sigma) f$eval(c(0.5, 0.5))
Print SUN KL fit diagnostics (including gradient)
print_sun_kl_fit(fit, label = NULL)print_sun_kl_fit(fit, label = NULL)
fit |
Result from |
label |
Optional header string. |
fit, invisibly.
Maximizes the taped SUN log-likelihood using the quasi-Newton trust-region
solver from trustOptim (SR1 by default). The nu components are
optimized on the log scale so that they remain positive. The entire
optimization runs in C++ with one OpenMP-parallel value+gradient evaluation
per iteration.
sun_mle(tape, start, control = list(), n_threads = 0L)sun_mle(tape, start, control = list(), n_threads = 0L)
tape |
An object from |
start |
Numeric start vector of length 21 (natural parameterization). |
control |
List of trust-region controls (see trustOptim), e.g.
|
n_threads |
Threads for shard evaluation; |
A list with par, value (log-likelihood),
gradient, iterations, status, and related fields.
Diagonal loadings L11,L22 are in [-1, 1] (correlation
scale). Off-diagonal loadings L12,L21 are in [-0.5, 0.5],
matching sun33_bounds().
sun22_bounds()sun22_bounds()
List with lower and upper length-10 numeric vectors.
make_sun22_params(), fit_sun22_quad()
Independent-SN pair slots use atanh(+/-0.8) and all other joint
coordinates use atanh(+/-0.5).
sun22_hs_bounds()sun22_hs_bounds()
List of length-10 lower and upper vectors.
Pair slots linking to for
(z41, z52) use atanh(+/-0.8); other joint
coordinates use atanh(+/-0.5).
sun32_hs_bounds()sun32_hs_bounds()
List of length-16 lower and upper vectors.
Diagonal loadings L11,L22,L33 are in [-1, 1] (correlation
scale). Off-diagonal loadings Lij/Lji are in
[-0.5, 0.5].
sun33_bounds()sun33_bounds()
List with lower and upper length-21 numeric vectors.
make_sun_params(), fit_sun33_quad()
Soft boxes on the joint unit-row Cholesky coordinates of make_sun_hs_params():
independent-SN pair slots z41,z52,z63 lie in
atanh(+/-0.8); all other z* lie in atanh(+/-0.5).
These are regularization / start boxes, not a Gershgorin PD certificate.
sun33_hs_bounds()sun33_hs_bounds()
List with lower and upper length-21 numeric vectors.
make_sun_hs_params(), dsun_hs()
Pair slots linking to for
(z51, z62) use atanh(+/-0.8); other joint
coordinates use atanh(+/-0.5).
sun42_hs_bounds()sun42_hs_bounds()
List of length-23 lower and upper vectors.
Pair slots linking to for
(z51, z62, z73) use atanh(+/-0.8); other joint
coordinates use atanh(+/-0.5).
sun43_hs_bounds()sun43_hs_bounds()
List of length-29 lower and upper vectors.
Skew loadings Lij act on the correlation scale, so they are
restricted to [-1, 1].
sun44_bounds()sun44_bounds()
List with lower and upper length-36 numeric vectors.
make_sun44_params(), fit_sun44_quad()
Independent-SN pair slots use atanh(+/-0.8) and all other joint
coordinates use atanh(+/-0.5).
sun44_hs_bounds()sun44_hs_bounds()
List of length-36 lower and upper vectors.
Pair slots linking to for
(z61, z72) use atanh(+/-0.8); other joint
coordinates use atanh(+/-0.5).
sun52_hs_bounds()sun52_hs_bounds()
List of length-31 lower and upper vectors.
Weighted covariance
weighted_cov(X, w)weighted_cov(X, w)
X |
Numeric matrix of observations (rows). |
w |
Nonnegative weights (recycled / renormalized). |
Symmetric ncol(X) covariance matrix.
Weighted column means
weighted_mean(X, w)weighted_mean(X, w)
X |
Numeric matrix of observations (rows). |
w |
Nonnegative weights (recycled / renormalized). |
Named numeric vector of length ncol(X).