forked from StudioInfinity/dyna3

In the process, spruce up our realization diagnostics logging and factor out some of the repetitive code in the examples, because we're already changing those parts of the code to adapt them to the new encapsulation. This commit changes the example output format. I've checked by hand that the output is rearranged but not meaningfully changed.
36 lines
No EOL
1.2 KiB
Rust
36 lines
No EOL
1.2 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use nalgebra::DMatrix;
|
|
|
|
use dyna3::engine::{Q, DescentHistory, RealizationResult};
|
|
|
|
pub fn print_title(title: &str) {
|
|
println!("─── {title} ───");
|
|
}
|
|
|
|
pub fn print_realization_diagnostics(realization_result: &RealizationResult) {
|
|
let RealizationResult { result, history } = realization_result;
|
|
println!();
|
|
if let Err(ref msg) = result {
|
|
println!("❌️ {msg}");
|
|
} else {
|
|
println!("✅️ Target accuracy achieved!");
|
|
}
|
|
println!("Steps: {}", history.scaled_loss.len() - 1);
|
|
println!("Loss: {}", history.scaled_loss.last().unwrap());
|
|
}
|
|
|
|
pub fn print_gram_matrix(config: &DMatrix<f64>) {
|
|
println!("\nCompleted Gram matrix:{}", (config.tr_mul(&*Q) * config).to_string().trim_end());
|
|
}
|
|
|
|
pub fn print_config(config: &DMatrix<f64>) {
|
|
println!("\nConfiguration:{}", config.to_string().trim_end());
|
|
}
|
|
|
|
pub fn print_loss_history(history: &DescentHistory) {
|
|
println!("\nStep │ Loss\n─────┼────────────────────────────────");
|
|
for (step, scaled_loss) in history.scaled_loss.iter().enumerate() {
|
|
println!("{:<4} │ {}", step, scaled_loss);
|
|
}
|
|
} |