Commit 308447b8 authored by Rui Vieira's avatar Rui Vieira 🍵
Browse files

Add squared distance

parent a32794fd
......@@ -2,3 +2,4 @@
/target
**/*.rs.bk
.idea
.vscode
This diff is collapsed.
......@@ -16,4 +16,5 @@ license = "Apache-2.0"
rand = "0.6.4"
[dev-dependencies]
matplotrust = "0.1.5"
\ No newline at end of file
matplotrust = "0.1.5"
probability = "0.15.12"
\ No newline at end of file
extern crate rand;
#[cfg(test)]
#[macro_use]
extern crate matplotrust;
mod utils;
use rand::prelude::*;
use rand::distributions::Normal as N;
......@@ -150,7 +150,7 @@ mod test_normal {
fn sample_mean_std() {
let n = 0..1000000;
let mut normal = Normal::new(0.0, 1.0);
let samples = n.map(|i| normal.sample()).collect::<Vec<f64>>();
let samples = n.map(|_i| normal.sample()).collect::<Vec<f64>>();
let mu = mean(&samples);
assert_delta!(0.0, mu, 1e-3);
}
......
pub fn squared_distance(x: &Vec<f64>, y: &Vec<f64>) -> f64 {
assert_eq!(x.len(), y.len(), "Vectors must have the same size.");
let mut sum = 0.0;
for i in 0..x.len() {
sum += (x[i] - y[i]).powi(2)
}
return sum;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment