Parameter counts and AIC¶
mtdr.aic
¶
Parameter counts and the Akaike information criterion.
The two estimators count parameters differently because they estimate
different things (docs/model.md § 3.3, § 7.1):
- the SVD / reduced-rank estimator fits low-rank coefficient matrices \(B_p=W_pS_p^\top\), a precision per neuron and a full-rank intercept, and its likelihood is a plug-in profile likelihood at the truncated least-squares estimate, (M21);
- the marginal-likelihood estimator integrates the weights \(W\) out, so it counts the temporal bases \(S_p\) (modulo the orthogonal rotation the marginal likelihood is invariant to), the precisions and the intercept, (M38a).
The two likelihoods are different objects, so the AIC values of the two
estimators are never comparable. formula="reference" gives the counts the
MATLAB demo uses, for parity fixtures only.
n_parameters_svd(ranks, n_neurons, n_bins, *, condition_independent=True, formula='textbook')
¶
Count the parameters of the SVD / reduced-rank fit, (M21b) or (M20b).
"textbook" (the default, (M21b)) counts the dimension of the
set of rank-\(r_p\) matrices \(n\times T\) for every regressor, one noise
precision per neuron, and, with the intercept, a full-rank \(n\times T\)
term (rank \(m=\min(n,T)\), which counts \(m(n+T-m)=nT\)):
"reference" is the count in the MATLAB SVDRegB_AIC, (M20b),
\(K=(nP'+TP'-\sum r')\sum r'\), where, as in the demo, \(P'\) and \(r'\)
include the intercept as a last regressor of rank \(\min(n,T)\) when
condition_independent=True. It is not a parameter count (it
over-penalises by roughly a factor \(P\)); it exists for parity fixtures.
Only the count changes; the reference's other three defects live in the
test helpers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranks
|
sequence of int
|
Rank \(r_p\) of each regressor, |
required |
n_neurons
|
int
|
\(n\), positive. |
required |
n_bins
|
int
|
\(T\), positive. |
required |
condition_independent
|
bool
|
Count the full-rank intercept. |
True
|
formula
|
('textbook', 'reference')
|
Which count. |
"textbook"
|
Returns:
| Type | Description |
|---|---|
int
|
The count. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
For a rank outside |
Examples:
>>> from mtdr.aic import n_parameters_svd
>>> n_parameters_svd([2, 1], n_neurons=10, n_bins=5) # 2*13 + 1*14 + 10 + 50
100
>>> n_parameters_svd([2, 1], 10, 5, formula="reference") # (30 + 15 - 8) * 8
296
n_parameters_mmle(ranks, n_neurons, n_bins, *, condition_independent=True, formula='identifiable')
¶
Count the parameters of the marginal-likelihood fit, (M38a) or (M38).
"identifiable" (the default, (M38a)): one precision per neuron, the
bases \(S_p\) modulo the orthogonal rotation \(S_p\to S_pQ_p\) that leaves the
marginal likelihood unchanged (docs/model.md § 10.1), and the
\(n\times T\) intercept when present:
"reference" is the demo's count, the length of its parameter vector
\((\lambda;s;\mathrm{vec}\,b)\), (M38): \(n+T\sum_pr_p\,[+\,nT]\). The
integrated-out weights are not counted by either. Without the intercept
the reference count drops the \(nT\) entries of \(b\) as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranks
|
sequence of int
|
Rank \(r_p\) of each regressor, |
required |
n_neurons
|
int
|
\(n\), positive. |
required |
n_bins
|
int
|
\(T\), positive. |
required |
condition_independent
|
bool
|
Count the intercept. |
True
|
formula
|
('identifiable', 'reference')
|
Which count. |
"identifiable"
|
Returns:
| Type | Description |
|---|---|
int
|
The count. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
As |
Examples:
>>> from mtdr.aic import n_parameters_mmle
>>> n_parameters_mmle([3, 4, 2], n_neurons=100, n_bins=15) # 100 + 125 + 1500
1725
>>> n_parameters_mmle([3, 4, 2], 100, 15, formula="reference") # 100 + 135 + 1500
1735
aic(log_likelihood, n_parameters)
¶
Akaike information criterion \(2K-2\ell\) (lower is better).
(M21b), (M38). log_likelihood should be a fully normalised
log-likelihood; the result is comparable only between fits of the same
estimator to the same Y and mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_likelihood
|
float
|
\(\ell\), finite. |
required |
n_parameters
|
int
|
\(K\ge0\). |
required |
Returns:
| Type | Description |
|---|---|
float
|
\(2K-2\ell\). |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If |
Examples:
>>> from mtdr.aic import aic
>>> aic(-120.5, 10)
261.0