forked from StudioInfinity/dyna3
Prior to this commit, there's only one kind of regulator: the one that regulates the inversive distance between two spheres (or, more generally, the Lorentz product between two element representation vectors). Adds a new kind of regulator, which regulates the curvature of a sphere (issue #55). In the process, introduces a general framework based on new traits for organizing and sharing code between different kinds of regulators. Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo> Reviewed-on: StudioInfinity/dyna3#80 Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net> Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
33 lines
No EOL
1.2 KiB
Rust
33 lines
No EOL
1.2 KiB
Rust
use dyna3::engine::{Q, realize_gram, sphere, ConstraintProblem};
|
|
|
|
fn main() {
|
|
let mut problem = ConstraintProblem::from_guess({
|
|
let a: f64 = 0.75_f64.sqrt();
|
|
&[
|
|
sphere(1.0, 0.0, 0.0, 1.0),
|
|
sphere(-0.5, a, 0.0, 1.0),
|
|
sphere(-0.5, -a, 0.0, 1.0)
|
|
]
|
|
});
|
|
for j in 0..3 {
|
|
for k in j..3 {
|
|
problem.gram.push_sym(j, k, if j == k { 1.0 } else { -1.0 });
|
|
}
|
|
}
|
|
println!();
|
|
let (config, _, success, history) = realize_gram(
|
|
&problem, 1.0e-12, 0.5, 0.9, 1.1, 200, 110
|
|
);
|
|
print!("\nCompleted Gram matrix:{}", config.tr_mul(&*Q) * &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);
|
|
}
|
|
} |