pub struct Statistics;Implementations§
Source§impl Statistics
impl Statistics
Sourcepub fn mean(data: &Vec<i128>) -> f64
pub fn mean(data: &Vec<i128>) -> f64
Computes the arithmetic mean (average) of a vector of integer values.
§Arguments
data- A reference to a vector of 128-bit signed integers (Vec<i128>) representing the values for which the mean will be calculated.
§Returns
A f64 value representing the average of all elements in data.
§Panics
This function will panic if data is empty, because division by zero
would occur. Ensure that the input vector contains at least one value.
§Example
let values = vec![10_i128, 20, 30, 40];
let avg = mean(&values);Sourcepub fn median(data: &Vec<i128>) -> f64
pub fn median(data: &Vec<i128>) -> f64
Computes the median value of a vector of integers.
§Arguments
data- A reference to a vector ofi128values.
§Returns
A f64 representing the median of the input data.
§Panics
This function will panic if data is empty, because accessing elements
in an empty slice is invalid. Ensure that the vector contains at least one value.
§Example
let values = vec![5_i128, 1, 9, 3, 7];
let med = median(&values);Sourcepub fn variance(data: &Vec<i128>) -> f64
pub fn variance(data: &Vec<i128>) -> f64
Computes the variance of a vector of integer values.
§Arguments
data- A reference to a vector ofi128values whose variance will be computed.
§Returns
A f64 representing the variance of the data.
§Panics
This function will panic if data is empty, since variance is undefined
for an empty dataset. Ensure the input contains at least one value.
§Example
let values = vec![2_i128, 4, 4, 4, 5, 5, 7, 9];
let var = Statistics::variance(&values);Sourcepub fn std_dev(data: &Vec<i128>) -> f64
pub fn std_dev(data: &Vec<i128>) -> f64
Computes the standard deviation of a vector of integer values.
§Arguments
data- A reference to a vector ofi128values whose standard deviation will be computed.
§Returns
A f64 representing the standard deviation.
§Panics
This function will panic if data is empty, since standard deviation
cannot be computed without at least one value.
§Example
let values = vec![2_i128, 4, 4, 4, 5, 5, 7, 9];
let sd = Statistics::std_dev(&values);Sourcepub fn min_max(data: &Vec<i128>) -> (i128, i128)
pub fn min_max(data: &Vec<i128>) -> (i128, i128)
Returns the minimum and maximum values in a vector of integer values.
§Arguments
data- A reference to a vector ofi128values.
§Returns
A tuple (min, max):
min(i128): The smallest value in the vector.max(i128): The largest value in the vector.
§Panics
This function will panic if the dataset is empty, because computing a minimum and maximum requires at least one value.
§Example
let values = vec![12_i128, 5, 30, 7, 9];
let (min_val, max_val) = Statistics::min_max(&values);Sourcepub fn quartiles(data: &Vec<i128>) -> (f64, f64, f64)
pub fn quartiles(data: &Vec<i128>) -> (f64, f64, f64)
Computes the first, second (median), and third quartiles of a vector of integer values.
§Arguments
data- A reference to a vector ofi128values.
§Returns
A tuple (q1, q2, q3) of type (f64, f64, f64) representing the three quartiles.
§Panics
This function will panic if data is empty.
§Example
let values = vec![7_i128, 15, 36, 39, 40, 41, 42, 43, 47, 49];
let (q1, q2, q3) = Statistics::quartiles(&values);Sourcepub fn plot_histogram(distances: &Vec<i128>, filename: &str)
pub fn plot_histogram(distances: &Vec<i128>, filename: &str)
Plots a histogram of the given distances and saves it as an image file.
This function divides the range of distances into a fixed number of bins (20),
counts the number of distances falling into each bin, and creates a histogram
chart using the plotters crate. The Y-axis is scaled based on the maximum
count plus a margin of 5 (can be changed).
§Arguments
distances- A reference to a vector ofi128distances.filename- A string slice representing the path where the histogram image will be saved.
§Panics
This function will panic if:
- The distances vector is empty.
- Writing the image file fails.
§Example
let distances = vec![10, 20, 20, 30, 40, 40, 40, 50];
Statistics::plot_histogram(&distances, "output/histogram.png");