spiral/
spiral.rs

1use brique::layers::*;
2use brique::model_builder::ModelBuilder;
3use brique::optimizer::Optimizer;
4use brique::spiral::generate_spiral_dataset;
5
6pub fn main() {
7    // generating the spiral dataset points
8    // 3000 points, spread into three classes (here a class = one spiral)
9    let (data, labels) = generate_spiral_dataset(3000, 3);
10
11    // Layer::init(number_of_inputs: u32, number_of_neurons_for_the_layer: u32, reLu: bool)
12    // if the last arg is true, applies ReLu as the activation function
13    // by default softmax is applied to the last layer
14
15    // One point of the spiral dataset consists of a X and a Y
16    // So the first layer has 2 inputs
17    // The last layer has 3 neurons because we have 3 classes, and therefore we want 3 outputs
18
19    // build and train
20    // (data: &matrix, labels: &matrix, batch_size: u32, number_of_epochs: u32, size_of_the_validation_dataset, usize)
21    let _ = ModelBuilder::new()
22        .add_layer(Layer::init(2, 10, true))
23        .add_layer(Layer::init(10, 10, true))
24        .add_layer(Layer::init(10, 3, false))
25        .optimizer(Optimizer::SGD {
26            learning_step: 0.001,
27        })
28        .l2_reg(0.0001)
29        .build_and_train(&data, &labels, 128, 10, 500);
30}