pub fn normalize_to_probabilities<T: Div<Output = T> + for<'a> Sum<&'a T>>(
    input: &Vec<T>
) -> Vec<T>
where for<'a> &'a T: Div<Output = T>,
Expand description

Given a list of values, attempt to normalize them based on their sum.

This method works as long as the type inside the vec supports the std::ops::Div and std::iter::Sum traits.

The algorithm “works” by summing all the values together, and then normalizes each value by calculating val / sum.

§Example

use wagon_utils::normalize_to_probabilities;

let v = vec![1.0, 1.0, 2.0];
assert_eq!(vec![0.25, 0.25, 0.5], normalize_to_probabilities(&v))