basic_usage/
basic_usage.rs

1use linear_ransac::{RansacSolver, Point};
2
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}