Trait rustml::scaling::ScaleMatrix [] [src]

pub trait ScaleMatrix<T> {
    fn scale(&self) -> (Self, Vec<Gaussian<T>>);
}

Trait to scale a matrix.

Required Methods

fn scale(&self) -> (Self, Vec<Gaussian<T>>)

Scales the values of the matrix and returns the scaled matrix and the parameters that were used for scaling.

First the mean and the standard deviation of the values for each column is computed. Then, a new matrix is computed where the element at row i and column j is the result of (m(i,j) - mu(j)) / std(j) where

  • m(i,j) is the element at row i and column j in the original matrix m
  • mu(j) is the mean of the elements in column j of m
  • std(j) is the standard deviation of the elements in column j of m

If the standard deviation is smaller than 0.0001 then 1.0 is used in the denominator.

Example

use rustml::*;
use rustml::scaling::*;

let m = mat![
    1.0, 100.0;
    2.0, 150.0;
    0.6, 110.0
];

let (scaled, gaussians) = m.scale();

// mean and standard deviation of first column
assert_eq!(gaussians[0].mean(), 1.2);
assert!(gaussians[0].std() - 0.721 < 0.001);
// mean and standard deviation of second column
assert_eq!(gaussians[1].mean(), 120.0);
assert!(gaussians[1].std() - 26.458 < 0.001);

let e = mat![
    -0.27735, -0.75593;
    1.10940, 1.13389;
    -0.83205, -0.37796
];

assert!(scaled.similar(&e, 0.0001))

Implementors