studentt
studentt
¶
Student's T distribution with fixed degrees of freedom for ngboost-lightning.
Provides a t_fixed_df(df) factory that creates a StudentT distribution
class with the given degrees of freedom baked in. A convenience alias
StudentT3 = t_fixed_df(3) covers the most common use case.
Internal parameters are [loc, log_scale] with df fixed at class
creation time.
StudentT
¶
Bases: Distribution
Student's T distribution with fixed df and log-scale parameterization.
Internal parameters are [loc, log_scale] where
scale = exp(log_scale). The degrees of freedom df is a class
attribute set by the t_fixed_df factory.
Do not instantiate StudentT directly — use t_fixed_df(df)
to create a subclass with the desired df.
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_params |
Always 2 (loc and log_scale).
|
df |
Degrees of freedom (class attribute, set by factory).
TYPE:
|
loc |
Location values, shape
TYPE:
|
scale |
Scale values, shape
TYPE:
|
Construct StudentT from internal parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
Internal parameters, shape
TYPE:
|
Source code in ngboost_lightning/distributions/studentt.py
fit
classmethod
¶
Estimate initial (loc, log_scale) from target data.
Uses weighted mean for loc and a robust scale estimate from the weighted variance adjusted for the T distribution's heavier tails.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Target values, shape
TYPE:
|
sample_weight
|
Per-sample weights, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Parameter vector |
Source code in ngboost_lightning/distributions/studentt.py
score
¶
Per-sample negative log-likelihood.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
NLL values, shape |
Source code in ngboost_lightning/distributions/studentt.py
d_score
¶
Analytical gradient of NLL w.r.t. [loc, log_scale].
Derivation (let v=df, s=scale, z=(y-loc)/s): NLL = const + log(s) + (v+1)/2 * log(1 + z^2/v)
d(NLL)/d(loc) = (v+1) * (loc - y) / (v * s^2 + (y - loc)^2)
d(NLL)/d(log_scale) = 1 - (v+1) * z^2 / (v + z^2)
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/studentt.py
metric
¶
Fisher Information for (loc, log_scale) parameterization.
For T(v, loc, log_scale): FI[0,0] = (v+1) / ((v+3) * scale^2) FI[1,1] = 2*v / (v+3) FI is diagonal (cross-derivatives vanish by symmetry).
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
FI tensor, shape |
Source code in ngboost_lightning/distributions/studentt.py
natural_gradient
¶
Natural gradient via diagonal Fisher (fast path).
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Natural gradient, shape |
Source code in ngboost_lightning/distributions/studentt.py
mean
¶
Conditional mean (= loc for T distribution when df > 1).
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Mean values, shape |
sample
¶
Draw n samples per distribution instance.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of samples to draw.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Samples, shape |
Source code in ngboost_lightning/distributions/studentt.py
cdf
¶
Cumulative distribution function.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Values at which to evaluate the CDF.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
CDF values, same shape as |
Source code in ngboost_lightning/distributions/studentt.py
ppf
¶
Percent point function (inverse CDF / quantile function).
| PARAMETER | DESCRIPTION |
|---|---|
q
|
Quantiles, values in [0, 1].
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Values at the given quantiles, same shape as |
Source code in ngboost_lightning/distributions/studentt.py
logpdf
¶
Log probability density function.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Values at which to evaluate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Log-density values, same shape as |
Source code in ngboost_lightning/distributions/studentt.py
t_fixed_df
¶
t_fixed_df(df: float) -> type[StudentT]
Create a StudentT distribution class with fixed degrees of freedom.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Degrees of freedom (must be > 0).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[StudentT]
|
A |
Examples: