feat: Engine diagnostics (#92)

Adds a `Diagnostics` component that shows the following diagnostics from the last realization:

- Confirmation of success or a short description of what failed.
- The value of the loss function at each step.
- The spectrum of the Hessian at each step.

The loss and spectrum plots are shown on switchable panels.

Also includes some refactoring/renaming of existing code.

Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo>
Reviewed-on: StudioInfinity/dyna3#92
Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net>
Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
This commit is contained in:
Vectornaut 2025-07-21 04:18:49 +00:00 committed by Glen Whitney
parent 4cb3262555
commit 5864017e6f
17 changed files with 1120 additions and 150 deletions

View file

@ -1,4 +1,13 @@
use dyna3::engine::{Q, point, realize_gram, sphere, ConstraintProblem};
#[path = "common/print.rs"]
mod print;
use dyna3::engine::{
point,
realize_gram,
sphere,
ConfigNeighborhood,
ConstraintProblem
};
fn main() {
let mut problem = ConstraintProblem::from_guess(&[
@ -11,21 +20,14 @@ fn main() {
}
}
problem.frozen.push(3, 0, problem.guess[(3, 0)]);
println!();
let (config, _, success, history) = realize_gram(
let realization = realize_gram(
&problem, 1.0e-12, 0.5, 0.9, 1.1, 200, 110
);
print!("\nCompleted Gram matrix:{}", config.tr_mul(&*Q) * &config);
print!("Configuration:{}", config);
if success {
println!("Target accuracy achieved!");
} else {
println!("Failed to reach target accuracy");
}
println!("Steps: {}", history.scaled_loss.len() - 1);
println!("Loss: {}", history.scaled_loss.last().unwrap());
println!("\nStep │ Loss\n─────┼────────────────────────────────");
for (step, scaled_loss) in history.scaled_loss.into_iter().enumerate() {
println!("{:<4}{}", step, scaled_loss);
print::title("Point on a sphere");
print::realization_diagnostics(&realization);
if let Ok(ConfigNeighborhood{ config, .. }) = realization.result {
print::gram_matrix(&config);
print::config(&config);
}
print::loss_history(&realization.history);
}