Purpose
This validation reconstructs the fitted parameters of
gipslda(), gipsqda(), and
gipsmultqda() independently. The reference calculation uses
only base R, stats, and the public gips API.
It does not call any gipsDA helper or internal
function.
The executable version is
tests/testthat/manual/test-manual-parameter-reconstruction.R.
The formulas and implementation notes are kept beside the calculations
in that test so that differences between the reference and package
implementations remain reviewable.
Mock data in
Three Gaussian classes are generated with sample sizes 9, 10, and 11. Their means are
Each class has a different positive-definite covariance matrix:
With a fixed seed, standard-normal matrices are transformed as
The unequal class sizes test the empirical priors and the sample-size vector used by the joint projection. Three dimensions keep brute-force permutation search small and deterministic.
Covariance projection
For every reference projection, the test constructs a
gips object directly:
search <- gips::gips(
empirical_covariances,
sample_sizes,
was_mean_estimated = TRUE
)
search <- gips::find_MAP(
search,
optimizer = "BF",
show_progress_bar = FALSE
)
permutation <- search[[1L]]
projected <- lapply(
empirical_covariances,
gips::project_matrix,
permutation
)When only one covariance matrix is projected, that matrix is passed
directly to gips::gips(). The brute-force optimizer
enumerates the permutations in
,
avoiding Monte Carlo variation.
The projected covariance is regularized only if its eigenvalue nearest zero satisfies . In that case,
This transformation is implemented explicitly in the test.
LDA reconstruction
Let denote the sample mean of class , and let be the within-class residuals. Define
For
observations and
classes, the covariance supplied to gips is calculated
manually as
After MAP projection and regularization, write . The whitening transform is
Using the empirical priors and , the between-class matrix is
If , the stored discriminant scaling is , truncated using the same numerical rank rule as the public model. The test independently compares:
- empirical priors, class counts, means, labels, and sample size;
- the MAP permutation;
- between-class singular values;
- the discriminant scaling after resolving arbitrary SVD column signs.
Separate QDA reconstruction
For each class, the sample covariance
is projected in a separate brute-force gips search. The
total sample size
is supplied to each search, matching the estimator’s statistical
parameterization. If
the reference parameters are
Because singular vectors can change sign without changing the model, the test compares , the precision matrix used by QDA, rather than the signs of individual columns.
Joint QDA reconstruction
The joint model starts from the same class covariances but passes
and the sample-size vector
to one gips search. Its single MAP permutation is then used
to project every covariance. The scaling matrices and log determinants
are calculated from the resulting matrices using the QDA equations
above.
This distinguishes gipsmultqda() from
gipsqda(): the former estimates one shared symmetry, while
the latter estimates each class symmetry independently.
Assertions
The three public fitting functions are called only after all reference parameters have been computed. Numerical quantities are compared with tolerance . Discrete quantities, dimensions, labels, sample size, and MAP permutations are compared exactly. The QDA scaling checks use precision matrices, and the LDA scaling check aligns SVD signs before applying the tolerance.
The test therefore validates the complete set of fitted numerical parameters, apart from the recorded call, against a calculation that is independent of the package implementation.