Extracted drawing of example_sine into separate fn

This commit is contained in:
lluni 2023-02-04 17:14:25 +01:00
parent e24b05f4bc
commit 9c5b74fb26
Signed by: lluni
GPG key ID: ACEEB468BC325D35

View file

@ -12,7 +12,7 @@ use rust_nn::layers::activation_layer::ActivationLayer;
use rust_nn::layers::fc_layer::{FCLayer, Initializer}; use rust_nn::layers::fc_layer::{FCLayer, Initializer};
use rust_nn::Network; use rust_nn::Network;
fn main() -> Result<(), Box<dyn Error>> { fn main() {
// training data // training data
let training_interval = (0.0f64, 2.0f64 * PI); let training_interval = (0.0f64, 2.0f64 * PI);
let steps = 100000; let steps = 100000;
@ -71,6 +71,20 @@ fn main() -> Result<(), Box<dyn Error>> {
// predict test dataset // predict test dataset
let y_test_pred = network.predict(&x_test); let y_test_pred = network.predict(&x_test);
// show results
if let Ok(()) = draw_results(&training_interval, &x_test, &y_test_true, &y_test_pred) {
println!("results can be seen in ./examples/sine.png");
} else {
println!("failed to draw results");
}
}
fn draw_results(
training_interval: &(f64, f64),
x_test: &[Array1<f64>],
y_test_true: &[Array1<f64>],
y_test_pred: &[Array1<f64>],
) -> Result<(), Box<dyn Error>> {
// create the chart // create the chart
let buf = BitMapBackend::new("./examples/sine.png", (800, 600)).into_drawing_area(); let buf = BitMapBackend::new("./examples/sine.png", (800, 600)).into_drawing_area();
buf.fill(&WHITE)?; buf.fill(&WHITE)?;