Parameters
- class openpkpd.model.parameters.ThetaSpec(init, lower=-inf, upper=inf, fixed=False, label=None)[source]
Bases:
objectSpecification for a single THETA parameter.
- class openpkpd.model.parameters.OmegaSpec(block_size, values, fixed=False, same=False, label=None)[source]
Bases:
objectSpecification for an OMEGA block.
- class openpkpd.model.parameters.SigmaSpec(block_size, values, fixed=False, label=None)[source]
Bases:
objectSpecification for a SIGMA block (residual error variance).
- class openpkpd.model.parameters.ParameterSet(theta, omega, sigma, theta_specs=<factory>, omega_specs=<factory>, sigma_specs=<factory>)[source]
Bases:
objectA concrete parameter point in (THETA, OMEGA, SIGMA) space.
THETA: 1-D array of population fixed effects. OMEGA: full n_eta × n_eta positive-definite matrix. SIGMA: full n_eps × n_eps positive-definite matrix.
- Parameters:
- to_vector()[source]
Pack free parameters into a 1-D vector for the optimizer.
- Return type:
- Convention:
Free THETA values (log-transformed if lower=0)
Free OMEGA lower-Cholesky elements (diagonal log-transformed)
Free SIGMA lower-Cholesky elements (diagonal log-transformed)
- classmethod from_vector(vec, template)[source]
Unpack optimizer vector back to structured ParameterSet.
- Return type:
- Parameters:
vec (ndarray)
template (ParameterSet)
- apply_bounds()[source]
Clamp THETA to bounds; ensure OMEGA/SIGMA are positive-definite.
- Return type:
- classmethod from_specs(theta_specs, omega_specs, sigma_specs)[source]
Build a ParameterSet from specs using initial values.
- n_iov_occasions()[source]
Number of occasions for IOV (count OMEGA SAME specs).
An
OmegaSpecwithsame=Truemeans this OMEGA block is a copy of the preceding block (NONMEMOMEGA SAMEsyntax). Each such repetition represents an additional occasion.- Return type:
- Returns:
Number of occasions. Returns 1 when no IOV is present (every individual has exactly one occasion).
- has_iov()[source]
Return True if any OMEGA spec has
same=True.An
OmegaSpecwithsame=Truesignals that this block is an IOV (Inter-Occasion Variability) repetition of the preceding block.- Return type:
- expand_omega_iov(n_occasions)[source]
Expand OMEGA to handle IOV by creating per-occasion ETA blocks.
For each
OmegaSpecthat is not markedsame=True, the block is repeatedn_occasionstimes to form a block-diagonal OMEGA. The resulting OMEGA hasn_eta_base * n_occasionsrandom effects.This mirrors the NONMEM pattern:
$OMEGA BLOCK(1) 0.04 $OMEGA BLOCK(1) SAME ; occasion 2 $OMEGA BLOCK(1) SAME ; occasion 3
which openpkpd stores as one BLOCK + two SAME entries.
- Parameters:
n_occasions (
int) – Number of occasions to expand to. Must be >= 1.- Return type:
- Returns:
A new ParameterSet with expanded OMEGA (block-diagonal over occasions) and OMEGA specs updated accordingly. THETA and SIGMA are copied unchanged.
- Raises:
ValueError – If
n_occasions < 1.
- get_optimizer_bounds()[source]
Return L-BFGS-B bounds for every element of
to_vector().Free THETA: (None, None) — the logit/log transform already enforces spec.lower/upper in
from_vector/apply_bounds.OMEGA/SIGMA log-Cholesky diagonal: (None, _MAX_COVA_LOG_DIAG_BOUND) so omega_ii ≤ _MAX_OMEGA_DIAG. Prevents the outer loop from driving IIV to infinity (a degenerate but numerically cheap solution). No lower bound is set: if the optimizer drives omega toward zero, the
objective()closure detects the resulting 1e10 penalty and retries with a cold η-hat reset (see foce.py) to recover clean OFV.OMEGA/SIGMA off-diagonal Cholesky elements: (None, None).