MCPcopy Create free account
hub / github.com/daniel-e/rustml / plot_learning_curve

Function plot_learning_curve

src/opt.rs:300–334  ·  view source on GitHub ↗

Plots the learning curve from an optimization result.

(r: &OptResult<f64>, w: &Window)

Source from the content-addressed store, hash-verified

298/// Plots the learning curve from an optimization result.
299///
300pub fn plot_learning_curve(r: &OptResult<f64>, w: &Window) -> Result<(String, String), &'static str> {
301
302 let errors = r.fvals.iter().map(|&(_, ref y)| y).cloned().collect::<Vec<f64>>();
303
304 let mut prfx = "/tmp/".to_string();
305 prfx.extend(thread_rng().gen_ascii_chars().take(16));
306
307 let script_file = prfx.clone() + ".m";
308 let image_file = prfx + ".png";
309
310 let r = builder()
311 .add_vector("y = $$", &errors)
312 .add("x = 1:size(y, 2)")
313 .add("plot(x, y, 'linewidth', 2)")
314 .add("grid on")
315 .add("title('learning curve')")
316 .add("xlabel('iteration')")
317 .add("ylabel('error')")
318 .add(&("print -r100 -dpng '".to_string() + &image_file + "'"))
319 .run(&script_file);
320
321 match r {
322 Ok(_) => {
323 let img = RgbImage::from_file(&image_file);
324 match img {
325 Some(i) => {
326 w.show_image(&i);
327 Ok((script_file, image_file))
328 },
329 _ => Err("Could not load image.")
330 }
331 },
332 _ => Err("Could not run octave.")
333 }
334}

Callers 1

mainFunction · 0.85

Calls 9

from_fileFunction · 0.85
mapMethod · 0.80
to_stringMethod · 0.80
runMethod · 0.80
add_vectorMethod · 0.80
show_imageMethod · 0.80
builderFunction · 0.70
iterMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected