pub trait DistanceFunction<T> {
// Required method
fn distance(&self, observed: &T, simulated: &T) -> f64;
}Expand description
Trait for computing distances between observed and simulated data.
Distance functions are crucial for ABC methods as they determine how “similarity” between datasets is measured. The choice of distance function significantly affects the quality of ABC approximations.
§Type Parameter
T- Type of data being compared (e.g.,Vec<f64>, scalar values)
§Examples
use fugue::*;
// Use built-in Euclidean distance
let euclidean = EuclideanDistance;
let dist = euclidean.distance(&vec![1.0, 2.0], &vec![1.1, 2.1]);
// Implement custom distance function
struct ScalarDistance;
impl DistanceFunction<f64> for ScalarDistance {
fn distance(&self, observed: &f64, simulated: &f64) -> f64 {
(observed - simulated).abs()
}
}