From: Gustav Eek Date: Wed, 25 Jan 2023 19:58:23 +0000 (+0100) Subject: Src. Provide the lognormal distribution option X-Git-Tag: v.0.2~1 X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=79d928c59ab970ecda59a908f1f6d8d6604a9479;p=ranknauto.git Src. Provide the lognormal distribution option --- diff --git a/src/main.rs b/src/main.rs index 5a9531b..a802abe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,8 +4,9 @@ use std::io; // bring flush() into scope with `use std::io::Write` use std::io::prelude::*; // Bring `std::io::BufRead` in scope -use statrs::distribution::{Exp, ContinuousCDF}; // Continuous needed for pdf +use statrs::distribution::{Exp, LogNormal, ContinuousCDF}; // Continuous needed for pdf // use statrs::statistics::Distribution; +// use statrs::prec; const DEBUG: bool = false; @@ -70,12 +71,34 @@ fn exp(n: i32) -> Vec { } +fn lognormal(n: i32) -> Vec { + const NAME: &str = "Lognormal"; // mean of normal distribution (N) + const MEAN: f64 = 0.0; // is unessential thanks to + const STD: f64 = 1.0; // normalization, and std of N + let dist = LogNormal::new(MEAN, STD).unwrap(); + let mut prio: Vec = Vec::new(); + if DEBUG { eprint!("{}: ", NAME) } + for i in 1..n + 1 { + let f = i as f64 / (n as f64 + 1.0); + let x = dist.inverse_cdf(f); + if DEBUG { + eprint!("i = {}, f = {:.2}, x = {:.2}; ", i, f, x); + } + prio.push(x); + } + if DEBUG { eprintln!("\x08\x08."); } + prio.reverse(); + normalize(prio) +} + + fn main() { let ranked: Vec = input(); let num = ranked.len() as i32; let _prio1 = delta(num); - let prio2 = exp(num); + let _prio2 = exp(num); + let prio3 = lognormal(num); if DEBUG { for l in ranked.iter() { @@ -84,6 +107,6 @@ fn main() { eprintln!("\x08\x08."); } - output(&prio2, &ranked); + output(&prio3, &ranked); }