use nalgebra::{DMatrix, DVector};
type DenseVector = DVector<f64>;
type DenseMatrix = DMatrix<f64>;
pub const LN_2PI: f64 = 1.8378770664093453;
#[inline]
pub fn logistic(x: f64) -> f64 {
1.0 / (1.0 + (-x).exp())
}
pub fn trace_of_product(a: &DenseMatrix, b: &DenseMatrix) -> f64 {
(0..a.nrows())
.fold(0.0, |sum, i| {
sum + (a.row(i) * b.column(i))[(0, 0)]
})
}
pub fn scale_rows(matrix: &DenseMatrix, vector: &DenseVector) -> DenseMatrix {
let mut scaled = matrix.clone();
for i in 0..matrix.nrows() {
for j in 0..matrix.ncols() {
scaled[(i, j)] *= vector[i];
}
}
return scaled;
}