Struct Statistics

Source
pub struct Statistics;

Implementations§

Source§

impl Statistics

Source

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);
Source

pub fn median(data: &Vec<i128>) -> f64

Computes the median value of a vector of integers.

§Arguments
  • data - A reference to a vector of i128 values.
§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);
Source

pub fn variance(data: &Vec<i128>) -> f64

Computes the variance of a vector of integer values.

§Arguments
  • data - A reference to a vector of i128 values 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);
Source

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 of i128 values 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);
Source

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 of i128 values.
§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);
Source

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 of i128 values.
§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);
Source

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 of i128 distances.
  • 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");
Source

pub fn generate_statistics(distances: &Vec<i128>)

Computes and logs statistical summaries of a vector of distances.

§Arguments
  • distances - A reference to a vector of i128 values representing distances.
§Example
let distances = vec![10, 20, 30, 40, 50];
Statistics::generate_statistics(&distances);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V