Struct fluent_data::model::Model
source · [−]pub struct Model<Point: PartialEq> { /* private fields */ }Expand description
A set of balls model.
Implementations
sourceimpl<Point: PartialEq + 'static> Model<Point>
impl<Point: PartialEq + 'static> Model<Point>
sourcepub fn new<Dist>(space_dist: Dist) -> Selfwhere
Dist: Fn(&Point, &Point) -> f64 + 'static,
pub fn new<Dist>(space_dist: Dist) -> Selfwhere
Dist: Fn(&Point, &Point) -> f64 + 'static,
Build a new model.
sourcepub fn load<Dist>(space_dist: Dist, data: Vec<Ball<Point>>) -> Selfwhere
Dist: Fn(&Point, &Point) -> f64 + 'static,
pub fn load<Dist>(space_dist: Dist, data: Vec<Ball<Point>>) -> Selfwhere
Dist: Fn(&Point, &Point) -> f64 + 'static,
Load an existing model.
use fluent_data::{Model, model::BallData, space};
fn main() {
let data = vec![
BallData::new(vec![4.], 3., 1.),
BallData::new(vec![5.], 2., 2.),
BallData::new(vec![3.], 3., 3.),
];
let model = Model::load(space::euclid_dist, data);
}sourcepub fn iter_balls(
&self
) -> impl Iterator<Item = impl Deref<Target = Ball<Point>> + '_>
pub fn iter_balls(
&self
) -> impl Iterator<Item = impl Deref<Target = Ball<Point>> + '_>
Gets an iterator over the balls of this model.
sourcepub fn predict(
&self,
point: &Point
) -> Neighborhood<Ball<Point>, impl Deref<Target = Ball<Point>> + '_>
pub fn predict(
&self,
point: &Point
) -> Neighborhood<Ball<Point>, impl Deref<Target = Ball<Point>> + '_>
Gets the balls that most probably include the given point.
use fluent_data::{Model, model::BallData, space, neighborhood::{GetNeighborhood, Neighborhood}};
fn main() {
let data = vec![
BallData::new(vec![4.], 3., 1.),
BallData::new(vec![5.], 2., 2.),
BallData::new(vec![3.], 3., 3.),
];
let model = Model::load(space::euclid_dist, data.clone());
let neighborhood = model.predict(&vec![6.]);
if let Neighborhood::Two(n1, n2) = neighborhood {
assert_eq!(&data[1], n1.coord());
assert_eq!(1./2., n1.dist());
assert_eq!(&data[0], n2.coord());
assert_eq!(4./3., n2.dist());
} else {
panic!()
}
}Auto Trait Implementations
impl<Point> !RefUnwindSafe for Model<Point>
impl<Point> !Send for Model<Point>
impl<Point> !Sync for Model<Point>
impl<Point> Unpin for Model<Point>
impl<Point> !UnwindSafe for Model<Point>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more