pub trait StatisticalCurve: MetricsExtractor {
// Required method
fn get_x_values(&self) -> Vec<Decimal>;
// Provided methods
fn generate_statistical_curve(
&self,
basic_metrics: &BasicMetrics,
shape_metrics: &ShapeMetrics,
range_metrics: &RangeMetrics,
trend_metrics: &TrendMetrics,
num_points: usize,
seed: Option<u64>,
) -> Result<Curve, CurveError> { ... }
fn generate_refined_statistical_curve(
&self,
basic_metrics: &BasicMetrics,
shape_metrics: &ShapeMetrics,
range_metrics: &RangeMetrics,
trend_metrics: &TrendMetrics,
num_points: usize,
max_attempts: usize,
tolerance: Decimal,
seed: Option<u64>,
) -> Result<Curve, CurveError> { ... }
fn verify_curve_metrics(
&self,
curve: &Curve,
target_metrics: &BasicMetrics,
tolerance: Decimal,
) -> Result<bool, CurveError> { ... }
}Expand description
A trait for generating statistical curves based on metrics
This trait provides methods to generate curves that match specified
statistical properties. It extends the MetricsExtractor trait to
ensure implementing types can both extract and generate metrics.
Required Methods§
Sourcefn get_x_values(&self) -> Vec<Decimal>
fn get_x_values(&self) -> Vec<Decimal>
Retrieves the x-axis values for the statistical curve.
This method returns a vector of Decimal values representing the x-coordinates
of the points that define the curve. These x-values are essential for plotting
the curve and performing various statistical analyses.
§Returns
A Vec<Decimal> containing the x-values of the statistical curve. Each Decimal
represents a point on the x-axis.
Provided Methods§
Sourcefn generate_statistical_curve(
&self,
basic_metrics: &BasicMetrics,
shape_metrics: &ShapeMetrics,
range_metrics: &RangeMetrics,
trend_metrics: &TrendMetrics,
num_points: usize,
seed: Option<u64>,
) -> Result<Curve, CurveError>
fn generate_statistical_curve( &self, basic_metrics: &BasicMetrics, shape_metrics: &ShapeMetrics, range_metrics: &RangeMetrics, trend_metrics: &TrendMetrics, num_points: usize, seed: Option<u64>, ) -> Result<Curve, CurveError>
Generates a statistical curve with properties that match the provided metrics.
§Overview
This function creates a curve with statistical properties that approximate the specified metrics. It uses a combination of normal distribution sampling and transformations to achieve the desired statistical characteristics.
§Parameters
basic_metrics: Basic statistical properties like mean, median, mode, and standard deviation.shape_metrics: Shape-related metrics like skewness and kurtosis.range_metrics: Range information including min, max, and quartile data.trend_metrics: Trend information including slope and intercept for linear trend.num_points: Number of points to generate in the curve.seed: Optional random seed for reproducible curve generation.
§Returns
Result<Curve, CurveError>: A curve matching the specified statistical properties, or an error if generation fails.
§Errors
Returns CurveError::ConstructionError when the requested
combination of basic, shape and range-parameter metrics is
infeasible (e.g. negative variance, inconsistent quantiles), and
propagates CurveError::MetricsError when the per-sample
metric evaluation fails.
Sourcefn generate_refined_statistical_curve(
&self,
basic_metrics: &BasicMetrics,
shape_metrics: &ShapeMetrics,
range_metrics: &RangeMetrics,
trend_metrics: &TrendMetrics,
num_points: usize,
max_attempts: usize,
tolerance: Decimal,
seed: Option<u64>,
) -> Result<Curve, CurveError>
fn generate_refined_statistical_curve( &self, basic_metrics: &BasicMetrics, shape_metrics: &ShapeMetrics, range_metrics: &RangeMetrics, trend_metrics: &TrendMetrics, num_points: usize, max_attempts: usize, tolerance: Decimal, seed: Option<u64>, ) -> Result<Curve, CurveError>
Generates a refined statistical curve that iteratively adjusts to better match the target metrics.
This method extends the basic curve generation by performing multiple attempts with adjusted parameters until the resulting curve metrics are within the specified tolerance of the target metrics.
§Parameters
basic_metrics: Target basic statistical metricsshape_metrics: Target shape metricsrange_metrics: Target range metricstrend_metrics: Target trend metricsnum_points: Number of points to generatemax_attempts: Maximum number of generation attempts (default: 5)tolerance: Acceptable difference between target and actual metrics (default: 0.1)seed: Optional random seed for reproducibility
§Returns
Result<Curve, CurveError>: The generated curve or an error
§Errors
Same failure surface as
StatisticalCurve::generate_statistical_curve, plus
CurveError::ConstructionError when the refinement loop
exhausts its iteration budget without matching the tolerance.
Sourcefn verify_curve_metrics(
&self,
curve: &Curve,
target_metrics: &BasicMetrics,
tolerance: Decimal,
) -> Result<bool, CurveError>
fn verify_curve_metrics( &self, curve: &Curve, target_metrics: &BasicMetrics, tolerance: Decimal, ) -> Result<bool, CurveError>
Verifies if the metrics of the generated curve match the target metrics within the specified tolerance.
§Parameters
curve: The curve to verifytarget_metrics: The target basic metrics to compare againsttolerance: Maximum acceptable difference between actual and target metrics
§Returns
Result<bool, CurveError>: True if metrics match within tolerance, false otherwise
§Errors
Propagates any CurveError::MetricsError or
CurveError::ConstructionError raised while recomputing the
curve’s actual metrics (typically when the curve contains
non-finite samples or lacks the density required for the
requested metric). Returns CurveError::AnalysisError when the gap
between an actual and a target metric leaves the representable
Decimal range.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".