fn probability_kolmogorov_smirnov(lambda: f64) -> Result<f64, TestError> {
    if lambda == 0.0 {
        return Ok(1.0);
    }

    let minus_two_lambda_squared = -2.0 * lambda * lambda;
    let mut q_ks = 0.0;

    for j in 1..200 {
        let sign = if j % 2 == 1 { 1.0 } else { -1.0 };

        let j = j as f64;
        let term = sign * 2.0 * (minus_two_lambda_squared * j * j).exp();

        q_ks += term;

        if term.abs() < 1e-8 {
            // Trim results that exceed 1.
            return Ok(q_ks.min(1.0));
        }
    }
    Err(TestError::CouldNotConvergeOnKolmogorovSmirnovProbabilityFunction { lambda })
}
/// Calculate the Kolmogorov-Smirnov probability function.
Calculate the Kolmogorov-Smirnov probability function.
Calculate the Kolmogorov - Smirnov probability function .
fn probability_kolmogorov_smirnov(lambda: f64) -> Result<f64, TestError> {
    if lambda == 0.0 {
        return Ok(1.0);
    }
    let minus_two_lambda_squared = -2.0 * lambda * lambda;
    let mut q_ks = 0.0;
    for j in 1..200 {
        let sign = if j % 2 == 1 { 1.0 } else { -1.0 };
        let j = j as f64;
        let term = sign * 2.0 * (minus_two_lambda_squared * j * j).exp();
        q_ks += term;
        if term.abs() < 1e-8 {
            // Trim results that exceed 1.
            return Ok(q_ks.min(1.0));
        }
    }
    Err(TestError::CouldNotConvergeOnKolmogorovSmirnovProbabilityFunction { lambda })
}
fn probability_kolmogorov_smirnov ( lambda : f64 ) -> Result < f64 , TestError > { if lambda == 0.0 { return Ok ( 1.0 ) ; } let minus_two_lambda_squared = - 2.0 * lambda * lambda ; let mut q_ks = 0.0 ; for j in 1 .. 200 { let sign = if j % 2 == 1 { 1.0 } else { - 1.0 } ; let j = j as f64 ; let term = sign * 2.0 * ( minus_two_lambda_squared * j * j ) . exp ( ) ; q_ks += term ; if term . abs ( ) < 1e-8 { // Trim results that exceed 1. return Ok ( q_ks . min ( 1.0 ) ) ; } } Err ( TestError :: CouldNotConvergeOnKolmogorovSmirnovProbabilityFunction { lambda } ) }
Calculate the Kolmogorov-Smirnov probability function.
Calculate the Kolmogorov - Smirnov probability function .
lambda
f64
lambda
f64