Stats¤
The zodiax.stats module provides statistical helpers for z-scores, log-likelihoods,
chi-squared values, degrees of freedom, and covariance-derived quantities.
zodiax.stats
¤
calc_entropy(cov)
¤
Calculates the entropy of a covariance matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cov
|
Array
|
The covariance matrix to calculate the entropy of. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
entropy |
Array
|
The entropy of the covariance matrix. |
Source code in zodiax/stats.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
check_positive_semi_definite(mat)
¤
Checks if a matrix is positive semi-definite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mat
|
Array
|
The matrix to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
is_positive_semi_definite |
bool
|
|
Source code in zodiax/stats.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
check_symmetric(mat)
¤
Checks if a matrix is symmetric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mat
|
Array
|
The matrix to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
is_symmetric |
bool
|
|
Source code in zodiax/stats.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
chi2(x, mean, std)
¤
Calculates the chi-squared statistic from values, means, and standard deviations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
The observed values. |
required |
mean
|
Array
|
The expected mean values. |
required |
std
|
Array
|
The standard deviations of the observations. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
chi2 |
Array
|
The chi-squared statistic. |
Source code in zodiax/stats.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
chi2r(x, mean, std, ddof)
¤
Calculates the reduced chi-squared statistic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
The observed values. |
required |
mean
|
Array
|
The expected mean values. |
required |
std
|
Array
|
The standard deviations of the observations. |
required |
ddof
|
int
|
The degrees of freedom used to normalise the chi-squared value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
chi2r |
Array
|
The reduced chi-squared statistic. |
Source code in zodiax/stats.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
chi2r_from_z(z_score, ddof)
¤
Calculates the reduced chi-squared statistic directly from z-scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z_score
|
Array
|
The z-score values. |
required |
ddof
|
int
|
The degrees of freedom used to normalise the chi-squared value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
chi2r |
Array
|
The reduced chi-squared statistic. |
Source code in zodiax/stats.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
ddof(params, data)
¤
Calculates the degrees of freedom as the difference between flattened data size and flattened parameter size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Array
|
The model parameters, provided as a pytree. |
required |
data
|
Array
|
The observed data, provided as a pytree. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ddof |
int
|
The number of degrees of freedom, computed as
|
Source code in zodiax/stats.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
gauss_hessian(J, cov=None)
¤
Calculates the Gauss-Newton Hessian approximation under a Gaussian likelihood model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
J
|
Array
|
The Jacobian matrix. |
required |
cov
|
Array
|
The covariance matrix used to weight the Jacobian. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
hessian |
Array
|
The Gauss-Newton Hessian approximation, either |
Source code in zodiax/stats.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
loglike(x, mean, std)
¤
Calculates the element-wise log-likelihood under a univariate normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
The observed values. |
required |
mean
|
Array
|
The mean of the normal distribution. |
required |
std
|
Array
|
The standard deviation of the normal distribution. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loglike |
Array
|
The element-wise log-likelihood values. |
Source code in zodiax/stats.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
mv_loglike(x, mean, cov)
¤
Calculates the log-likelihood under a multivariate normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
The observed vector. |
required |
mean
|
Array
|
The mean vector of the multivariate normal distribution. |
required |
cov
|
Array
|
The covariance matrix of the multivariate normal distribution. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mv_loglike |
Array
|
The multivariate normal log-likelihood value. |
Source code in zodiax/stats.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
mv_z_score(x, mean, cov)
¤
Calculates the squared Mahalanobis distance \((\mu - x)^ op\Sigma^{-1}(\mu - x)\) of a value given a mean and covariance matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
The value to calculate the multivariate z-score of. |
required |
mean
|
Array
|
The mean vector to use in the calculation. |
required |
cov
|
Array
|
The covariance matrix to use in the calculation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mv_z_score |
Array
|
The squared Mahalanobis distance of the value. |
Source code in zodiax/stats.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
z_score(x, mean, std)
¤
Calculates the z-score \((\mu - x) / \sigma\) of a value given a mean and standard deviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
The value to calculate the z-score of. |
required |
mean
|
Array
|
The mean to use in the z-score calculation. |
required |
std
|
Array
|
The standard deviation to use in the z-score calculation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
z_score |
Array
|
The z-score of the value. |
Source code in zodiax/stats.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |