r2rs-stats 0.1.1

Statistics programming for Rust based on R's stats package
Documentation
// "Whatever you do, work at it with all your heart, as working for the Lord,
// not for human masters, since you know that you will receive an inheritance
// from the Lord as a reward. It is the Lord Christ you are serving."
// (Col 3:23-24)

use nalgebra::DMatrix;

use crate::regression::glm::link::core::Link;

#[derive(Default, Clone, Debug)]
pub struct Sqrt {}

impl Sqrt {
    pub fn new() -> Self {
        Self::default()
    }
}

impl Link for Sqrt {
    fn link_func(&self, mu: &DMatrix<f64>) -> DMatrix<f64> {
        mu.map(|mu| mu.sqrt())
    }

    fn link_inverse(&self, eta: &DMatrix<f64>) -> DMatrix<f64> {
        eta.map(|eta| eta.powi(2))
    }

    fn mu_eta(&self, eta: &DMatrix<f64>) -> DMatrix<f64> {
        eta.map(|eta| (2.0 * eta))
    }

    fn valid_eta(&self, eta: &DMatrix<f64>) -> bool {
        eta.iter().all(|&eta| eta.is_finite() && eta > 0.0)
    }
}