pub struct RansacSolver { /* private fields */ }Implementations§
Source§impl RansacSolver
impl RansacSolver
Sourcepub fn new() -> Self
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}Sourcepub fn with_seed(self, seed: u64) -> Self
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}Sourcepub fn with_min_trials(self, min_trials: usize) -> Self
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
Sourcepub fn fit(&self, data: &[Point]) -> Result<LinearModel, RansacError>
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
impl Clone for RansacSolver
Source§fn clone(&self) -> RansacSolver
fn clone(&self) -> RansacSolver
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RansacSolver
impl Debug for RansacSolver
Auto Trait Implementations§
impl Freeze for RansacSolver
impl RefUnwindSafe for RansacSolver
impl Send for RansacSolver
impl Sync for RansacSolver
impl Unpin for RansacSolver
impl UnwindSafe for RansacSolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more