feat: + cross_validate, trait Predictor, refactoring
This commit is contained in:
@@ -25,7 +25,7 @@ use crate::math::num::RealNumber;
|
||||
use super::Distance;
|
||||
|
||||
/// Euclidean distance is a measure of the true straight line distance between two points in Euclidean n-space.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Euclidian {}
|
||||
|
||||
impl Euclidian {
|
||||
|
||||
@@ -26,7 +26,7 @@ use crate::math::num::RealNumber;
|
||||
use super::Distance;
|
||||
|
||||
/// While comparing two integer-valued vectors of equal length, Hamming distance is the number of bit positions in which the two bits are different
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Hamming {}
|
||||
|
||||
impl<T: PartialEq, F: RealNumber> Distance<Vec<T>, F> for Hamming {
|
||||
|
||||
@@ -52,7 +52,7 @@ use super::Distance;
|
||||
use crate::linalg::Matrix;
|
||||
|
||||
/// Mahalanobis distance.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Mahalanobis<T: RealNumber, M: Matrix<T>> {
|
||||
/// covariance matrix of the dataset
|
||||
pub sigma: M,
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::math::num::RealNumber;
|
||||
use super::Distance;
|
||||
|
||||
/// Manhattan distance
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Manhattan {}
|
||||
|
||||
impl<T: RealNumber> Distance<Vec<T>, T> for Manhattan {
|
||||
|
||||
@@ -28,7 +28,7 @@ use crate::math::num::RealNumber;
|
||||
use super::Distance;
|
||||
|
||||
/// Defines the Minkowski distance of order `p`
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Minkowski {
|
||||
/// order, integer
|
||||
pub p: u16,
|
||||
|
||||
@@ -28,7 +28,7 @@ use crate::linalg::Matrix;
|
||||
use crate::math::num::RealNumber;
|
||||
|
||||
/// Distance metric, a function that calculates distance between two points
|
||||
pub trait Distance<T, F: RealNumber> {
|
||||
pub trait Distance<T, F: RealNumber>: Clone {
|
||||
/// Calculates distance between _a_ and _b_
|
||||
fn distance(&self, a: &T, b: &T) -> F;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user