Skip to main content

stats_claw/distributions/
types.rs

1//! Plain-data parameter structs for the supported probability distributions.
2//!
3//! Each struct carries only the parameters (and two descriptive string fields)
4//! that identify a distribution; all numerics live in the behaviour traits
5//! (`Pdf`/`Pmf`/`Cdf`/`Quantile`/`Moments`/`Sample`/`LogCdf`) implemented for
6//! these types in the sibling subgroup modules. The structs derive `Default`
7//! so callers can build them with struct-update syntax and only set the fields
8//! they care about:
9//!
10//! ```
11//! use stats_claw::distributions::NormalDistribution;
12//!
13//! let n = NormalDistribution { mean: 0.0, standard_deviation: 1.0, ..Default::default() };
14//! assert_eq!(n.mean, 0.0);
15//! ```
16//!
17//! The `distribution_name` and `description` fields are optional human-readable
18//! labels; the numerics never read them, so they default to the empty string.
19
20/// Parameters of a Beta distribution on a finite interval.
21///
22/// The Beta family models a random proportion or probability. Its density is
23/// shaped by two positive parameters and supported on `[support_lower_bound,
24/// support_upper_bound]` (the standard Beta uses `[0, 1]`).
25#[derive(Debug, Clone, Default)]
26pub struct BetaDistribution {
27    /// First shape parameter `α`; must be `> 0`. Larger values push mass toward
28    /// the upper bound.
29    pub alpha_parameter: f64,
30    /// Second shape parameter `β`; must be `> 0`. Larger values push mass toward
31    /// the lower bound.
32    pub beta_parameter: f64,
33    /// Inclusive lower bound of the support; `0.0` for the standard Beta.
34    pub support_lower_bound: f64,
35    /// Inclusive upper bound of the support; `1.0` for the standard Beta.
36    pub support_upper_bound: f64,
37    /// Optional human-readable name; unused by the numerics, defaults to empty.
38    pub distribution_name: String,
39    /// Optional human-readable description; unused by the numerics, defaults to empty.
40    pub description: String,
41}
42
43/// Parameters of a Binomial distribution.
44///
45/// Models the number of successes in `number_of_trials` independent Bernoulli
46/// trials, each succeeding with probability `success_probability`.
47#[derive(Debug, Clone, Default)]
48pub struct BinomialDistribution {
49    /// Number of independent trials `n`; must be `≥ 0`.
50    pub number_of_trials: i64,
51    /// Per-trial success probability `p`; must lie in `[0, 1]`.
52    pub success_probability: f64,
53    /// Optional human-readable name; unused by the numerics, defaults to empty.
54    pub distribution_name: String,
55    /// Optional human-readable description; unused by the numerics, defaults to empty.
56    pub description: String,
57}
58
59/// Parameters of a Cauchy distribution.
60///
61/// A heavy-tailed, symmetric distribution with undefined mean and variance,
62/// centred at `location` with half-width-at-half-maximum `scale`.
63#[derive(Debug, Clone, Default)]
64pub struct CauchyDistribution {
65    /// Location parameter `x₀`; the median and mode of the distribution.
66    pub location: f64,
67    /// Scale parameter `γ`; must be `> 0`. The half-width at half-maximum.
68    pub scale: f64,
69    /// Optional human-readable name; unused by the numerics, defaults to empty.
70    pub distribution_name: String,
71    /// Optional human-readable description; unused by the numerics, defaults to empty.
72    pub description: String,
73}
74
75/// Parameters of a chi-squared distribution.
76///
77/// The distribution of a sum of `degrees_of_freedom` squared standard normals;
78/// the reference distribution for variance and goodness-of-fit tests.
79#[derive(Debug, Clone, Default)]
80pub struct ChiSquaredDistribution {
81    /// Degrees of freedom `k`; must be `≥ 1`.
82    pub degrees_of_freedom: i64,
83    /// Optional human-readable name; unused by the numerics, defaults to empty.
84    pub distribution_name: String,
85    /// Optional human-readable description; unused by the numerics, defaults to empty.
86    pub description: String,
87}
88
89/// Parameters of an Exponential distribution.
90///
91/// Models the waiting time between events in a Poisson process; supported on
92/// `[0, ∞)` and parameterised by its rate.
93#[derive(Debug, Clone, Default)]
94pub struct ExponentialDistribution {
95    /// Rate parameter `λ`; must be `> 0`. The mean is `1/λ`.
96    pub rate_parameter: f64,
97    /// Optional human-readable name; unused by the numerics, defaults to empty.
98    pub distribution_name: String,
99    /// Optional human-readable description; unused by the numerics, defaults to empty.
100    pub description: String,
101}
102
103/// Parameters of an F distribution.
104///
105/// The ratio of two independent chi-squared variates each divided by their
106/// degrees of freedom; the reference distribution for ANOVA and variance-ratio
107/// tests.
108#[derive(Debug, Clone, Default)]
109pub struct FDistribution {
110    /// Numerator degrees of freedom `d₁`; must be `≥ 1`.
111    pub numerator_df: i64,
112    /// Denominator degrees of freedom `d₂`; must be `≥ 1`.
113    pub denominator_df: i64,
114    /// Optional human-readable name; unused by the numerics, defaults to empty.
115    pub distribution_name: String,
116    /// Optional human-readable description; unused by the numerics, defaults to empty.
117    pub description: String,
118}
119
120/// Parameters of a Gamma distribution.
121///
122/// A flexible positive-support family generalising the exponential and
123/// chi-squared distributions, in the shape/scale parameterisation.
124#[derive(Debug, Clone, Default)]
125pub struct GammaDistribution {
126    /// Shape parameter `k`; must be `> 0`.
127    pub shape_parameter: f64,
128    /// Scale parameter `θ`; must be `> 0`. The mean is `k·θ`.
129    pub scale_parameter: f64,
130    /// Optional human-readable name; unused by the numerics, defaults to empty.
131    pub distribution_name: String,
132    /// Optional human-readable description; unused by the numerics, defaults to empty.
133    pub description: String,
134}
135
136/// Parameters of a Laplace (double-exponential) distribution.
137///
138/// A symmetric distribution with a sharp peak at `location` and exponentially
139/// decaying tails governed by `scale`.
140#[derive(Debug, Clone, Default)]
141pub struct LaplaceDistribution {
142    /// Location parameter `μ`; the median, mode, and mean.
143    pub location: f64,
144    /// Scale parameter `b`; must be `> 0`. The variance is `2·b²`.
145    pub scale: f64,
146    /// Optional human-readable name; unused by the numerics, defaults to empty.
147    pub distribution_name: String,
148    /// Optional human-readable description; unused by the numerics, defaults to empty.
149    pub description: String,
150}
151
152/// Parameters of a log-normal distribution.
153///
154/// The distribution of a variable whose natural logarithm is normally
155/// distributed; supported on `(0, ∞)` and parameterised on the log scale.
156#[derive(Debug, Clone, Default)]
157pub struct LogNormalDistribution {
158    /// Mean `μ` of the underlying normal on the log scale.
159    pub mean_log_value: f64,
160    /// Standard deviation `σ` of the underlying normal on the log scale; `> 0`.
161    pub std_log_value: f64,
162    /// Optional human-readable name; unused by the numerics, defaults to empty.
163    pub distribution_name: String,
164    /// Optional human-readable description; unused by the numerics, defaults to empty.
165    pub description: String,
166}
167
168/// Parameters of a Normal (Gaussian) distribution.
169///
170/// The canonical bell-curve, fully specified by its `mean` and
171/// `standard_deviation`; `variance` is carried as a convenience field.
172#[derive(Debug, Clone, Default)]
173pub struct NormalDistribution {
174    /// Mean `μ`; the centre of the distribution.
175    pub mean: f64,
176    /// Standard deviation `σ`; must be `> 0`.
177    pub standard_deviation: f64,
178    /// Variance `σ²`; a convenience field, not required by the numerics.
179    pub variance: f64,
180    /// Optional parameterization label; unused by the numerics, defaults to empty.
181    pub parameterization: String,
182    /// Optional human-readable name; unused by the numerics, defaults to empty.
183    pub distribution_name: String,
184    /// Optional human-readable description; unused by the numerics, defaults to empty.
185    pub description: String,
186}
187
188/// Parameters of a Poisson distribution.
189///
190/// Models the count of events occurring in a fixed interval at a constant
191/// average rate; supported on the non-negative integers.
192#[derive(Debug, Clone, Default)]
193pub struct PoissonDistribution {
194    /// Rate parameter `λ`; must be `> 0`. Both the mean and the variance.
195    pub rate_parameter: f64,
196    /// Optional human-readable name; unused by the numerics, defaults to empty.
197    pub distribution_name: String,
198    /// Optional human-readable description; unused by the numerics, defaults to empty.
199    pub description: String,
200}
201
202/// Parameters of a Student's t distribution.
203///
204/// A symmetric, heavier-tailed analogue of the normal used for inference on
205/// means from small samples; converges to the normal as the degrees of freedom
206/// grow.
207#[derive(Debug, Clone, Default)]
208pub struct TDistribution {
209    /// Degrees of freedom `ν`; must be `≥ 1`.
210    pub degrees_of_freedom: i64,
211    /// Optional human-readable name; unused by the numerics, defaults to empty.
212    pub distribution_name: String,
213    /// Optional human-readable description; unused by the numerics, defaults to empty.
214    pub description: String,
215}
216
217/// Parameters of a continuous Uniform distribution.
218///
219/// Constant density over the half-open interval `[lower_bound, upper_bound)`
220/// and zero outside it.
221#[derive(Debug, Clone, Default)]
222pub struct UniformDistribution {
223    /// Inclusive lower bound `a` of the support.
224    pub lower_bound: f64,
225    /// Exclusive upper bound `b` of the support; must satisfy `b > a`.
226    pub upper_bound: f64,
227    /// Optional human-readable name; unused by the numerics, defaults to empty.
228    pub distribution_name: String,
229    /// Optional human-readable description; unused by the numerics, defaults to empty.
230    pub description: String,
231}
232
233/// Parameters of a Weibull distribution.
234///
235/// A positive-support family widely used in reliability and survival analysis,
236/// in the shape/scale parameterisation.
237#[derive(Debug, Clone, Default)]
238pub struct WeibullDistribution {
239    /// Shape parameter `k`; must be `> 0`. Controls the hazard-rate trend.
240    pub shape_parameter: f64,
241    /// Scale parameter `λ`; must be `> 0`. The characteristic life.
242    pub scale_parameter: f64,
243    /// Optional human-readable name; unused by the numerics, defaults to empty.
244    pub distribution_name: String,
245    /// Optional human-readable description; unused by the numerics, defaults to empty.
246    pub description: String,
247}