API Reference¶
src.distributions
¶
Distribution modules for probability distributions.
BayesianGMM
¶
Bayesian Gaussian Mixture Model with automatic component selection.
Source code in src/distributions/mixtures.py
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 | |
__init__(max_components=10, weight_concentration_prior=1.0, max_iter=200, tol=0.0001)
¶
Initialize Bayesian GMM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_components
|
int
|
Maximum number of components |
10
|
weight_concentration_prior
|
float
|
Dirichlet concentration prior |
1.0
|
max_iter
|
int
|
Maximum EM iterations |
200
|
tol
|
float
|
Convergence tolerance |
0.0001
|
Source code in src/distributions/mixtures.py
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 | |
fit(data)
¶
Fit Bayesian GMM to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Training data |
required |
Returns:
| Type | Description |
|---|---|
BayesianGMM
|
Self |
Source code in src/distributions/mixtures.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
get_active_components()
¶
Get number of active components (with non-negligible weight).
Returns:
| Type | Description |
|---|---|
int
|
Number of active components |
Source code in src/distributions/mixtures.py
441 442 443 444 445 446 447 448 449 450 451 452 | |
predict(data)
¶
Predict component labels.
Source code in src/distributions/mixtures.py
432 433 434 435 436 437 438 439 | |
BetaDistribution
¶
Bases: Distribution
Beta distribution.
Source code in src/distributions/continuous.py
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 170 | |
__init__(alpha=2.0, beta=2.0)
¶
Initialize Beta distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Shape parameter (must be > 0) |
2.0
|
beta
|
float
|
Shape parameter (must be > 0) |
2.0
|
Source code in src/distributions/continuous.py
134 135 136 137 138 139 140 141 142 143 144 145 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
165 166 167 168 169 170 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
151 152 153 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
155 156 157 158 159 160 161 162 163 | |
BinomialDistribution
¶
Bases: Distribution
Binomial distribution.
Source code in src/distributions/discrete.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 | |
__init__(n=10, p=0.5)
¶
Initialize Binomial distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of trials (must be positive integer) |
10
|
p
|
float
|
Probability of success (must be between 0 and 1) |
0.5
|
Source code in src/distributions/discrete.py
13 14 15 16 17 18 19 20 21 22 23 24 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
46 47 48 49 50 51 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
30 31 32 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
34 35 36 37 38 39 40 41 42 43 44 | |
CauchyDistribution
¶
Bases: Distribution
Cauchy distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(x0=0.0, gamma=1.0)
¶
Initialize Cauchy distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
float
|
Location parameter |
0.0
|
gamma
|
float
|
Scale parameter (must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
375 376 377 378 379 380 381 382 383 384 385 386 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
406 407 408 409 410 411 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
392 393 394 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
396 397 398 399 400 401 402 403 404 | |
ChiSquareDistribution
¶
Bases: Distribution
Chi-square distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(df=3)
¶
Initialize Chi-square distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
int
|
Degrees of freedom (must be > 0) |
3
|
Source code in src/distributions/continuous.py
218 219 220 221 222 223 224 225 226 227 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
246 247 248 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
233 234 235 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
237 238 239 240 241 242 243 244 | |
ClaytonCopula
¶
Bases: Copula
Clayton copula (Archimedean).
Source code in src/distributions/copulas.py
161 162 163 164 165 166 167 168 169 170 171 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 | |
__init__(theta, dimension=2)
¶
Initialize Clayton copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
Dependence parameter (theta >= -1/(d-1), theta != 0) |
required |
dimension
|
int
|
Number of dimensions |
2
|
Source code in src/distributions/copulas.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
cdf(u)
¶
Clayton copula CDF.
Source code in src/distributions/copulas.py
182 183 184 185 186 187 188 189 190 | |
kendall_tau()
¶
Calculate Kendall's tau.
Returns:
| Type | Description |
|---|---|
float
|
Kendall's tau |
Source code in src/distributions/copulas.py
232 233 234 235 236 237 238 239 | |
pdf(u)
¶
Clayton copula density (bivariate only).
Source code in src/distributions/copulas.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
rvs(size=1, random_state=None)
¶
Generate samples from Clayton copula (bivariate only).
Source code in src/distributions/copulas.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
Copula
¶
Base class for copulas.
Source code in src/distributions/copulas.py
8 9 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 | |
__init__(name, dimension=2)
¶
Initialize copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Copula name |
required |
dimension
|
int
|
Number of dimensions |
2
|
Source code in src/distributions/copulas.py
11 12 13 14 15 16 17 18 19 20 | |
cdf(u)
¶
Copula CDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Uniform(0,1) marginals (shape: n x d or d) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Copula CDF values |
Source code in src/distributions/copulas.py
22 23 24 25 26 27 28 29 30 31 32 | |
kendall_tau()
¶
Calculate Kendall's tau.
Source code in src/distributions/copulas.py
59 60 61 | |
pdf(u)
¶
Copula density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Uniform(0,1) marginals |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Copula density values |
Source code in src/distributions/copulas.py
34 35 36 37 38 39 40 41 42 43 44 | |
rvs(size=1, random_state=None)
¶
Generate random samples from copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
random_state
|
int | None
|
Random seed |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Uniform(0,1) samples (shape: size x d) |
Source code in src/distributions/copulas.py
46 47 48 49 50 51 52 53 54 55 56 57 | |
DirichletDistribution
¶
Bases: MultivariateDistribution
Dirichlet distribution.
Source code in src/distributions/multivariate.py
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 | |
__init__(alpha)
¶
Initialize Dirichlet distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
ndarray
|
Concentration parameters (must be positive) |
required |
Source code in src/distributions/multivariate.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
cov()
¶
Calculate covariance matrix.
Source code in src/distributions/multivariate.py
253 254 255 256 257 | |
entropy()
¶
Calculate differential entropy.
Source code in src/distributions/multivariate.py
271 272 273 274 275 | |
logpdf(x)
¶
Calculate log probability density function.
Source code in src/distributions/multivariate.py
223 224 225 226 227 | |
mean()
¶
Calculate mean vector.
Source code in src/distributions/multivariate.py
244 245 246 | |
mode()
¶
Calculate mode.
Returns:
| Type | Description |
|---|---|
ndarray
|
Mode vector (only valid if all alpha > 1) |
Source code in src/distributions/multivariate.py
259 260 261 262 263 264 265 266 267 268 269 | |
pdf(x)
¶
Calculate probability density function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Points on simplex (shape: n x d or d), must sum to 1 |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
PDF values |
Source code in src/distributions/multivariate.py
209 210 211 212 213 214 215 216 217 218 219 220 221 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
random_state
|
int | None
|
Random seed |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Samples on simplex (shape: size x d) |
Source code in src/distributions/multivariate.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
var()
¶
Calculate variance for each component.
Source code in src/distributions/multivariate.py
248 249 250 251 | |
DiscreteUniformDistribution
¶
Bases: Distribution
Discrete Uniform distribution.
Source code in src/distributions/discrete.py
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 | |
__init__(low=1, high=6)
¶
Initialize Discrete Uniform distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
low
|
int
|
Lower bound (inclusive) |
1
|
high
|
int
|
Upper bound (inclusive) |
6
|
Source code in src/distributions/discrete.py
223 224 225 226 227 228 229 230 231 232 233 234 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
254 255 256 257 258 259 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
240 241 242 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
244 245 246 247 248 249 250 251 252 | |
Distribution
¶
Bases: ABC
Abstract base class for probability distributions.
Source code in src/distributions/base.py
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 170 171 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 | |
__init__(name, is_discrete=False)
¶
Initialize the distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the distribution |
required |
is_discrete
|
bool
|
Whether the distribution is discrete |
False
|
Source code in src/distributions/base.py
15 16 17 18 19 20 21 22 23 24 25 26 | |
__repr__()
¶
String representation of the distribution.
Source code in src/distributions/base.py
328 329 330 331 332 | |
cdf(x)
¶
Calculate cumulative distribution function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input values |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
CDF values |
Source code in src/distributions/base.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
entropy()
¶
Calculate the differential entropy of the distribution.
Returns:
| Type | Description |
|---|---|
float
|
Entropy value |
Source code in src/distributions/base.py
249 250 251 252 253 254 255 256 257 258 259 | |
get_parameter_bounds()
abstractmethod
¶
Get valid parameter ranges.
Returns:
| Type | Description |
|---|---|
dict[str, tuple[float, float]]
|
Dictionary of parameter names and (min, max) tuples |
Source code in src/distributions/base.py
61 62 63 64 65 66 67 68 69 | |
get_parameters()
abstractmethod
¶
Get current distribution parameters.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of parameter names and values |
Source code in src/distributions/base.py
41 42 43 44 45 46 47 48 49 | |
get_statistics()
¶
Get comprehensive statistics for the distribution.
Returns:
| Type | Description |
|---|---|
dict[str, float | None]
|
Dictionary of statistic names and values |
Source code in src/distributions/base.py
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 | |
get_support()
¶
Get the support (valid range) of the distribution.
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (min, max) values |
Source code in src/distributions/base.py
261 262 263 264 265 266 267 268 269 270 271 | |
interval(alpha=0.95)
¶
Calculate confidence interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Confidence level (e.g., 0.95 for 95% confidence) |
0.95
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (lower, upper) bounds |
Source code in src/distributions/base.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
kurtosis()
¶
Calculate the excess kurtosis of the distribution.
Returns:
| Type | Description |
|---|---|
float
|
Excess kurtosis value |
Source code in src/distributions/base.py
236 237 238 239 240 241 242 243 244 245 246 247 | |
mean()
¶
Calculate the mean of the distribution.
Returns:
| Type | Description |
|---|---|
float
|
Mean value |
Source code in src/distributions/base.py
135 136 137 138 139 140 141 142 143 144 145 | |
median()
¶
Calculate the median of the distribution.
Returns:
| Type | Description |
|---|---|
float
|
Median value |
Source code in src/distributions/base.py
171 172 173 174 175 176 177 178 179 180 181 | |
mode()
¶
Calculate the mode of the distribution.
Returns:
| Type | Description |
|---|---|
float
|
Mode value (may not be available for all distributions) |
Source code in src/distributions/base.py
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 | |
pdf(x)
¶
Calculate probability density function (or PMF for discrete).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input values |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
PDF/PMF values |
Source code in src/distributions/base.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
ppf(q)
¶
Calculate percent point function (inverse CDF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
ndarray
|
Probabilities (between 0 and 1) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Quantile values |
Source code in src/distributions/base.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
rvs(size=1, random_state=None)
¶
Generate random samples from the distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples to generate |
1
|
random_state
|
int | None
|
Random seed for reproducibility |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of random samples |
Source code in src/distributions/base.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
set_parameters(**params)
abstractmethod
¶
Set distribution parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**params
|
Any
|
Parameter names and values |
{}
|
Source code in src/distributions/base.py
51 52 53 54 55 56 57 58 59 | |
skewness()
¶
Calculate the skewness of the distribution.
Returns:
| Type | Description |
|---|---|
float
|
Skewness value |
Source code in src/distributions/base.py
223 224 225 226 227 228 229 230 231 232 233 234 | |
std()
¶
Calculate the standard deviation of the distribution.
Returns:
| Type | Description |
|---|---|
float
|
Standard deviation value |
Source code in src/distributions/base.py
159 160 161 162 163 164 165 166 167 168 169 | |
var()
¶
Calculate the variance of the distribution.
Returns:
| Type | Description |
|---|---|
float
|
Variance value |
Source code in src/distributions/base.py
147 148 149 150 151 152 153 154 155 156 157 | |
ExponentialDistribution
¶
Bases: Distribution
Exponential distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(lambda_param=1.0)
¶
Initialize Exponential distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambda_param
|
float
|
Rate parameter (must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
56 57 58 59 60 61 62 63 64 65 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
84 85 86 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
71 72 73 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
75 76 77 78 79 80 81 82 | |
GammaDistribution
¶
Bases: Distribution
Gamma distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(shape=2.0, scale=2.0)
¶
Initialize Gamma distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
float
|
Shape parameter (k, must be > 0) |
2.0
|
scale
|
float
|
Scale parameter (theta, must be > 0) |
2.0
|
Source code in src/distributions/continuous.py
176 177 178 179 180 181 182 183 184 185 186 187 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
207 208 209 210 211 212 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
193 194 195 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
197 198 199 200 201 202 203 204 205 | |
GaussianCopula
¶
Bases: Copula
Gaussian (Normal) copula.
Source code in src/distributions/copulas.py
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 | |
__init__(correlation)
¶
Initialize Gaussian copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
correlation
|
ndarray
|
Correlation matrix (must be positive definite) |
required |
Source code in src/distributions/copulas.py
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 | |
cdf(u)
¶
Gaussian copula CDF.
Source code in src/distributions/copulas.py
93 94 95 96 97 98 99 100 101 102 103 104 | |
kendall_tau()
¶
Calculate Kendall's tau (for bivariate case).
Returns:
| Type | Description |
|---|---|
float
|
Kendall's tau |
Source code in src/distributions/copulas.py
144 145 146 147 148 149 150 151 152 153 154 155 | |
pdf(u)
¶
Gaussian copula density.
Source code in src/distributions/copulas.py
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 | |
rvs(size=1, random_state=None)
¶
Generate samples from Gaussian copula.
Source code in src/distributions/copulas.py
132 133 134 135 136 137 138 139 140 141 142 | |
GaussianMixtureModel
¶
Gaussian Mixture Model using sklearn.
Source code in src/distributions/mixtures.py
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 333 334 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 | |
__init__(n_components=2, covariance_type='full', max_iter=100)
¶
Initialize Gaussian Mixture Model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_components
|
int
|
Number of mixture components |
2
|
covariance_type
|
str
|
Type of covariance ('full', 'tied', 'diag', 'spherical') |
'full'
|
max_iter
|
int
|
Maximum EM iterations |
100
|
Source code in src/distributions/mixtures.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
aic(data)
¶
Calculate Akaike Information Criterion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data |
required |
Returns:
| Type | Description |
|---|---|
float
|
AIC value |
Source code in src/distributions/mixtures.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
bic(data)
¶
Calculate Bayesian Information Criterion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data |
required |
Returns:
| Type | Description |
|---|---|
float
|
BIC value |
Source code in src/distributions/mixtures.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
fit(data)
¶
Fit GMM to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Training data (n x d) |
required |
Returns:
| Type | Description |
|---|---|
GaussianMixtureModel
|
Self |
Source code in src/distributions/mixtures.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
get_parameters()
¶
Get fitted parameters.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with means, covariances, and weights |
Source code in src/distributions/mixtures.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
pdf(data)
¶
Calculate probability density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data points |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
PDF values |
Source code in src/distributions/mixtures.py
306 307 308 309 310 311 312 313 314 315 316 317 | |
predict(data)
¶
Predict component labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data to predict |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Component labels |
Source code in src/distributions/mixtures.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
rvs(size=1)
¶
Generate random samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Samples |
Source code in src/distributions/mixtures.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
score_samples(data)
¶
Calculate log-likelihood of samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data to score |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Log-likelihood values |
Source code in src/distributions/mixtures.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
GeometricDistribution
¶
Bases: Distribution
Geometric distribution.
Source code in src/distributions/discrete.py
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 | |
__init__(p=0.5)
¶
Initialize Geometric distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Probability of success (must be between 0 and 1) |
0.5
|
Source code in src/distributions/discrete.py
93 94 95 96 97 98 99 100 101 102 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
121 122 123 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
108 109 110 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
112 113 114 115 116 117 118 119 | |
GumbelCopula
¶
Bases: Copula
Gumbel copula (Archimedean).
Source code in src/distributions/copulas.py
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 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
__init__(theta, dimension=2)
¶
Initialize Gumbel copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
Dependence parameter (theta >= 1) |
required |
dimension
|
int
|
Number of dimensions |
2
|
Source code in src/distributions/copulas.py
248 249 250 251 252 253 254 255 256 257 258 259 260 | |
cdf(u)
¶
Gumbel copula CDF.
Source code in src/distributions/copulas.py
262 263 264 265 266 267 268 269 270 271 | |
kendall_tau()
¶
Calculate Kendall's tau.
Returns:
| Type | Description |
|---|---|
float
|
Kendall's tau |
Source code in src/distributions/copulas.py
341 342 343 344 345 346 347 348 | |
pdf(u)
¶
Gumbel copula density (bivariate only).
Source code in src/distributions/copulas.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
rvs(size=1, random_state=None)
¶
Generate samples from Gumbel copula (bivariate only).
Source code in src/distributions/copulas.py
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 333 334 335 336 337 338 339 | |
HypergeometricDistribution
¶
Bases: Distribution
Hypergeometric distribution.
Source code in src/distributions/discrete.py
170 171 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 | |
__init__(M=20, n=7, N=12)
¶
Initialize Hypergeometric distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
M
|
int
|
Total population size |
20
|
n
|
int
|
Number of success states in population |
7
|
N
|
int
|
Number of draws |
12
|
Source code in src/distributions/discrete.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
211 212 213 214 215 216 217 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
192 193 194 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
LognormalDistribution
¶
Bases: Distribution
Lognormal distribution.
Source code in src/distributions/continuous.py
329 330 331 332 333 334 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 | |
__init__(mu=0.0, sigma=1.0)
¶
Initialize Lognormal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
float
|
Mean of underlying normal distribution |
0.0
|
sigma
|
float
|
Standard deviation of underlying normal distribution (must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
332 333 334 335 336 337 338 339 340 341 342 343 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
364 365 366 367 368 369 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
349 350 351 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
353 354 355 356 357 358 359 360 361 362 | |
MixtureDistribution
¶
General mixture distribution.
Source code in src/distributions/mixtures.py
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 170 171 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 | |
__init__(components, weights)
¶
Initialize mixture distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
list
|
List of component distributions |
required |
weights
|
list[float] | ndarray
|
Mixing weights (must sum to 1) |
required |
Source code in src/distributions/mixtures.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
cdf(x)
¶
Calculate cumulative distribution function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input values |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
CDF values |
Source code in src/distributions/mixtures.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
fit_em(data, n_components, max_iter=100, tol=0.0001, random_state=None)
¶
Fit mixture model using Expectation-Maximization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Observed data |
required |
n_components
|
int
|
Number of mixture components |
required |
max_iter
|
int
|
Maximum EM iterations |
100
|
tol
|
float
|
Convergence tolerance |
0.0001
|
random_state
|
int | None
|
Seed for the random component initialization.
Pass an int for reproducible fits; |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, list, list[float]]
|
Tuple of (responsibilities, components, weights) |
Source code in src/distributions/mixtures.py
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 170 171 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 | |
mean()
¶
Calculate mean of mixture.
Returns:
| Type | Description |
|---|---|
float
|
Mean value |
Source code in src/distributions/mixtures.py
108 109 110 111 112 113 114 115 116 117 118 119 | |
pdf(x)
¶
Calculate probability density function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input values |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
PDF values |
Source code in src/distributions/mixtures.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
random_state
|
int | None
|
Random seed |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Random samples |
Source code in src/distributions/mixtures.py
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 | |
var()
¶
Calculate variance of mixture.
Returns:
| Type | Description |
|---|---|
float
|
Variance value |
Source code in src/distributions/mixtures.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
MultivariateDistribution
¶
Base class for multivariate distributions.
Source code in src/distributions/multivariate.py
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 | |
__init__(name, dimension)
¶
Initialize multivariate distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the distribution |
required |
dimension
|
int
|
Number of dimensions |
required |
Source code in src/distributions/multivariate.py
14 15 16 17 18 19 20 21 22 23 24 | |
cov()
¶
Calculate covariance matrix.
Source code in src/distributions/multivariate.py
38 39 40 | |
mean()
¶
Calculate mean vector.
Source code in src/distributions/multivariate.py
34 35 36 | |
pdf(x)
¶
Calculate probability density function.
Source code in src/distributions/multivariate.py
26 27 28 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Source code in src/distributions/multivariate.py
30 31 32 | |
MultivariateNormalDistribution
¶
Bases: MultivariateDistribution
Multivariate Normal (Gaussian) distribution.
Source code in src/distributions/multivariate.py
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
__init__(mean, cov)
¶
Initialize Multivariate Normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
ndarray
|
Mean vector (shape: d) |
required |
cov
|
ndarray
|
Covariance matrix (shape: d x d) |
required |
Source code in src/distributions/multivariate.py
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 | |
conditional(indices, values)
¶
Get conditional distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
list
|
Indices of variables to condition on |
required |
values
|
ndarray
|
Values of conditioned variables |
required |
Returns:
| Type | Description |
|---|---|
MultivariateNormalDistribution
|
Conditional distribution |
Source code in src/distributions/multivariate.py
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 | |
cov()
¶
Calculate covariance matrix.
Source code in src/distributions/multivariate.py
119 120 121 | |
logpdf(x)
¶
Calculate log probability density function.
Source code in src/distributions/multivariate.py
94 95 96 97 98 | |
mahalanobis(x)
¶
Calculate Mahalanobis distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Points (shape: n x d or d) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Mahalanobis distances |
Source code in src/distributions/multivariate.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
marginal(indices)
¶
Get marginal distribution for selected variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
list
|
List of variable indices to keep |
required |
Returns:
| Type | Description |
|---|---|
MultivariateNormalDistribution
|
Marginal distribution |
Source code in src/distributions/multivariate.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
mean()
¶
Calculate mean vector.
Source code in src/distributions/multivariate.py
115 116 117 | |
pdf(x)
¶
Calculate probability density function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Points to evaluate (shape: n x d or d) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
PDF values |
Source code in src/distributions/multivariate.py
80 81 82 83 84 85 86 87 88 89 90 91 92 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
random_state
|
int | None
|
Random seed |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Samples (shape: size x d) |
Source code in src/distributions/multivariate.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
MultivariateStudentT
¶
Bases: MultivariateDistribution
Multivariate Student's t-distribution.
Source code in src/distributions/multivariate.py
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 333 334 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 | |
__init__(df, loc, shape)
¶
Initialize Multivariate Student-t distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
float
|
Degrees of freedom |
required |
loc
|
ndarray
|
Location vector |
required |
shape
|
ndarray
|
Shape matrix (similar to covariance) |
required |
Source code in src/distributions/multivariate.py
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 | |
cov()
¶
Calculate covariance matrix (only for df > 2).
Source code in src/distributions/multivariate.py
353 354 355 356 357 | |
mean()
¶
Calculate mean vector (only for df > 1).
Source code in src/distributions/multivariate.py
347 348 349 350 351 | |
pdf(x)
¶
Calculate probability density function.
Source code in src/distributions/multivariate.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Source code in src/distributions/multivariate.py
334 335 336 337 338 339 340 341 342 343 344 345 | |
NegativeBinomialDistribution
¶
Bases: Distribution
Negative Binomial distribution.
Source code in src/distributions/discrete.py
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 | |
__init__(r=5, p=0.5)
¶
Initialize Negative Binomial distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
int
|
Number of successes (must be positive integer) |
5
|
p
|
float
|
Probability of success (must be between 0 and 1) |
0.5
|
Source code in src/distributions/discrete.py
129 130 131 132 133 134 135 136 137 138 139 140 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
162 163 164 165 166 167 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
146 147 148 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
150 151 152 153 154 155 156 157 158 159 160 | |
NormalDistribution
¶
Bases: Distribution
Normal (Gaussian) distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(mu=0.0, sigma=1.0)
¶
Initialize Normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
float
|
Mean parameter |
0.0
|
sigma
|
float
|
Standard deviation parameter (must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
14 15 16 17 18 19 20 21 22 23 24 25 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
45 46 47 48 49 50 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
31 32 33 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
35 36 37 38 39 40 41 42 43 | |
PoissonDistribution
¶
Bases: Distribution
Poisson distribution.
Source code in src/distributions/discrete.py
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 | |
__init__(lambda_param=3.0)
¶
Initialize Poisson distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambda_param
|
float
|
Rate parameter (must be > 0) |
3.0
|
Source code in src/distributions/discrete.py
57 58 59 60 61 62 63 64 65 66 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
85 86 87 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
72 73 74 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
76 77 78 79 80 81 82 83 | |
StudentTCopula
¶
Bases: Copula
Student-t copula.
Source code in src/distributions/copulas.py
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 | |
__init__(correlation, df)
¶
Initialize Student-t copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
correlation
|
ndarray
|
Correlation matrix |
required |
df
|
float
|
Degrees of freedom |
required |
Source code in src/distributions/copulas.py
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 | |
cdf(u)
¶
Student-t copula CDF.
Note: closed-form evaluation requires multivariate-t integration and is
not implemented; use Monte Carlo estimation via :meth:rvs instead.
Source code in src/distributions/copulas.py
385 386 387 388 389 390 391 392 393 394 | |
kendall_tau()
¶
Calculate Kendall's tau (bivariate only).
Returns:
| Type | Description |
|---|---|
float
|
Kendall's tau |
Source code in src/distributions/copulas.py
425 426 427 428 429 430 431 432 433 434 435 436 | |
pdf(u)
¶
Student-t copula density.
Note: the density is not implemented; use sampling-based inference via
:meth:rvs instead.
Source code in src/distributions/copulas.py
396 397 398 399 400 401 402 403 404 | |
rvs(size=1, random_state=None)
¶
Generate samples from Student-t copula.
Source code in src/distributions/copulas.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
StudentTDistribution
¶
Bases: Distribution
Student's t-distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(df=10.0)
¶
Initialize Student's t-distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
float
|
Degrees of freedom (must be > 0) |
10.0
|
Source code in src/distributions/continuous.py
254 255 256 257 258 259 260 261 262 263 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
282 283 284 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
269 270 271 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
273 274 275 276 277 278 279 280 | |
UniformDistribution
¶
Bases: Distribution
Continuous Uniform distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(a=0.0, b=1.0)
¶
Initialize Uniform distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Lower bound |
0.0
|
b
|
float
|
Upper bound (must be > a) |
1.0
|
Source code in src/distributions/continuous.py
92 93 94 95 96 97 98 99 100 101 102 103 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
123 124 125 126 127 128 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
109 110 111 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
113 114 115 116 117 118 119 120 121 | |
WeibullDistribution
¶
Bases: Distribution
Weibull distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(shape=1.5, scale=1.0)
¶
Initialize Weibull distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
float
|
Shape parameter (k, must be > 0) |
1.5
|
scale
|
float
|
Scale parameter (lambda, must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
290 291 292 293 294 295 296 297 298 299 300 301 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
321 322 323 324 325 326 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
307 308 309 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
311 312 313 314 315 316 317 318 319 | |
WishartDistribution
¶
Wishart distribution (distribution over positive definite matrices).
Source code in src/distributions/multivariate.py
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 | |
__init__(df, scale)
¶
Initialize Wishart distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
int
|
Degrees of freedom (must be >= dimension) |
required |
scale
|
ndarray
|
Scale matrix (positive definite) |
required |
Source code in src/distributions/multivariate.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
logpdf(x)
¶
Calculate log probability density function.
Source code in src/distributions/multivariate.py
394 395 396 | |
mean()
¶
Calculate mean matrix.
Source code in src/distributions/multivariate.py
402 403 404 | |
mode()
¶
Calculate mode matrix.
Source code in src/distributions/multivariate.py
406 407 408 409 410 | |
pdf(x)
¶
Calculate probability density function.
Source code in src/distributions/multivariate.py
390 391 392 | |
rvs(size=1, random_state=None)
¶
Generate random positive definite matrices.
Source code in src/distributions/multivariate.py
398 399 400 | |
fit_copula_to_data(data, copula_type='gaussian', method='rank')
¶
Fit copula to multivariate data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Multivariate data (n x d) |
required |
copula_type
|
str
|
Type of copula ('gaussian', 'clayton', 'gumbel', 't') |
'gaussian'
|
method
|
str
|
Method for pseudo-observations ('rank' or 'empirical') |
'rank'
|
Returns:
| Type | Description |
|---|---|
Copula
|
Fitted copula object |
Source code in src/distributions/copulas.py
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 | |
plot_bivariate_normal(dist, num_points=100, num_contours=10)
¶
Plot bivariate normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
MultivariateNormalDistribution
|
Multivariate normal distribution (dimension must be 2) |
required |
num_points
|
int
|
Number of grid points |
100
|
num_contours
|
int
|
Number of contour levels |
10
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, tuple[Axes, Axes]]
|
Figure and axes objects |
Source code in src/distributions/multivariate.py
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 | |
plot_dirichlet_simplex(dist, num_samples=1000)
¶
Plot Dirichlet distribution samples on simplex (for dimension 3).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
DirichletDistribution
|
Dirichlet distribution (dimension must be 3) |
required |
num_samples
|
int
|
Number of samples to generate |
1000
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
Figure and axes objects |
Source code in src/distributions/multivariate.py
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 527 528 529 530 | |
select_optimal_components(data, max_components=10)
¶
Select optimal number of components using BIC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Training data |
required |
max_components
|
int
|
Maximum components to try |
10
|
Returns:
| Type | Description |
|---|---|
tuple[int, dict]
|
Tuple of (optimal_n_components, results_dict) |
Source code in src/distributions/mixtures.py
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 | |
src.distributions.continuous
¶
Continuous probability distributions.
BetaDistribution
¶
Bases: Distribution
Beta distribution.
Source code in src/distributions/continuous.py
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 170 | |
__init__(alpha=2.0, beta=2.0)
¶
Initialize Beta distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Shape parameter (must be > 0) |
2.0
|
beta
|
float
|
Shape parameter (must be > 0) |
2.0
|
Source code in src/distributions/continuous.py
134 135 136 137 138 139 140 141 142 143 144 145 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
165 166 167 168 169 170 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
151 152 153 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
155 156 157 158 159 160 161 162 163 | |
CauchyDistribution
¶
Bases: Distribution
Cauchy distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(x0=0.0, gamma=1.0)
¶
Initialize Cauchy distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
float
|
Location parameter |
0.0
|
gamma
|
float
|
Scale parameter (must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
375 376 377 378 379 380 381 382 383 384 385 386 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
406 407 408 409 410 411 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
392 393 394 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
396 397 398 399 400 401 402 403 404 | |
ChiSquareDistribution
¶
Bases: Distribution
Chi-square distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(df=3)
¶
Initialize Chi-square distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
int
|
Degrees of freedom (must be > 0) |
3
|
Source code in src/distributions/continuous.py
218 219 220 221 222 223 224 225 226 227 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
246 247 248 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
233 234 235 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
237 238 239 240 241 242 243 244 | |
ExponentialDistribution
¶
Bases: Distribution
Exponential distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(lambda_param=1.0)
¶
Initialize Exponential distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambda_param
|
float
|
Rate parameter (must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
56 57 58 59 60 61 62 63 64 65 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
84 85 86 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
71 72 73 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
75 76 77 78 79 80 81 82 | |
GammaDistribution
¶
Bases: Distribution
Gamma distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(shape=2.0, scale=2.0)
¶
Initialize Gamma distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
float
|
Shape parameter (k, must be > 0) |
2.0
|
scale
|
float
|
Scale parameter (theta, must be > 0) |
2.0
|
Source code in src/distributions/continuous.py
176 177 178 179 180 181 182 183 184 185 186 187 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
207 208 209 210 211 212 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
193 194 195 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
197 198 199 200 201 202 203 204 205 | |
LognormalDistribution
¶
Bases: Distribution
Lognormal distribution.
Source code in src/distributions/continuous.py
329 330 331 332 333 334 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 | |
__init__(mu=0.0, sigma=1.0)
¶
Initialize Lognormal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
float
|
Mean of underlying normal distribution |
0.0
|
sigma
|
float
|
Standard deviation of underlying normal distribution (must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
332 333 334 335 336 337 338 339 340 341 342 343 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
364 365 366 367 368 369 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
349 350 351 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
353 354 355 356 357 358 359 360 361 362 | |
NormalDistribution
¶
Bases: Distribution
Normal (Gaussian) distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(mu=0.0, sigma=1.0)
¶
Initialize Normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
float
|
Mean parameter |
0.0
|
sigma
|
float
|
Standard deviation parameter (must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
14 15 16 17 18 19 20 21 22 23 24 25 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
45 46 47 48 49 50 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
31 32 33 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
35 36 37 38 39 40 41 42 43 | |
StudentTDistribution
¶
Bases: Distribution
Student's t-distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(df=10.0)
¶
Initialize Student's t-distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
float
|
Degrees of freedom (must be > 0) |
10.0
|
Source code in src/distributions/continuous.py
254 255 256 257 258 259 260 261 262 263 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
282 283 284 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
269 270 271 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
273 274 275 276 277 278 279 280 | |
UniformDistribution
¶
Bases: Distribution
Continuous Uniform distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(a=0.0, b=1.0)
¶
Initialize Uniform distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Lower bound |
0.0
|
b
|
float
|
Upper bound (must be > a) |
1.0
|
Source code in src/distributions/continuous.py
92 93 94 95 96 97 98 99 100 101 102 103 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
123 124 125 126 127 128 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
109 110 111 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
113 114 115 116 117 118 119 120 121 | |
WeibullDistribution
¶
Bases: Distribution
Weibull distribution.
Source code in src/distributions/continuous.py
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 | |
__init__(shape=1.5, scale=1.0)
¶
Initialize Weibull distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
float
|
Shape parameter (k, must be > 0) |
1.5
|
scale
|
float
|
Scale parameter (lambda, must be > 0) |
1.0
|
Source code in src/distributions/continuous.py
290 291 292 293 294 295 296 297 298 299 300 301 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/continuous.py
321 322 323 324 325 326 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/continuous.py
307 308 309 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/continuous.py
311 312 313 314 315 316 317 318 319 | |
src.distributions.discrete
¶
Discrete probability distributions.
BinomialDistribution
¶
Bases: Distribution
Binomial distribution.
Source code in src/distributions/discrete.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 | |
__init__(n=10, p=0.5)
¶
Initialize Binomial distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of trials (must be positive integer) |
10
|
p
|
float
|
Probability of success (must be between 0 and 1) |
0.5
|
Source code in src/distributions/discrete.py
13 14 15 16 17 18 19 20 21 22 23 24 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
46 47 48 49 50 51 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
30 31 32 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
34 35 36 37 38 39 40 41 42 43 44 | |
DiscreteUniformDistribution
¶
Bases: Distribution
Discrete Uniform distribution.
Source code in src/distributions/discrete.py
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 | |
__init__(low=1, high=6)
¶
Initialize Discrete Uniform distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
low
|
int
|
Lower bound (inclusive) |
1
|
high
|
int
|
Upper bound (inclusive) |
6
|
Source code in src/distributions/discrete.py
223 224 225 226 227 228 229 230 231 232 233 234 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
254 255 256 257 258 259 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
240 241 242 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
244 245 246 247 248 249 250 251 252 | |
GeometricDistribution
¶
Bases: Distribution
Geometric distribution.
Source code in src/distributions/discrete.py
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 | |
__init__(p=0.5)
¶
Initialize Geometric distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Probability of success (must be between 0 and 1) |
0.5
|
Source code in src/distributions/discrete.py
93 94 95 96 97 98 99 100 101 102 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
121 122 123 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
108 109 110 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
112 113 114 115 116 117 118 119 | |
HypergeometricDistribution
¶
Bases: Distribution
Hypergeometric distribution.
Source code in src/distributions/discrete.py
170 171 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 | |
__init__(M=20, n=7, N=12)
¶
Initialize Hypergeometric distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
M
|
int
|
Total population size |
20
|
n
|
int
|
Number of success states in population |
7
|
N
|
int
|
Number of draws |
12
|
Source code in src/distributions/discrete.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
211 212 213 214 215 216 217 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
192 193 194 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
NegativeBinomialDistribution
¶
Bases: Distribution
Negative Binomial distribution.
Source code in src/distributions/discrete.py
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 | |
__init__(r=5, p=0.5)
¶
Initialize Negative Binomial distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
int
|
Number of successes (must be positive integer) |
5
|
p
|
float
|
Probability of success (must be between 0 and 1) |
0.5
|
Source code in src/distributions/discrete.py
129 130 131 132 133 134 135 136 137 138 139 140 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
162 163 164 165 166 167 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
146 147 148 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
150 151 152 153 154 155 156 157 158 159 160 | |
PoissonDistribution
¶
Bases: Distribution
Poisson distribution.
Source code in src/distributions/discrete.py
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 | |
__init__(lambda_param=3.0)
¶
Initialize Poisson distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambda_param
|
float
|
Rate parameter (must be > 0) |
3.0
|
Source code in src/distributions/discrete.py
57 58 59 60 61 62 63 64 65 66 | |
get_parameter_bounds()
¶
Get parameter bounds.
Source code in src/distributions/discrete.py
85 86 87 | |
get_parameters()
¶
Get current parameters.
Source code in src/distributions/discrete.py
72 73 74 | |
set_parameters(**params)
¶
Set distribution parameters.
Source code in src/distributions/discrete.py
76 77 78 79 80 81 82 83 | |
src.distributions.multivariate
¶
Multivariate probability distributions.
DirichletDistribution
¶
Bases: MultivariateDistribution
Dirichlet distribution.
Source code in src/distributions/multivariate.py
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 | |
__init__(alpha)
¶
Initialize Dirichlet distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
ndarray
|
Concentration parameters (must be positive) |
required |
Source code in src/distributions/multivariate.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
cov()
¶
Calculate covariance matrix.
Source code in src/distributions/multivariate.py
253 254 255 256 257 | |
entropy()
¶
Calculate differential entropy.
Source code in src/distributions/multivariate.py
271 272 273 274 275 | |
logpdf(x)
¶
Calculate log probability density function.
Source code in src/distributions/multivariate.py
223 224 225 226 227 | |
mean()
¶
Calculate mean vector.
Source code in src/distributions/multivariate.py
244 245 246 | |
mode()
¶
Calculate mode.
Returns:
| Type | Description |
|---|---|
ndarray
|
Mode vector (only valid if all alpha > 1) |
Source code in src/distributions/multivariate.py
259 260 261 262 263 264 265 266 267 268 269 | |
pdf(x)
¶
Calculate probability density function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Points on simplex (shape: n x d or d), must sum to 1 |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
PDF values |
Source code in src/distributions/multivariate.py
209 210 211 212 213 214 215 216 217 218 219 220 221 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
random_state
|
int | None
|
Random seed |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Samples on simplex (shape: size x d) |
Source code in src/distributions/multivariate.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
var()
¶
Calculate variance for each component.
Source code in src/distributions/multivariate.py
248 249 250 251 | |
MultivariateDistribution
¶
Base class for multivariate distributions.
Source code in src/distributions/multivariate.py
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 | |
__init__(name, dimension)
¶
Initialize multivariate distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the distribution |
required |
dimension
|
int
|
Number of dimensions |
required |
Source code in src/distributions/multivariate.py
14 15 16 17 18 19 20 21 22 23 24 | |
cov()
¶
Calculate covariance matrix.
Source code in src/distributions/multivariate.py
38 39 40 | |
mean()
¶
Calculate mean vector.
Source code in src/distributions/multivariate.py
34 35 36 | |
pdf(x)
¶
Calculate probability density function.
Source code in src/distributions/multivariate.py
26 27 28 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Source code in src/distributions/multivariate.py
30 31 32 | |
MultivariateNormalDistribution
¶
Bases: MultivariateDistribution
Multivariate Normal (Gaussian) distribution.
Source code in src/distributions/multivariate.py
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
__init__(mean, cov)
¶
Initialize Multivariate Normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
ndarray
|
Mean vector (shape: d) |
required |
cov
|
ndarray
|
Covariance matrix (shape: d x d) |
required |
Source code in src/distributions/multivariate.py
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 | |
conditional(indices, values)
¶
Get conditional distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
list
|
Indices of variables to condition on |
required |
values
|
ndarray
|
Values of conditioned variables |
required |
Returns:
| Type | Description |
|---|---|
MultivariateNormalDistribution
|
Conditional distribution |
Source code in src/distributions/multivariate.py
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 | |
cov()
¶
Calculate covariance matrix.
Source code in src/distributions/multivariate.py
119 120 121 | |
logpdf(x)
¶
Calculate log probability density function.
Source code in src/distributions/multivariate.py
94 95 96 97 98 | |
mahalanobis(x)
¶
Calculate Mahalanobis distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Points (shape: n x d or d) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Mahalanobis distances |
Source code in src/distributions/multivariate.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
marginal(indices)
¶
Get marginal distribution for selected variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
list
|
List of variable indices to keep |
required |
Returns:
| Type | Description |
|---|---|
MultivariateNormalDistribution
|
Marginal distribution |
Source code in src/distributions/multivariate.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
mean()
¶
Calculate mean vector.
Source code in src/distributions/multivariate.py
115 116 117 | |
pdf(x)
¶
Calculate probability density function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Points to evaluate (shape: n x d or d) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
PDF values |
Source code in src/distributions/multivariate.py
80 81 82 83 84 85 86 87 88 89 90 91 92 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
random_state
|
int | None
|
Random seed |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Samples (shape: size x d) |
Source code in src/distributions/multivariate.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
MultivariateStudentT
¶
Bases: MultivariateDistribution
Multivariate Student's t-distribution.
Source code in src/distributions/multivariate.py
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 333 334 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 | |
__init__(df, loc, shape)
¶
Initialize Multivariate Student-t distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
float
|
Degrees of freedom |
required |
loc
|
ndarray
|
Location vector |
required |
shape
|
ndarray
|
Shape matrix (similar to covariance) |
required |
Source code in src/distributions/multivariate.py
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 | |
cov()
¶
Calculate covariance matrix (only for df > 2).
Source code in src/distributions/multivariate.py
353 354 355 356 357 | |
mean()
¶
Calculate mean vector (only for df > 1).
Source code in src/distributions/multivariate.py
347 348 349 350 351 | |
pdf(x)
¶
Calculate probability density function.
Source code in src/distributions/multivariate.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Source code in src/distributions/multivariate.py
334 335 336 337 338 339 340 341 342 343 344 345 | |
WishartDistribution
¶
Wishart distribution (distribution over positive definite matrices).
Source code in src/distributions/multivariate.py
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 | |
__init__(df, scale)
¶
Initialize Wishart distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
int
|
Degrees of freedom (must be >= dimension) |
required |
scale
|
ndarray
|
Scale matrix (positive definite) |
required |
Source code in src/distributions/multivariate.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
logpdf(x)
¶
Calculate log probability density function.
Source code in src/distributions/multivariate.py
394 395 396 | |
mean()
¶
Calculate mean matrix.
Source code in src/distributions/multivariate.py
402 403 404 | |
mode()
¶
Calculate mode matrix.
Source code in src/distributions/multivariate.py
406 407 408 409 410 | |
pdf(x)
¶
Calculate probability density function.
Source code in src/distributions/multivariate.py
390 391 392 | |
rvs(size=1, random_state=None)
¶
Generate random positive definite matrices.
Source code in src/distributions/multivariate.py
398 399 400 | |
plot_bivariate_normal(dist, num_points=100, num_contours=10)
¶
Plot bivariate normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
MultivariateNormalDistribution
|
Multivariate normal distribution (dimension must be 2) |
required |
num_points
|
int
|
Number of grid points |
100
|
num_contours
|
int
|
Number of contour levels |
10
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, tuple[Axes, Axes]]
|
Figure and axes objects |
Source code in src/distributions/multivariate.py
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 | |
plot_dirichlet_simplex(dist, num_samples=1000)
¶
Plot Dirichlet distribution samples on simplex (for dimension 3).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
DirichletDistribution
|
Dirichlet distribution (dimension must be 3) |
required |
num_samples
|
int
|
Number of samples to generate |
1000
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
Figure and axes objects |
Source code in src/distributions/multivariate.py
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 527 528 529 530 | |
src.distributions.copulas
¶
Copulas for modeling dependencies between random variables.
ClaytonCopula
¶
Bases: Copula
Clayton copula (Archimedean).
Source code in src/distributions/copulas.py
161 162 163 164 165 166 167 168 169 170 171 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 | |
__init__(theta, dimension=2)
¶
Initialize Clayton copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
Dependence parameter (theta >= -1/(d-1), theta != 0) |
required |
dimension
|
int
|
Number of dimensions |
2
|
Source code in src/distributions/copulas.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
cdf(u)
¶
Clayton copula CDF.
Source code in src/distributions/copulas.py
182 183 184 185 186 187 188 189 190 | |
kendall_tau()
¶
Calculate Kendall's tau.
Returns:
| Type | Description |
|---|---|
float
|
Kendall's tau |
Source code in src/distributions/copulas.py
232 233 234 235 236 237 238 239 | |
pdf(u)
¶
Clayton copula density (bivariate only).
Source code in src/distributions/copulas.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
rvs(size=1, random_state=None)
¶
Generate samples from Clayton copula (bivariate only).
Source code in src/distributions/copulas.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
Copula
¶
Base class for copulas.
Source code in src/distributions/copulas.py
8 9 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 | |
__init__(name, dimension=2)
¶
Initialize copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Copula name |
required |
dimension
|
int
|
Number of dimensions |
2
|
Source code in src/distributions/copulas.py
11 12 13 14 15 16 17 18 19 20 | |
cdf(u)
¶
Copula CDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Uniform(0,1) marginals (shape: n x d or d) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Copula CDF values |
Source code in src/distributions/copulas.py
22 23 24 25 26 27 28 29 30 31 32 | |
kendall_tau()
¶
Calculate Kendall's tau.
Source code in src/distributions/copulas.py
59 60 61 | |
pdf(u)
¶
Copula density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
Uniform(0,1) marginals |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Copula density values |
Source code in src/distributions/copulas.py
34 35 36 37 38 39 40 41 42 43 44 | |
rvs(size=1, random_state=None)
¶
Generate random samples from copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
random_state
|
int | None
|
Random seed |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Uniform(0,1) samples (shape: size x d) |
Source code in src/distributions/copulas.py
46 47 48 49 50 51 52 53 54 55 56 57 | |
GaussianCopula
¶
Bases: Copula
Gaussian (Normal) copula.
Source code in src/distributions/copulas.py
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 | |
__init__(correlation)
¶
Initialize Gaussian copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
correlation
|
ndarray
|
Correlation matrix (must be positive definite) |
required |
Source code in src/distributions/copulas.py
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 | |
cdf(u)
¶
Gaussian copula CDF.
Source code in src/distributions/copulas.py
93 94 95 96 97 98 99 100 101 102 103 104 | |
kendall_tau()
¶
Calculate Kendall's tau (for bivariate case).
Returns:
| Type | Description |
|---|---|
float
|
Kendall's tau |
Source code in src/distributions/copulas.py
144 145 146 147 148 149 150 151 152 153 154 155 | |
pdf(u)
¶
Gaussian copula density.
Source code in src/distributions/copulas.py
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 | |
rvs(size=1, random_state=None)
¶
Generate samples from Gaussian copula.
Source code in src/distributions/copulas.py
132 133 134 135 136 137 138 139 140 141 142 | |
GumbelCopula
¶
Bases: Copula
Gumbel copula (Archimedean).
Source code in src/distributions/copulas.py
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 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
__init__(theta, dimension=2)
¶
Initialize Gumbel copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
Dependence parameter (theta >= 1) |
required |
dimension
|
int
|
Number of dimensions |
2
|
Source code in src/distributions/copulas.py
248 249 250 251 252 253 254 255 256 257 258 259 260 | |
cdf(u)
¶
Gumbel copula CDF.
Source code in src/distributions/copulas.py
262 263 264 265 266 267 268 269 270 271 | |
kendall_tau()
¶
Calculate Kendall's tau.
Returns:
| Type | Description |
|---|---|
float
|
Kendall's tau |
Source code in src/distributions/copulas.py
341 342 343 344 345 346 347 348 | |
pdf(u)
¶
Gumbel copula density (bivariate only).
Source code in src/distributions/copulas.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
rvs(size=1, random_state=None)
¶
Generate samples from Gumbel copula (bivariate only).
Source code in src/distributions/copulas.py
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 333 334 335 336 337 338 339 | |
StudentTCopula
¶
Bases: Copula
Student-t copula.
Source code in src/distributions/copulas.py
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 | |
__init__(correlation, df)
¶
Initialize Student-t copula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
correlation
|
ndarray
|
Correlation matrix |
required |
df
|
float
|
Degrees of freedom |
required |
Source code in src/distributions/copulas.py
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 | |
cdf(u)
¶
Student-t copula CDF.
Note: closed-form evaluation requires multivariate-t integration and is
not implemented; use Monte Carlo estimation via :meth:rvs instead.
Source code in src/distributions/copulas.py
385 386 387 388 389 390 391 392 393 394 | |
kendall_tau()
¶
Calculate Kendall's tau (bivariate only).
Returns:
| Type | Description |
|---|---|
float
|
Kendall's tau |
Source code in src/distributions/copulas.py
425 426 427 428 429 430 431 432 433 434 435 436 | |
pdf(u)
¶
Student-t copula density.
Note: the density is not implemented; use sampling-based inference via
:meth:rvs instead.
Source code in src/distributions/copulas.py
396 397 398 399 400 401 402 403 404 | |
rvs(size=1, random_state=None)
¶
Generate samples from Student-t copula.
Source code in src/distributions/copulas.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
fit_copula_to_data(data, copula_type='gaussian', method='rank')
¶
Fit copula to multivariate data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Multivariate data (n x d) |
required |
copula_type
|
str
|
Type of copula ('gaussian', 'clayton', 'gumbel', 't') |
'gaussian'
|
method
|
str
|
Method for pseudo-observations ('rank' or 'empirical') |
'rank'
|
Returns:
| Type | Description |
|---|---|
Copula
|
Fitted copula object |
Source code in src/distributions/copulas.py
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 | |
src.distributions.mixtures
¶
Mixture distributions - combinations of multiple distributions.
BayesianGMM
¶
Bayesian Gaussian Mixture Model with automatic component selection.
Source code in src/distributions/mixtures.py
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 | |
__init__(max_components=10, weight_concentration_prior=1.0, max_iter=200, tol=0.0001)
¶
Initialize Bayesian GMM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_components
|
int
|
Maximum number of components |
10
|
weight_concentration_prior
|
float
|
Dirichlet concentration prior |
1.0
|
max_iter
|
int
|
Maximum EM iterations |
200
|
tol
|
float
|
Convergence tolerance |
0.0001
|
Source code in src/distributions/mixtures.py
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 | |
fit(data)
¶
Fit Bayesian GMM to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Training data |
required |
Returns:
| Type | Description |
|---|---|
BayesianGMM
|
Self |
Source code in src/distributions/mixtures.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
get_active_components()
¶
Get number of active components (with non-negligible weight).
Returns:
| Type | Description |
|---|---|
int
|
Number of active components |
Source code in src/distributions/mixtures.py
441 442 443 444 445 446 447 448 449 450 451 452 | |
predict(data)
¶
Predict component labels.
Source code in src/distributions/mixtures.py
432 433 434 435 436 437 438 439 | |
GaussianMixtureModel
¶
Gaussian Mixture Model using sklearn.
Source code in src/distributions/mixtures.py
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 333 334 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 | |
__init__(n_components=2, covariance_type='full', max_iter=100)
¶
Initialize Gaussian Mixture Model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_components
|
int
|
Number of mixture components |
2
|
covariance_type
|
str
|
Type of covariance ('full', 'tied', 'diag', 'spherical') |
'full'
|
max_iter
|
int
|
Maximum EM iterations |
100
|
Source code in src/distributions/mixtures.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
aic(data)
¶
Calculate Akaike Information Criterion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data |
required |
Returns:
| Type | Description |
|---|---|
float
|
AIC value |
Source code in src/distributions/mixtures.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
bic(data)
¶
Calculate Bayesian Information Criterion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data |
required |
Returns:
| Type | Description |
|---|---|
float
|
BIC value |
Source code in src/distributions/mixtures.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
fit(data)
¶
Fit GMM to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Training data (n x d) |
required |
Returns:
| Type | Description |
|---|---|
GaussianMixtureModel
|
Self |
Source code in src/distributions/mixtures.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
get_parameters()
¶
Get fitted parameters.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with means, covariances, and weights |
Source code in src/distributions/mixtures.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
pdf(data)
¶
Calculate probability density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data points |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
PDF values |
Source code in src/distributions/mixtures.py
306 307 308 309 310 311 312 313 314 315 316 317 | |
predict(data)
¶
Predict component labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data to predict |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Component labels |
Source code in src/distributions/mixtures.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
rvs(size=1)
¶
Generate random samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Samples |
Source code in src/distributions/mixtures.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
score_samples(data)
¶
Calculate log-likelihood of samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Data to score |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Log-likelihood values |
Source code in src/distributions/mixtures.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
MixtureDistribution
¶
General mixture distribution.
Source code in src/distributions/mixtures.py
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 170 171 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 | |
__init__(components, weights)
¶
Initialize mixture distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
list
|
List of component distributions |
required |
weights
|
list[float] | ndarray
|
Mixing weights (must sum to 1) |
required |
Source code in src/distributions/mixtures.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
cdf(x)
¶
Calculate cumulative distribution function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input values |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
CDF values |
Source code in src/distributions/mixtures.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
fit_em(data, n_components, max_iter=100, tol=0.0001, random_state=None)
¶
Fit mixture model using Expectation-Maximization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Observed data |
required |
n_components
|
int
|
Number of mixture components |
required |
max_iter
|
int
|
Maximum EM iterations |
100
|
tol
|
float
|
Convergence tolerance |
0.0001
|
random_state
|
int | None
|
Seed for the random component initialization.
Pass an int for reproducible fits; |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, list, list[float]]
|
Tuple of (responsibilities, components, weights) |
Source code in src/distributions/mixtures.py
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 170 171 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 | |
mean()
¶
Calculate mean of mixture.
Returns:
| Type | Description |
|---|---|
float
|
Mean value |
Source code in src/distributions/mixtures.py
108 109 110 111 112 113 114 115 116 117 118 119 | |
pdf(x)
¶
Calculate probability density function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input values |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
PDF values |
Source code in src/distributions/mixtures.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
rvs(size=1, random_state=None)
¶
Generate random samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples |
1
|
random_state
|
int | None
|
Random seed |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Random samples |
Source code in src/distributions/mixtures.py
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 | |
var()
¶
Calculate variance of mixture.
Returns:
| Type | Description |
|---|---|
float
|
Variance value |
Source code in src/distributions/mixtures.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
select_optimal_components(data, max_components=10)
¶
Select optimal number of components using BIC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Training data |
required |
max_components
|
int
|
Maximum components to try |
10
|
Returns:
| Type | Description |
|---|---|
tuple[int, dict]
|
Tuple of (optimal_n_components, results_dict) |
Source code in src/distributions/mixtures.py
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 | |
src.fitting.distribution_fitter
¶
Distribution fitting to empirical data.
BayesianEstimator
¶
Bayesian parameter estimation.
Source code in src/fitting/distribution_fitter.py
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 333 334 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 | |
__init__(data)
¶
Initialize Bayesian estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Observed data |
required |
Source code in src/fitting/distribution_fitter.py
287 288 289 290 291 292 293 294 295 | |
estimate_bernoulli_p(prior_alpha, prior_beta)
¶
Bayesian estimation of Bernoulli success probability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior_alpha
|
float
|
Prior alpha (Beta) |
required |
prior_beta
|
float
|
Prior beta (Beta) |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (posterior_alpha, posterior_beta) |
Source code in src/fitting/distribution_fitter.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
estimate_normal_mean(prior_mean, prior_var, known_variance)
¶
Bayesian estimation of normal mean with known variance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior_mean
|
float
|
Prior mean |
required |
prior_var
|
float
|
Prior variance |
required |
known_variance
|
float
|
Known data variance |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (posterior_mean, posterior_variance) |
Source code in src/fitting/distribution_fitter.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
estimate_normal_variance(prior_shape, prior_scale, known_mean)
¶
Bayesian estimation of normal variance with known mean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior_shape
|
float
|
Prior shape (Inverse-Gamma) |
required |
prior_scale
|
float
|
Prior scale (Inverse-Gamma) |
required |
known_mean
|
float
|
Known mean |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (posterior_shape, posterior_scale) |
Source code in src/fitting/distribution_fitter.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
estimate_poisson_rate(prior_shape, prior_rate)
¶
Bayesian estimation of Poisson rate parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior_shape
|
float
|
Prior shape (Gamma) |
required |
prior_rate
|
float
|
Prior rate (Gamma) |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (posterior_shape, posterior_rate) |
Source code in src/fitting/distribution_fitter.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
DistributionFitter
¶
Fit probability distributions to empirical data.
Source code in src/fitting/distribution_fitter.py
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 170 171 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 | |
__init__(data)
¶
Initialize distribution fitter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Empirical data to fit |
required |
Source code in src/fitting/distribution_fitter.py
17 18 19 20 21 22 23 24 25 26 27 28 | |
calculate_residuals(dist_name, params)
¶
Calculate standardized residuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist_name
|
str
|
Distribution name |
required |
params
|
tuple
|
Distribution parameters |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Standardized residuals |
Source code in src/fitting/distribution_fitter.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
fit_all(distributions=None)
¶
Fit multiple distributions and rank by goodness of fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distributions
|
list[str] | None
|
List of distribution names to try. If None, tries all supported distributions. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
Dictionary of results sorted by fit quality (AIC) |
Source code in src/fitting/distribution_fitter.py
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 | |
fit_beta()
¶
Fit beta distribution (data must be in [0, 1]).
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (alpha, beta) |
Source code in src/fitting/distribution_fitter.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
fit_distribution(dist_name)
¶
Fit a specific distribution using Maximum Likelihood Estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist_name
|
str
|
Name of scipy.stats distribution |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with fit results |
Source code in src/fitting/distribution_fitter.py
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 | |
fit_exponential()
¶
Fit exponential distribution using MLE.
Returns:
| Type | Description |
|---|---|
float
|
Lambda parameter |
Source code in src/fitting/distribution_fitter.py
153 154 155 156 157 158 159 160 161 | |
fit_gamma_mle()
¶
Fit gamma distribution using Maximum Likelihood Estimation.
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (shape, scale) |
Source code in src/fitting/distribution_fitter.py
163 164 165 166 167 168 169 170 171 172 | |
fit_gamma_mom()
¶
Fit gamma distribution using Method of Moments.
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (shape, scale) |
Source code in src/fitting/distribution_fitter.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
fit_lognormal()
¶
Fit lognormal distribution.
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (mu, sigma) of underlying normal |
Source code in src/fitting/distribution_fitter.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
fit_normal()
¶
Fit normal distribution using MLE.
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (mu, sigma) |
Source code in src/fitting/distribution_fitter.py
142 143 144 145 146 147 148 149 150 151 | |
fit_weibull()
¶
Fit Weibull distribution using MLE.
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (shape, scale) |
Source code in src/fitting/distribution_fitter.py
212 213 214 215 216 217 218 219 220 | |
qq_plot_data(dist_name, params)
¶
Generate data for Q-Q plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist_name
|
str
|
Distribution name |
required |
params
|
tuple
|
Distribution parameters |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
Tuple of (theoretical_quantiles, sample_quantiles) |
Source code in src/fitting/distribution_fitter.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
GoodnessOfFit
¶
Goodness of fit tests.
Source code in src/fitting/distribution_fitter.py
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 | |
anderson_darling_test(data, dist='norm')
staticmethod
¶
Anderson-Darling test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Sample data |
required |
dist
|
str
|
Distribution name ('norm', 'expon', 'logistic', 'gumbel', 'extreme1') |
'norm'
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with test results |
Source code in src/fitting/distribution_fitter.py
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 | |
chi_square_test(observed, expected, df=None)
staticmethod
¶
Chi-square goodness of fit test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed
|
ndarray
|
Observed frequencies |
required |
expected
|
ndarray
|
Expected frequencies |
required |
df
|
int | None
|
Degrees of freedom (if None, calculated automatically) |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (chi2_statistic, p_value) |
Source code in src/fitting/distribution_fitter.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
jarque_bera_test(data)
staticmethod
¶
Jarque-Bera test for normality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Sample data |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (jb_statistic, p_value) |
Source code in src/fitting/distribution_fitter.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
kolmogorov_smirnov_test(data, cdf_function)
staticmethod
¶
Kolmogorov-Smirnov test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Sample data |
required |
cdf_function
|
Callable[..., Any]
|
Theoretical CDF function |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (ks_statistic, p_value) |
Source code in src/fitting/distribution_fitter.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
shapiro_wilk_test(data)
staticmethod
¶
Shapiro-Wilk test for normality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Sample data |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (w_statistic, p_value) |
Source code in src/fitting/distribution_fitter.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
src.monte_carlo.simulator
¶
Monte Carlo simulation engine for complex probability calculations.
MonteCarloSimulator
¶
Advanced Monte Carlo simulation engine.
Source code in src/monte_carlo/simulator.py
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 170 171 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 333 334 335 336 337 338 339 340 341 342 343 | |
__init__(random_seed=None)
¶
Initialize Monte Carlo simulator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_seed
|
int | None
|
Random seed for reproducibility |
None
|
Source code in src/monte_carlo/simulator.py
32 33 34 35 36 37 38 39 40 | |
bootstrap(data, statistic, num_bootstrap=10000, confidence_level=0.95)
¶
Bootstrap resampling for estimating sampling distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Original data |
required |
statistic
|
Callable
|
Function to compute statistic (takes data, returns scalar) |
required |
num_bootstrap
|
int
|
Number of bootstrap samples |
10000
|
confidence_level
|
float
|
Confidence level for interval |
0.95
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with bootstrap results |
Source code in src/monte_carlo/simulator.py
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 | |
estimate_expectation(random_var_func, num_samples=10000)
¶
Estimate expectation using Monte Carlo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_var_func
|
Callable
|
Function that generates random variable values |
required |
num_samples
|
int
|
Number of Monte Carlo samples |
10000
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (expectation_estimate, standard_error) |
Source code in src/monte_carlo/simulator.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
estimate_probability(event_func, num_samples=100000, confidence_level=0.95)
¶
Estimate probability of an event using Monte Carlo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_func
|
Callable
|
Function that returns True/False for event occurrence |
required |
num_samples
|
int
|
Number of Monte Carlo samples |
100000
|
confidence_level
|
float
|
Confidence level for interval |
0.95
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with probability estimate and confidence interval |
Source code in src/monte_carlo/simulator.py
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 | |
importance_sampling(target_func, proposal_sampler, proposal_pdf, target_pdf, num_samples=10000)
¶
Importance sampling for rare event estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_func
|
Callable
|
Function to compute on target distribution |
required |
proposal_sampler
|
Callable
|
Function to sample from proposal distribution |
required |
proposal_pdf
|
Callable
|
PDF of proposal distribution |
required |
target_pdf
|
Callable
|
PDF of target distribution |
required |
num_samples
|
int
|
Number of samples |
10000
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (estimate, standard_error) |
Source code in src/monte_carlo/simulator.py
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 | |
permutation_test(group1, group2, test_statistic, num_permutations=10000)
¶
Permutation test for hypothesis testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group1
|
ndarray
|
First group data |
required |
group2
|
ndarray
|
Second group data |
required |
test_statistic
|
Callable
|
Function that computes test statistic from (group1, group2) |
required |
num_permutations
|
int
|
Number of permutations |
10000
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with test results |
Source code in src/monte_carlo/simulator.py
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 333 334 335 336 337 338 339 340 341 342 343 | |
simulate(func, num_samples=10000, track_convergence=False, confidence_level=0.95, **kwargs)
¶
Run Monte Carlo simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Function that generates one sample |
required |
num_samples
|
int
|
Number of Monte Carlo samples |
10000
|
track_convergence
|
bool
|
Whether to track convergence |
False
|
confidence_level
|
float
|
Confidence level for interval |
0.95
|
**kwargs
|
Any
|
Additional arguments passed to func |
{}
|
Returns:
| Type | Description |
|---|---|
SimulationResult
|
SimulationResult object |
Source code in src/monte_carlo/simulator.py
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 | |
stratified_sampling(func, strata_bounds, num_samples_per_stratum=1000)
¶
Stratified sampling for variance reduction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Function to evaluate |
required |
strata_bounds
|
list[tuple[float, float]]
|
List of (lower, upper) bounds for each stratum |
required |
num_samples_per_stratum
|
int
|
Samples per stratum |
1000
|
Returns:
| Type | Description |
|---|---|
SimulationResult
|
SimulationResult object |
Source code in src/monte_carlo/simulator.py
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 | |
QuasiMonteCarloSimulator
¶
Quasi-Monte Carlo using low-discrepancy sequences.
Source code in src/monte_carlo/simulator.py
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 | |
halton_sequence(n, base=2)
staticmethod
¶
Generate Halton sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of points |
required |
base
|
int
|
Base for sequence |
2
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of Halton sequence values |
Source code in src/monte_carlo/simulator.py
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 | |
integrate_qmc(func, bounds, num_points=10000)
¶
Quasi-Monte Carlo integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Function to integrate |
required |
bounds
|
list[tuple[float, float]]
|
Integration bounds for each dimension |
required |
num_points
|
int
|
Number of QMC points |
10000
|
Returns:
| Type | Description |
|---|---|
float
|
Integral estimate |
Source code in src/monte_carlo/simulator.py
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 | |
sobol_sequence(n, dim=1)
staticmethod
¶
Generate Sobol sequence (requires scipy >= 1.7.0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of points |
required |
dim
|
int
|
Dimension |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of shape (n, dim) |
Source code in src/monte_carlo/simulator.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
SimulationResult
dataclass
¶
Results from Monte Carlo simulation.
Source code in src/monte_carlo/simulator.py
15 16 17 18 19 20 21 22 23 24 25 26 | |
VarianceReduction
¶
Variance reduction techniques.
Source code in src/monte_carlo/simulator.py
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 | |
antithetic_variates(sampler, func, num_pairs=5000)
staticmethod
¶
Antithetic variates for variance reduction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampler
|
Callable
|
Function that generates uniform(0,1) samples |
required |
func
|
Callable
|
Function to evaluate |
required |
num_pairs
|
int
|
Number of antithetic pairs |
5000
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (estimate, standard_error) |
Source code in src/monte_carlo/simulator.py
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 | |
control_variates(target_sampler, target_func, control_func, control_mean, num_samples=10000)
staticmethod
¶
Control variates for variance reduction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_sampler
|
Callable
|
Function to generate samples |
required |
target_func
|
Callable
|
Function to evaluate (unknown expectation) |
required |
control_func
|
Callable
|
Control function (known expectation) |
required |
control_mean
|
float
|
Known expectation of control function |
required |
num_samples
|
int
|
Number of samples |
10000
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (estimate, standard_error) |
Source code in src/monte_carlo/simulator.py
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 | |
src.statistical_tests
¶
Statistical tests and hypothesis testing utilities.
Note: This module is named 'statistical_tests' to avoid collision with Python's built-in 'statistics' module.
anova(*samples, alpha=0.05)
¶
Perform one-way ANOVA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*samples
|
ndarray
|
Variable number of sample groups |
()
|
alpha
|
float
|
Significance level |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, float | bool]
|
Dictionary with test results |
Source code in src/statistical_tests/hypothesis_tests.py
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 | |
chi_square_test(observed, expected=None, alpha=0.05)
¶
Perform chi-square goodness-of-fit test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed
|
ndarray
|
Observed frequencies |
required |
expected
|
ndarray | None
|
Expected frequencies (uniform if None) |
None
|
alpha
|
float
|
Significance level |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, float | bool | int]
|
Dictionary with test results |
Source code in src/statistical_tests/hypothesis_tests.py
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 | |
correlation_matrix(data, method='pearson', return_pvalues=False)
¶
Compute correlation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
2D array where each column is a variable |
required |
method
|
str
|
'pearson', 'spearman', or 'kendall' |
'pearson'
|
return_pvalues
|
bool
|
Whether to return p-values |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Dictionary with correlation matrix and optionally p-values |
Source code in src/statistical_tests/descriptive.py
167 168 169 170 171 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 | |
correlation_test(x, y, method='pearson', alpha=0.05)
¶
Test for correlation between two variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
First variable |
required |
y
|
ndarray
|
Second variable |
required |
method
|
str
|
'pearson', 'spearman', or 'kendall' |
'pearson'
|
alpha
|
float
|
Significance level |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, float | bool | str]
|
Dictionary with test results |
Source code in src/statistical_tests/hypothesis_tests.py
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 | |
describe(data, percentiles=None)
¶
Comprehensive descriptive statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data |
required |
percentiles
|
list[float] | None
|
List of percentiles to compute (default: [25, 50, 75]) |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with descriptive statistics |
Source code in src/statistical_tests/descriptive.py
7 8 9 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 | |
friedman_test(*samples, alpha=0.05)
¶
Friedman test (nonparametric alternative to repeated measures ANOVA).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*samples
|
ndarray
|
Variable number of sample groups (must have same length) |
()
|
alpha
|
float
|
Significance level |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, float | bool | int]
|
Dictionary with test results |
Source code in src/statistical_tests/nonparametric.py
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 | |
kruskal_wallis(*samples, alpha=0.05)
¶
Kruskal-Wallis H test (nonparametric alternative to one-way ANOVA).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*samples
|
ndarray
|
Variable number of sample groups |
()
|
alpha
|
float
|
Significance level |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, float | bool | int]
|
Dictionary with test results |
Source code in src/statistical_tests/nonparametric.py
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 | |
mann_whitney_u(sample1, sample2, alternative='two-sided', alpha=0.05)
¶
Mann-Whitney U test (nonparametric alternative to two-sample t-test).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample1
|
ndarray
|
First sample |
required |
sample2
|
ndarray
|
Second sample |
required |
alternative
|
str
|
'two-sided', 'less', or 'greater' |
'two-sided'
|
alpha
|
float
|
Significance level |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, float | bool | str]
|
Dictionary with test results |
Source code in src/statistical_tests/nonparametric.py
7 8 9 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 | |
normality_tests(data, alpha=0.05)
¶
Run multiple normality tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Sample data |
required |
alpha
|
float
|
Significance level |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, float | bool]]
|
Dictionary with results from multiple tests |
Source code in src/statistical_tests/hypothesis_tests.py
166 167 168 169 170 171 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 | |
outlier_detection(data, method='iqr', threshold=1.5)
¶
Detect outliers using various methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data |
required |
method
|
str
|
'iqr', 'zscore', or 'mad' |
'iqr'
|
threshold
|
float
|
Threshold for outlier detection - IQR: typically 1.5 or 3.0 - Z-score: typically 2.5 or 3.0 - MAD: typically 2.5 or 3.0 |
1.5
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Dictionary with outlier information |
Source code in src/statistical_tests/descriptive.py
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 | |
quantile_summary(data, n_quantiles=4)
¶
Compute quantile summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data |
required |
n_quantiles
|
int
|
Number of quantiles (4 for quartiles, 10 for deciles, etc.) |
4
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Dictionary with quantile information |
Source code in src/statistical_tests/descriptive.py
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 | |
t_test(sample1, sample2=None, mu=0, alternative='two-sided', alpha=0.05)
¶
Perform t-test (one-sample or two-sample).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample1
|
ndarray
|
First sample data |
required |
sample2
|
ndarray | None
|
Second sample data (None for one-sample test) |
None
|
mu
|
float
|
Hypothesized mean (for one-sample test) |
0
|
alternative
|
str
|
'two-sided', 'less', or 'greater' |
'two-sided'
|
alpha
|
float
|
Significance level |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, float | bool | str]
|
Dictionary with test results |
Source code in src/statistical_tests/hypothesis_tests.py
9 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 | |
wilcoxon_signed_rank(sample1, sample2=None, alternative='two-sided', alpha=0.05)
¶
Wilcoxon signed-rank test (nonparametric paired test).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample1
|
ndarray
|
First sample or differences |
required |
sample2
|
ndarray | None
|
Second sample (None if sample1 contains differences) |
None
|
alternative
|
str
|
'two-sided', 'less', or 'greater' |
'two-sided'
|
alpha
|
float
|
Significance level |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, float | bool | str]
|
Dictionary with test results |
Source code in src/statistical_tests/nonparametric.py
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 | |
src.utils.validation
¶
Input validation utilities.
validate_array(array, shape=None, ndim=None, dtype=None, min_length=None, name='array')
¶
Validate array properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Array to validate |
required |
shape
|
tuple | None
|
Expected shape (None to skip check) |
None
|
ndim
|
int | None
|
Expected number of dimensions (None to skip check) |
None
|
dtype
|
type | None
|
Expected data type (None to skip check) |
None
|
min_length
|
int | None
|
Minimum length for first dimension (None to skip check) |
None
|
name
|
str
|
Name of parameter for error messages |
'array'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Validated array |
Raises:
| Type | Description |
|---|---|
ValueError
|
If array does not meet requirements |
Source code in src/utils/validation.py
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 | |
validate_correlation_matrix(corr, name='correlation')
¶
Validate that matrix is a valid correlation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corr
|
ndarray
|
Correlation matrix |
required |
name
|
str
|
Name of parameter for error messages |
'correlation'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Validated correlation matrix |
Raises:
| Type | Description |
|---|---|
ValueError
|
If matrix is not valid correlation |
Source code in src/utils/validation.py
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 | |
validate_covariance_matrix(cov, name='covariance')
¶
Validate that matrix is a valid covariance matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cov
|
ndarray
|
Covariance matrix |
required |
name
|
str
|
Name of parameter for error messages |
'covariance'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Validated covariance matrix |
Raises:
| Type | Description |
|---|---|
ValueError
|
If matrix is not valid covariance |
Source code in src/utils/validation.py
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 | |
validate_in_range(value, lower, upper, name='value', inclusive='both')
¶
Validate that value(s) are in specified range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float | ndarray
|
Value(s) to validate |
required |
lower
|
float
|
Lower bound |
required |
upper
|
float
|
Upper bound |
required |
name
|
str
|
Name of parameter for error messages |
'value'
|
inclusive
|
str
|
'both', 'lower', 'upper', or 'neither' |
'both'
|
Returns:
| Type | Description |
|---|---|
float | ndarray
|
Validated value |
Raises:
| Type | Description |
|---|---|
ValueError
|
If value is not in range |
Source code in src/utils/validation.py
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 | |
validate_integer(value, name='value')
¶
Validate that value is an integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int | float
|
Value to validate |
required |
name
|
str
|
Name of parameter for error messages |
'value'
|
Returns:
| Type | Description |
|---|---|
int
|
Validated integer |
Raises:
| Type | Description |
|---|---|
ValueError
|
If value is not an integer |
Source code in src/utils/validation.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
validate_nonnegative(value, name='value')
¶
Validate that value(s) are non-negative (>= 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float | ndarray
|
Value(s) to validate |
required |
name
|
str
|
Name of parameter for error messages |
'value'
|
Returns:
| Type | Description |
|---|---|
float | ndarray
|
Validated value |
Raises:
| Type | Description |
|---|---|
ValueError
|
If value is negative |
Source code in src/utils/validation.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
validate_positive(value, name='value')
¶
Validate that value(s) are strictly positive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float | ndarray
|
Value(s) to validate |
required |
name
|
str
|
Name of parameter for error messages |
'value'
|
Returns:
| Type | Description |
|---|---|
float | ndarray
|
Validated value |
Raises:
| Type | Description |
|---|---|
ValueError
|
If value is not positive |
Source code in src/utils/validation.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
validate_probability(p, name='probability')
¶
Validate that value(s) are valid probabilities in [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float | ndarray
|
Probability value(s) |
required |
name
|
str
|
Name of parameter for error messages |
'probability'
|
Returns:
| Type | Description |
|---|---|
float | ndarray
|
Validated probability |
Raises:
| Type | Description |
|---|---|
ValueError
|
If probability is not in [0, 1] |
Source code in src/utils/validation.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
src.utils.data_preprocessing
¶
Data preprocessing utilities.
bin_data(data, n_bins=None, bins=None, method='equal_width', return_bins=False)
¶
Bin continuous data into discrete bins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data |
required |
n_bins
|
int | None
|
Number of bins (if bins not provided) |
None
|
bins
|
ndarray | None
|
Explicit bin edges |
None
|
method
|
str
|
'equal_width', 'equal_frequency', or 'custom' |
'equal_width'
|
return_bins
|
bool
|
Whether to return bin edges |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | tuple[ndarray, ndarray]
|
Bin indices for each data point, optionally with bin edges |
Source code in src/utils/data_preprocessing.py
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 | |
box_cox_transform(data, lambda_param=None)
¶
Apply Box-Cox power transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data (must be positive) |
required |
lambda_param
|
float | None
|
Transformation parameter (estimated if None) |
None
|
Returns:
| Type | Description |
|---|---|
ndarray | tuple[ndarray, float]
|
Transformed data and lambda parameter (if estimated) |
Source code in src/utils/data_preprocessing.py
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 | |
handle_missing(data, method='mean', fill_value=None)
¶
Handle missing values (NaN) in data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data with potential NaN values |
required |
method
|
str
|
'mean', 'median', 'mode', 'forward_fill', 'backward_fill', or 'constant' |
'mean'
|
fill_value
|
float | None
|
Value to use for 'constant' method |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Data with missing values filled |
Source code in src/utils/data_preprocessing.py
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
log_transform(data, shift=0.0, base='e')
¶
Apply logarithmic transformation to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data |
required |
shift
|
float
|
Value to add before taking log (for handling zeros/negatives) |
0.0
|
base
|
str
|
'e', '10', or '2' |
'e'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Log-transformed data |
Source code in src/utils/data_preprocessing.py
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 | |
normalize(data, method='minmax', feature_range=(0, 1), return_params=False)
¶
Normalize data to specified range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data |
required |
method
|
str
|
'minmax' or 'maxabs' |
'minmax'
|
feature_range
|
tuple[float, float]
|
Target range (min, max) |
(0, 1)
|
return_params
|
bool
|
Whether to return normalization parameters |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | tuple[ndarray, dict]
|
Normalized data, optionally with parameters |
Source code in src/utils/data_preprocessing.py
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 | |
remove_outliers(data, method='iqr', threshold=1.5, return_mask=False)
¶
Remove outliers from data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data |
required |
method
|
str
|
'iqr', 'zscore', or 'mad' |
'iqr'
|
threshold
|
float
|
Threshold for outlier detection |
1.5
|
return_mask
|
bool
|
Whether to return boolean mask of inliers |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | tuple[ndarray, ndarray]
|
Data with outliers removed, optionally with inlier mask |
Source code in src/utils/data_preprocessing.py
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 | |
standardize(data, return_params=False)
¶
Standardize data to zero mean and unit variance (Z-score normalization).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data |
required |
return_params
|
bool
|
Whether to return standardization parameters |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | tuple[ndarray, dict]
|
Standardized data, optionally with parameters (mean, std) |
Source code in src/utils/data_preprocessing.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
src.utils.plotting
¶
Plotting utilities for probability distributions.
plot_correlation_heatmap(data, labels=None, method='pearson', figsize=(10, 8), annot=True, cmap='coolwarm')
¶
Create correlation matrix heatmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
2D array where each column is a variable |
required |
labels
|
list[str] | None
|
Variable names |
None
|
method
|
str
|
'pearson', 'spearman', or 'kendall' |
'pearson'
|
figsize
|
tuple[float, float]
|
Figure size |
(10, 8)
|
annot
|
bool
|
Whether to annotate cells with values |
True
|
cmap
|
str
|
Colormap name |
'coolwarm'
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
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 | |
plot_distribution_comparison(data, distributions, fitted_params=None, bins=30, figsize=(12, 6))
¶
Compare empirical data with fitted distributions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Empirical data |
required |
distributions
|
list[str]
|
List of distribution names |
required |
fitted_params
|
dict | None
|
Dictionary of fitted parameters for each distribution |
None
|
bins
|
int
|
Number of histogram bins |
30
|
figsize
|
tuple[float, float]
|
Figure size |
(12, 6)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
8 9 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 | |
plot_histogram_with_fit(data, dist='norm', params=None, bins=30, figsize=(10, 6))
¶
Plot histogram with fitted distribution overlay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Empirical data |
required |
dist
|
str
|
Distribution name |
'norm'
|
params
|
tuple | None
|
Distribution parameters (fitted if None) |
None
|
bins
|
int
|
Number of histogram bins |
30
|
figsize
|
tuple[float, float]
|
Figure size |
(10, 6)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
plot_probability_bands(data, dist='norm', params=None, confidence_levels=None, figsize=(12, 6))
¶
Plot data with probability bands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Time series or sequential data |
required |
dist
|
str
|
Distribution name |
'norm'
|
params
|
tuple | None
|
Distribution parameters |
None
|
confidence_levels
|
list[float] | None
|
List of confidence levels |
None
|
figsize
|
tuple[float, float]
|
Figure size |
(12, 6)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
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 333 334 335 336 337 338 339 340 341 | |
plot_qq(data, dist='norm', params=None, figsize=(8, 8))
¶
Create Q-Q plot for distribution fit assessment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Empirical data |
required |
dist
|
str
|
Distribution name |
'norm'
|
params
|
tuple | None
|
Distribution parameters (fitted if None) |
None
|
figsize
|
tuple[float, float]
|
Figure size |
(8, 8)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
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 | |
src.utils.logger
¶
Structured logging infrastructure with JSON and console output.
get_correlation_id()
¶
Get the current correlation ID.
Source code in src/utils/logger.py
108 109 110 | |
get_logger(name)
¶
Get or create a logger with the default console configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logger name (typically name). |
required |
Returns:
| Type | Description |
|---|---|
Logger
|
Logger instance (created with default setup if not yet initialized). |
Source code in src/utils/logger.py
154 155 156 157 158 159 160 161 162 163 164 165 166 | |
log_error(logger, message, exc=None, extra=None)
¶
Log an error with full exception context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger instance to use. |
required |
message
|
str
|
Human-readable error message. |
required |
exc
|
Exception | None
|
Exception instance (if available, to attach traceback). |
None
|
extra
|
dict[str, Any] | None
|
Optional additional context data. |
None
|
Source code in src/utils/logger.py
169 170 171 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 | |
log_execution_time(logger=None)
¶
Decorator to log function execution time.
Usage
@log_execution_time(logger) def my_function(): ...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger | None
|
Logger instance to use. If None, logger for the module is used. |
None
|
Source code in src/utils/logger.py
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 | |
set_correlation_id(correlation_id=None)
¶
Set or generate a correlation ID for request tracking.
Source code in src/utils/logger.py
101 102 103 104 105 | |
setup_logger(name='root', level=logging.INFO, structured=False)
¶
Set up a logger with the specified configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logger name (use name for module-level loggers). |
'root'
|
level
|
int
|
Logging level (DEBUG, INFO, WARNING, ERROR). |
INFO
|
structured
|
bool
|
If True, emit JSON lines; otherwise pretty console output. |
False
|
Returns:
| Type | Description |
|---|---|
Logger
|
Configured logger instance. |
Source code in src/utils/logger.py
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 | |
src.visualizers
¶
Visualization helpers for probability distributions.
This package provides the public visualization API. The heavy lifting lives in
:mod:src.utils.plotting; the functions here add distribution-aware wrappers so
both src.visualizers and src.utils.plotting import paths work.
plot_cdf(distribution, x=None, num_points=500, ax=None)
¶
Plot the CDF of a distribution (see :func:plot_pdf for args).
Source code in src/visualizers/__init__.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
plot_comparison(distributions, x=None, num_points=500)
¶
Overlay the PDFs/PMFs of several distributions on shared axes.
Source code in src/visualizers/__init__.py
113 114 115 116 117 118 119 120 121 122 | |
plot_correlation_heatmap(data, labels=None, method='pearson', figsize=(10, 8), annot=True, cmap='coolwarm')
¶
Create correlation matrix heatmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
2D array where each column is a variable |
required |
labels
|
list[str] | None
|
Variable names |
None
|
method
|
str
|
'pearson', 'spearman', or 'kendall' |
'pearson'
|
figsize
|
tuple[float, float]
|
Figure size |
(10, 8)
|
annot
|
bool
|
Whether to annotate cells with values |
True
|
cmap
|
str
|
Colormap name |
'coolwarm'
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
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 | |
plot_distribution_comparison(data, distributions, fitted_params=None, bins=30, figsize=(12, 6))
¶
Compare empirical data with fitted distributions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Empirical data |
required |
distributions
|
list[str]
|
List of distribution names |
required |
fitted_params
|
dict | None
|
Dictionary of fitted parameters for each distribution |
None
|
bins
|
int
|
Number of histogram bins |
30
|
figsize
|
tuple[float, float]
|
Figure size |
(12, 6)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
8 9 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 | |
plot_histogram_with_fit(data, dist='norm', params=None, bins=30, figsize=(10, 6))
¶
Plot histogram with fitted distribution overlay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Empirical data |
required |
dist
|
str
|
Distribution name |
'norm'
|
params
|
tuple | None
|
Distribution parameters (fitted if None) |
None
|
bins
|
int
|
Number of histogram bins |
30
|
figsize
|
tuple[float, float]
|
Figure size |
(10, 6)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
plot_pdf(distribution, x=None, num_points=500, ax=None)
¶
Plot the PDF/PMF of a distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distribution
|
Any
|
Any object exposing |
required |
x
|
ndarray | None
|
Evaluation points. If None, inferred from the distribution support. |
None
|
num_points
|
int
|
Points to use when inferring the grid. |
500
|
ax
|
Axes | None
|
Optional matplotlib axes to draw on. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
Tuple of (figure, axes). |
Source code in src/visualizers/__init__.py
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 | |
plot_probability_bands(data, dist='norm', params=None, confidence_levels=None, figsize=(12, 6))
¶
Plot data with probability bands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Time series or sequential data |
required |
dist
|
str
|
Distribution name |
'norm'
|
params
|
tuple | None
|
Distribution parameters |
None
|
confidence_levels
|
list[float] | None
|
List of confidence levels |
None
|
figsize
|
tuple[float, float]
|
Figure size |
(12, 6)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
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 333 334 335 336 337 338 339 340 341 | |
plot_qq(data, dist='norm', params=None, figsize=(8, 8))
¶
Create Q-Q plot for distribution fit assessment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Empirical data |
required |
dist
|
str
|
Distribution name |
'norm'
|
params
|
tuple | None
|
Distribution parameters (fitted if None) |
None
|
figsize
|
tuple[float, float]
|
Figure size |
(8, 8)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Matplotlib figure |
Source code in src/utils/plotting.py
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 | |
src.cli
¶
Command-line interface for the Probability Distribution Visualizer.