1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! A simple machine learning library in Rust.
//!
//! `toy_ml` is designed to be a "Hello World" for machine learning enthusiasts
//! looking to get started with Rust. It provides a basic implementation of the
//! gradient descent algorithm, which, while simple, serves as a starting point
//! for understanding machine learning concepts in Rust.
/// The `gradient_descent` function performs a single step of the gradient descent optimization algorithm.
///
/// # Arguments
///
/// * `m_now` - The current value of the slope (m) of the line.
/// * `c_now` - The current value of the y-intercept (c) of the line.
/// * `l` - The learning rate, which controls the size of the update step.
/// * `x` - A reference to a vector containing the x-coordinates of the data points.
/// * `y` - A reference to a vector containing the y-coordinates of the data points.
///
/// # Returns
///
/// A tuple containing the updated values of the slope (m) and y-intercept (c).
///
/// # Example
///
/// ```
/// let m_initial: f64 = 0.0;
/// let c_initial: f64 = 0.0;
/// let learning_rate: f64 = 0.01;
/// let x_coords: Vec<f64> = vec![1.0, 2.0, 3.0];
/// let y_coords: Vec<f64> = vec![2.0, 4.0, 6.0];
///
/// let (m_updated, c_updated) = toy_ml::gradient_descent(m_initial, c_initial, learning_rate, &x_coords, &y_coords);
/// ```
///
/// Note: This implementation is intended for educational purposes and may not be suitable for production use.
/// It aims to inspire and provide a foundation for those interested in exploring machine learning with Rust.