RansacSolver

Struct RansacSolver 

Source
pub struct RansacSolver { /* private fields */ }

Implementations§

Source§

impl RansacSolver

Source

pub fn new() -> Self

Examples found in repository?
examples/basic_usage.rs (line 16)
3fn main() {
4    // 1. Create some messy data
5    let data = vec![
6        Point::new(1.0,  3.0),  // 2x + 1
7        Point::new(2.0,  5.0),  // 2x + 1
8        Point::new(3.0,  7.0),  // 2x + 1
9        Point::new(4.0,  9.0),  // 2x + 1
10        Point::new(2.5, 50.0),  // OUTLIER!
11        Point::new(3.5, -10.0), // OUTLIER!
12        Point::new(5.0, 11.0),  // 2x + 1
13    ];
14
15    // 2. Fit
16    let result = RansacSolver::new()
17        .with_seed(123)
18        .fit(&data);
19
20    // 3. Handle Result
21    match result {
22        Ok(model) => {
23            println!("Succcess!");
24            println!("y = {:.2}x + {:.2}", model.slope, model.intercept);
25            // Should predict close to y = 2*10 + 1 = 21
26            println!("Prediction for x=10: {}", model.predict(10.0));
27        },
28        Err(e) => println!("RANSAC failed: {}", e),
29    }
30}
Source

pub fn with_seed(self, seed: u64) -> Self

Examples found in repository?
examples/basic_usage.rs (line 17)
3fn main() {
4    // 1. Create some messy data
5    let data = vec![
6        Point::new(1.0,  3.0),  // 2x + 1
7        Point::new(2.0,  5.0),  // 2x + 1
8        Point::new(3.0,  7.0),  // 2x + 1
9        Point::new(4.0,  9.0),  // 2x + 1
10        Point::new(2.5, 50.0),  // OUTLIER!
11        Point::new(3.5, -10.0), // OUTLIER!
12        Point::new(5.0, 11.0),  // 2x + 1
13    ];
14
15    // 2. Fit
16    let result = RansacSolver::new()
17        .with_seed(123)
18        .fit(&data);
19
20    // 3. Handle Result
21    match result {
22        Ok(model) => {
23            println!("Succcess!");
24            println!("y = {:.2}x + {:.2}", model.slope, model.intercept);
25            // Should predict close to y = 2*10 + 1 = 21
26            println!("Prediction for x=10: {}", model.predict(10.0));
27        },
28        Err(e) => println!("RANSAC failed: {}", e),
29    }
30}
Source

pub fn with_min_trials(self, min_trials: usize) -> Self

Set a custom minimum number of RANSAC trials. This lower bound prevents premature stopping when an early

Source

pub fn fit(&self, data: &[Point]) -> Result<LinearModel, RansacError>

Examples found in repository?
examples/basic_usage.rs (line 18)
3fn main() {
4    // 1. Create some messy data
5    let data = vec![
6        Point::new(1.0,  3.0),  // 2x + 1
7        Point::new(2.0,  5.0),  // 2x + 1
8        Point::new(3.0,  7.0),  // 2x + 1
9        Point::new(4.0,  9.0),  // 2x + 1
10        Point::new(2.5, 50.0),  // OUTLIER!
11        Point::new(3.5, -10.0), // OUTLIER!
12        Point::new(5.0, 11.0),  // 2x + 1
13    ];
14
15    // 2. Fit
16    let result = RansacSolver::new()
17        .with_seed(123)
18        .fit(&data);
19
20    // 3. Handle Result
21    match result {
22        Ok(model) => {
23            println!("Succcess!");
24            println!("y = {:.2}x + {:.2}", model.slope, model.intercept);
25            // Should predict close to y = 2*10 + 1 = 21
26            println!("Prediction for x=10: {}", model.predict(10.0));
27        },
28        Err(e) => println!("RANSAC failed: {}", e),
29    }
30}

Trait Implementations§

Source§

impl Clone for RansacSolver

Source§

fn clone(&self) -> RansacSolver

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RansacSolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RansacSolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V