Distributions
This page documents the distributions module.
ordboost.distributions
Predictive probability distributions for discrete ordinal outcomes.
ContinuousPredictiveDistribution
Bases: PredictiveDistribution
Encapsulates a continuous predictive Cumulative Distribution Function (CDF).
Provides vectorized utilities for computing expected continuous values, medians, percent point functions (quantiles/PPF), central prediction intervals, and continuous CDF probabilities across samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_y
|
ndarray
|
1D float array of shape (n_grid_points,) representing continuous physical target grid values in strictly ascending order. |
required |
grid_cdf
|
ndarray
|
2D float array of shape (n_samples, n_grid_points) containing
evaluated cumulative probabilities across grid points. Every
row's first value must be 0.0 and last value must be 1.0 (within
tolerance) for |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
grid_y |
ndarray
|
1D float array containing grid values as a read-only object. |
grid_cdf |
ndarray
|
2D float array containing cumulative probabilities, clipped to [0.0, 1.0] as a read-only object. |
Methods:
| Name | Description |
|---|---|
mean |
Calculate expected continuous values via numerical integration. |
ppf |
Calculate percent point function (inverse CDF / quantiles). |
median |
Calculate the 50th percentile prediction for each sample. |
interval |
Calculate central prediction bounds for a given significance level. |
cdf |
Evaluate continuous CDF probability P(Y <= y) at physical value y. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/distributions.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
cdf(y)
Evaluate the continuous CDF, P(Y <= y), at physical value(s) y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
float | ArrayLike
|
Physical target value(s) at which to evaluate the CDF. A
scalar is broadcast across all samples; a 1D array of length
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of shape (n_samples,) containing P(Y <= y) for each
sample, linearly interpolated (or exactly looked up) against
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/distributions.py
mean()
Calculate expected continuous values via numerical integration.
Uses the identity E[Y] = grid_y[0] + integral_{grid_y[0]}^{grid_y[-1]}
(1 - F(y)) dy, evaluated by the trapezoidal rule. Correctness
relies on grid_cdf starting at 0.0 and ending at 1.0, which is
enforced at construction time.
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of shape (n_samples,) containing expected physical values. |
Source code in ordboost/distributions.py
DiscretePredictiveDistribution
Bases: PredictiveDistribution
Encapsulates a discrete Probability Mass Function (PMF) matrix.
Provides vectorized utilities for computing cumulative distribution functions (CDF), percent point functions (quantiles/PPF), expected values, medians, and prediction intervals across samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pmf
|
ndarray
|
A 2D float array of shape (n_samples, n_classes) representing the predicted probability for each discrete target class. Values along each row must sum to 1.0 (within floating-point tolerance). |
required |
classes
|
ndarray
|
A 1D array of shape (n_classes,) representing the physical ordinal class labels in strictly ascending order. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
pmf |
ndarray
|
A 2D float array of shape (n_samples, n_classes) containing validated predicted class probabilities as a read-only object. |
classes |
ndarray
|
A 1D array of shape (n_classes,) containing the validated ordinal class labels as a read-only object. |
cdf |
ndarray
|
A 2D float array of shape (n_samples, n_classes) containing
cumulative probabilities computed from |
Methods:
| Name | Description |
|---|---|
mean |
Calculate the expected value for each sample. |
ppf |
Calculate the percent point function (inverse CDF / quantiles). |
median |
Calculate the 50th percentile prediction for each sample. |
interval |
Calculate central prediction bounds for a given significance level. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/distributions.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
cdf
property
Compute the Cumulative Distribution Function (CDF) array.
Returns:
| Type | Description |
|---|---|
ndarray
|
2D array of shape (n_samples, n_classes) containing cumulative
probabilities. The final column is forced to exactly 1.0 to
guard against |
mean()
Calculate the expected value (mean) for each sample.
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of shape (n_samples,) representing expected values in physical class units. |
Source code in ordboost/distributions.py
PredictiveDistribution
Bases: ABC
Abstract base class for all predictive probability distributions.
Defines a unified interface for extracting point estimates, quantiles, prediction intervals, and cumulative probabilities regardless of whether the distribution is discrete or continuous.
Methods:
| Name | Description |
|---|---|
mean |
Calculate expected values across samples. |
median |
Calculate 50th percentile predictions across samples. |
ppf |
Calculate percent point function (inverse CDF / quantiles). |
interval |
Calculate central prediction bounds for a given significance level. |
Source code in ordboost/distributions.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
interval(alpha=0.1)
Calculate central prediction bounds for a given significance level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Significance level (e.g., alpha=0.10 yields a 90% central interval). |
0.10
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
Tuple of (lower_bounds, upper_bounds), each as a 1D array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/distributions.py
mean()
abstractmethod
Calculate the expected value for each sample.
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of shape (n_samples,) containing expected values in physical target units. |
Notes
Implementations must ensure the underlying distribution's total probability mass is fully accounted for (e.g. PMF rows summing to 1.0, or a CDF grid spanning exactly [0.0, 1.0]) for this to return an unbiased estimate. Concrete subclasses enforce this at construction time rather than here.
Source code in ordboost/distributions.py
median()
Calculate the 50th percentile (median) prediction for each sample.
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of shape (n_samples,) containing median predictions. |
ppf(q)
Percent Point Function (inverse CDF / quantile calculation).
Validates q once, then delegates to the subclass's _ppf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
float | ArrayLike
|
Quantile level(s). Can be a single scalar or a 1D array-like of quantiles, with all values in [0.0, 1.0]. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
If |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |