From 9c5b74fb264f814a7cf74d0155a2b32686bf20de Mon Sep 17 00:00:00 2001 From: lluni Date: Sat, 4 Feb 2023 17:14:25 +0100 Subject: [PATCH] Extracted drawing of example_sine into separate fn --- examples/example_sine.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/example_sine.rs b/examples/example_sine.rs index 09de34c..e968bcf 100644 --- a/examples/example_sine.rs +++ b/examples/example_sine.rs @@ -12,7 +12,7 @@ use rust_nn::layers::activation_layer::ActivationLayer; use rust_nn::layers::fc_layer::{FCLayer, Initializer}; use rust_nn::Network; -fn main() -> Result<(), Box> { +fn main() { // training data let training_interval = (0.0f64, 2.0f64 * PI); let steps = 100000; @@ -71,6 +71,20 @@ fn main() -> Result<(), Box> { // predict test dataset 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], + y_test_true: &[Array1], + y_test_pred: &[Array1], +) -> Result<(), Box> { // create the chart let buf = BitMapBackend::new("./examples/sine.png", (800, 600)).into_drawing_area(); buf.fill(&WHITE)?;