Crates.io | nalgebra-mvn |
lib.rs | nalgebra-mvn |
version | 0.15.0 |
source | src |
created_at | 2019-08-04 05:56:31.012989 |
updated_at | 2024-06-24 05:45:51.865416 |
description | Multivariate normal distribution using nalgebra |
homepage | |
repository | https://github.com/astraw/nalgebra-mvn |
max_upload_size | |
id | 154081 |
size | 53,925 |
Multivariate normal distribution using nalgebra.
use nalgebra::{ Vector2, Matrix2, OMatrix, U2, U3};
use nalgebra_mvn::MultivariateNormal;
// specify mean and covariance of our multi-variate normal
let mu = Vector2::from_row_slice(&[9.0, 1.0]);
let sigma = Matrix2::from_row_slice(
&[1.0, 0.0,
0.0, 1.0]);
let mvn = MultivariateNormal::from_mean_and_covariance(&mu, &sigma).unwrap();
// input samples are row vectors vertically stacked
let xs = OMatrix::<_,U3,U2>::new(
8.9, 1.0,
9.0, 1.0,
9.1, 1.0,
);
// evaluate the density at each of our samples.
let result = mvn.pdf(&xs);
// result is a vector with num samples rows
assert!(result.nrows()==xs.nrows());
Licensed under either of
at your option.
License: MIT/Apache-2.0