forked from StudioInfinity/dyna3
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:
parent
4cb3262555
commit
5864017e6f
17 changed files with 1120 additions and 150 deletions
|
@ -3,8 +3,9 @@ use sycamore::prelude::*;
|
|||
use web_sys::{console, wasm_bindgen::JsValue};
|
||||
|
||||
use crate::{
|
||||
engine,
|
||||
AppState,
|
||||
engine,
|
||||
engine::DescentHistory,
|
||||
assembly::{Assembly, InversiveDistanceRegulator, Point, Sphere}
|
||||
};
|
||||
|
||||
|
@ -195,6 +196,7 @@ pub fn AddRemove() -> View {
|
|||
assembly.regulators.update(|regs| regs.clear());
|
||||
assembly.elements.update(|elts| elts.clear());
|
||||
assembly.elements_by_id.update(|elts_by_id| elts_by_id.clear());
|
||||
assembly.descent_history.set(DescentHistory::new());
|
||||
state.selection.update(|sel| sel.clear());
|
||||
|
||||
// load assembly
|
||||
|
|
|
@ -23,8 +23,11 @@ use crate::{
|
|||
project_sphere_to_normalized,
|
||||
realize_gram,
|
||||
sphere,
|
||||
ConfigNeighborhood,
|
||||
ConfigSubspace,
|
||||
ConstraintProblem
|
||||
ConstraintProblem,
|
||||
DescentHistory,
|
||||
Realization
|
||||
},
|
||||
outline::OutlineItem,
|
||||
specified::SpecifiedValue
|
||||
|
@ -547,7 +550,11 @@ pub struct Assembly {
|
|||
pub tangent: Signal<ConfigSubspace>,
|
||||
|
||||
// indexing
|
||||
pub elements_by_id: Signal<BTreeMap<String, Rc<dyn Element>>>
|
||||
pub elements_by_id: Signal<BTreeMap<String, Rc<dyn Element>>>,
|
||||
|
||||
// realization diagnostics
|
||||
pub realization_status: Signal<Result<(), String>>,
|
||||
pub descent_history: Signal<DescentHistory>
|
||||
}
|
||||
|
||||
impl Assembly {
|
||||
|
@ -556,7 +563,9 @@ impl Assembly {
|
|||
elements: create_signal(BTreeSet::new()),
|
||||
regulators: create_signal(BTreeSet::new()),
|
||||
tangent: create_signal(ConfigSubspace::zero(0)),
|
||||
elements_by_id: create_signal(BTreeMap::default())
|
||||
elements_by_id: create_signal(BTreeMap::default()),
|
||||
realization_status: create_signal(Ok(())),
|
||||
descent_history: create_signal(DescentHistory::new())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -687,31 +696,49 @@ impl Assembly {
|
|||
console_log!("Old configuration:{:>8.3}", problem.guess);
|
||||
|
||||
// look for a configuration with the given Gram matrix
|
||||
let (config, tangent, success, history) = realize_gram(
|
||||
let Realization { result, history } = realize_gram(
|
||||
&problem, 1.0e-12, 0.5, 0.9, 1.1, 200, 110
|
||||
);
|
||||
|
||||
/* DEBUG */
|
||||
// report the outcome of the search
|
||||
if success {
|
||||
console_log!("Target accuracy achieved!")
|
||||
// report the outcome of the search in the browser console
|
||||
if let Err(ref message) = result {
|
||||
console_log!("❌️ {message}");
|
||||
} else {
|
||||
console_log!("Failed to reach target accuracy")
|
||||
console_log!("✅️ Target accuracy achieved!");
|
||||
}
|
||||
console_log!("Steps: {}", history.scaled_loss.len() - 1);
|
||||
console_log!("Loss: {}", *history.scaled_loss.last().unwrap());
|
||||
console_log!("Tangent dimension: {}", tangent.dim());
|
||||
console_log!("Loss: {}", history.scaled_loss.last().unwrap());
|
||||
|
||||
if success {
|
||||
// read out the solution
|
||||
for elt in self.elements.get_clone_untracked() {
|
||||
elt.representation().update(
|
||||
|rep| rep.set_column(0, &config.column(elt.column_index().unwrap()))
|
||||
);
|
||||
// report the loss history
|
||||
self.descent_history.set(history);
|
||||
|
||||
match result {
|
||||
Ok(ConfigNeighborhood { config, nbhd: tangent }) => {
|
||||
/* DEBUG */
|
||||
// report the tangent dimension
|
||||
console_log!("Tangent dimension: {}", tangent.dim());
|
||||
|
||||
// report the realization status
|
||||
self.realization_status.set(Ok(()));
|
||||
|
||||
// read out the solution
|
||||
for elt in self.elements.get_clone_untracked() {
|
||||
elt.representation().update(
|
||||
|rep| rep.set_column(0, &config.column(elt.column_index().unwrap()))
|
||||
);
|
||||
}
|
||||
|
||||
// save the tangent space
|
||||
self.tangent.set_silent(tangent);
|
||||
},
|
||||
Err(message) => {
|
||||
// report the realization status. the `Err(message)` we're
|
||||
// setting the status to has a different type than the
|
||||
// `Err(message)` we received from the match: we're changing the
|
||||
// `Ok` type from `Realization` to `()`
|
||||
self.realization_status.set(Err(message))
|
||||
}
|
||||
|
||||
// save the tangent space
|
||||
self.tangent.set_silent(tangent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
258
app-proto/src/diagnostics.rs
Normal file
258
app-proto/src/diagnostics.rs
Normal file
|
@ -0,0 +1,258 @@
|
|||
use charming::{
|
||||
Chart,
|
||||
WasmRenderer,
|
||||
component::{Axis, DataZoom, Grid},
|
||||
element::{AxisType, Symbol},
|
||||
series::{Line, Scatter},
|
||||
};
|
||||
use sycamore::prelude::*;
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct DiagnosticsState {
|
||||
active_tab: Signal<String>
|
||||
}
|
||||
|
||||
impl DiagnosticsState {
|
||||
fn new(initial_tab: String) -> DiagnosticsState {
|
||||
DiagnosticsState {
|
||||
active_tab: create_signal(initial_tab)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// a realization status indicator
|
||||
#[component]
|
||||
fn RealizationStatus() -> View {
|
||||
let state = use_context::<AppState>();
|
||||
let realization_status = state.assembly.realization_status;
|
||||
view! {
|
||||
div(
|
||||
id="realization-status",
|
||||
class=realization_status.with(
|
||||
|status| match status {
|
||||
Ok(_) => "",
|
||||
Err(_) => "invalid"
|
||||
}
|
||||
)
|
||||
) {
|
||||
div(class="status")
|
||||
div {
|
||||
(realization_status.with(
|
||||
|status| match status {
|
||||
Ok(_) => "Target accuracy achieved".to_string(),
|
||||
Err(message) => message.clone()
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn into_log10_time_point((step, value): (usize, f64)) -> Vec<Option<f64>> {
|
||||
vec![
|
||||
Some(step as f64),
|
||||
if value == 0.0 { None } else { Some(value.abs().log10()) }
|
||||
]
|
||||
}
|
||||
|
||||
// the loss history from the last realization
|
||||
#[component]
|
||||
fn LossHistory() -> View {
|
||||
const CONTAINER_ID: &str = "loss-history";
|
||||
let state = use_context::<AppState>();
|
||||
let renderer = WasmRenderer::new_opt(None, Some(178));
|
||||
|
||||
on_mount(move || {
|
||||
create_effect(move || {
|
||||
// get the loss history
|
||||
let scaled_loss: Vec<_> = state.assembly.descent_history.with(
|
||||
|history| history.scaled_loss
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(step, &loss)| (step, loss))
|
||||
.map(into_log10_time_point)
|
||||
.collect()
|
||||
);
|
||||
|
||||
// initialize the chart axes
|
||||
let step_axis = Axis::new()
|
||||
.type_(AxisType::Category)
|
||||
.boundary_gap(false);
|
||||
let scaled_loss_axis = Axis::new();
|
||||
|
||||
// load the chart data. when there's no history, we load the data
|
||||
// point (0, None) to clear the chart. it would feel more natural to
|
||||
// load empty data vectors, but that turns out not to clear the
|
||||
// chart: it instead leads to previous data being re-used
|
||||
let scaled_loss_series = Line::new().data(
|
||||
if scaled_loss.len() > 0 {
|
||||
scaled_loss
|
||||
} else {
|
||||
vec![vec![Some(0.0), None::<f64>]]
|
||||
}
|
||||
);
|
||||
let chart = Chart::new()
|
||||
.animation(false)
|
||||
.data_zoom(DataZoom::new().y_axis_index(0).right(40))
|
||||
.x_axis(step_axis)
|
||||
.y_axis(scaled_loss_axis)
|
||||
.grid(Grid::new().top(20).right(80).bottom(30).left(60))
|
||||
.series(scaled_loss_series);
|
||||
renderer.render(CONTAINER_ID, &chart).unwrap();
|
||||
});
|
||||
});
|
||||
|
||||
view! {
|
||||
div(id=CONTAINER_ID, class="diagnostics-chart")
|
||||
}
|
||||
}
|
||||
|
||||
// the spectrum of the Hessian during the last realization
|
||||
#[component]
|
||||
fn SpectrumHistory() -> View {
|
||||
const CONTAINER_ID: &str = "spectrum-history";
|
||||
let state = use_context::<AppState>();
|
||||
let renderer = WasmRenderer::new(478, 178);
|
||||
|
||||
on_mount(move || {
|
||||
create_effect(move || {
|
||||
// get the spectrum of the Hessian at each step, split into its
|
||||
// positive, negative, and strictly-zero parts
|
||||
let (
|
||||
hess_eigvals_zero,
|
||||
hess_eigvals_nonzero
|
||||
): (Vec<_>, Vec<_>) = state.assembly.descent_history.with(
|
||||
|history| history.hess_eigvals
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(
|
||||
|(step, eigvals)| eigvals.iter().map(
|
||||
move |&val| (step, val)
|
||||
)
|
||||
)
|
||||
.flatten()
|
||||
.partition(|&(_, val)| val == 0.0)
|
||||
);
|
||||
let zero_level = hess_eigvals_nonzero
|
||||
.iter()
|
||||
.map(|(_, val)| val.abs())
|
||||
.reduce(f64::min)
|
||||
.map(|val| 0.1 * val)
|
||||
.unwrap_or(1.0);
|
||||
let (
|
||||
hess_eigvals_pos,
|
||||
hess_eigvals_neg
|
||||
): (Vec<_>, Vec<_>) = hess_eigvals_nonzero
|
||||
.into_iter()
|
||||
.partition(|&(_, val)| val > 0.0);
|
||||
|
||||
// initialize the chart axes
|
||||
let step_axis = Axis::new()
|
||||
.type_(AxisType::Category)
|
||||
.boundary_gap(false);
|
||||
let eigval_axis = Axis::new();
|
||||
|
||||
// load the chart data. when there's no history, we load the data
|
||||
// point (0, None) to clear the chart. it would feel more natural to
|
||||
// load empty data vectors, but that turns out not to clear the
|
||||
// chart: it instead leads to previous data being re-used
|
||||
let eigval_series_pos = Scatter::new()
|
||||
.symbol_size(4.5)
|
||||
.data(
|
||||
if hess_eigvals_pos.len() > 0 {
|
||||
hess_eigvals_pos
|
||||
.into_iter()
|
||||
.map(into_log10_time_point)
|
||||
.collect()
|
||||
} else {
|
||||
vec![vec![Some(0.0), None::<f64>]]
|
||||
}
|
||||
);
|
||||
let eigval_series_neg = Scatter::new()
|
||||
.symbol(Symbol::Diamond)
|
||||
.symbol_size(6.0)
|
||||
.data(
|
||||
if hess_eigvals_neg.len() > 0 {
|
||||
hess_eigvals_neg
|
||||
.into_iter()
|
||||
.map(into_log10_time_point)
|
||||
.collect()
|
||||
} else {
|
||||
vec![vec![Some(0.0), None::<f64>]]
|
||||
}
|
||||
);
|
||||
let eigval_series_zero = Scatter::new()
|
||||
.symbol(Symbol::Triangle)
|
||||
.symbol_size(5.0)
|
||||
.data(
|
||||
if hess_eigvals_zero.len() > 0 {
|
||||
hess_eigvals_zero
|
||||
.into_iter()
|
||||
.map(|(step, _)| (step, zero_level))
|
||||
.map(into_log10_time_point)
|
||||
.collect()
|
||||
} else {
|
||||
vec![vec![Some(0.0), None::<f64>]]
|
||||
}
|
||||
);
|
||||
let chart = Chart::new()
|
||||
.animation(false)
|
||||
.data_zoom(DataZoom::new().y_axis_index(0).right(40))
|
||||
.x_axis(step_axis)
|
||||
.y_axis(eigval_axis)
|
||||
.grid(Grid::new().top(20).right(80).bottom(30).left(60))
|
||||
.series(eigval_series_pos)
|
||||
.series(eigval_series_neg)
|
||||
.series(eigval_series_zero);
|
||||
renderer.render(CONTAINER_ID, &chart).unwrap();
|
||||
});
|
||||
});
|
||||
|
||||
view! {
|
||||
div(id=CONTAINER_ID, class="diagnostics-chart")
|
||||
}
|
||||
}
|
||||
|
||||
#[component(inline_props)]
|
||||
fn DiagnosticsPanel(name: &'static str, children: Children) -> View {
|
||||
let diagnostics_state = use_context::<DiagnosticsState>();
|
||||
view! {
|
||||
div(
|
||||
class="diagnostics-panel",
|
||||
"hidden"=diagnostics_state.active_tab.with(
|
||||
|active_tab| {
|
||||
if active_tab == name {
|
||||
None
|
||||
} else {
|
||||
Some("")
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
(children)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn Diagnostics() -> View {
|
||||
let diagnostics_state = DiagnosticsState::new("loss".to_string());
|
||||
let active_tab = diagnostics_state.active_tab.clone();
|
||||
provide_context(diagnostics_state);
|
||||
|
||||
view! {
|
||||
div(id="diagnostics") {
|
||||
div(id="diagnostics-bar") {
|
||||
RealizationStatus {}
|
||||
select(bind:value=active_tab) {
|
||||
option(value="loss") { "Loss" }
|
||||
option(value="spectrum") { "Spectrum" }
|
||||
}
|
||||
}
|
||||
DiagnosticsPanel(name="loss") { LossHistory {} }
|
||||
DiagnosticsPanel(name="spectrum") { SpectrumHistory {} }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -806,6 +806,7 @@ pub fn Display() -> View {
|
|||
// again
|
||||
canvas(
|
||||
ref=display,
|
||||
id="display",
|
||||
width="600",
|
||||
height="600",
|
||||
tabindex="0",
|
||||
|
|
|
@ -256,18 +256,18 @@ pub struct DescentHistory {
|
|||
pub config: Vec<DMatrix<f64>>,
|
||||
pub scaled_loss: Vec<f64>,
|
||||
pub neg_grad: Vec<DMatrix<f64>>,
|
||||
pub min_eigval: Vec<f64>,
|
||||
pub hess_eigvals: Vec::<DVector<f64>>,
|
||||
pub base_step: Vec<DMatrix<f64>>,
|
||||
pub backoff_steps: Vec<i32>
|
||||
}
|
||||
|
||||
impl DescentHistory {
|
||||
fn new() -> DescentHistory {
|
||||
pub fn new() -> DescentHistory {
|
||||
DescentHistory {
|
||||
config: Vec::<DMatrix<f64>>::new(),
|
||||
scaled_loss: Vec::<f64>::new(),
|
||||
neg_grad: Vec::<DMatrix<f64>>::new(),
|
||||
min_eigval: Vec::<f64>::new(),
|
||||
hess_eigvals: Vec::<DVector<f64>>::new(),
|
||||
base_step: Vec::<DMatrix<f64>>::new(),
|
||||
backoff_steps: Vec::<i32>::new(),
|
||||
}
|
||||
|
@ -393,6 +393,17 @@ fn seek_better_config(
|
|||
None
|
||||
}
|
||||
|
||||
// a first-order neighborhood of a configuration
|
||||
pub struct ConfigNeighborhood {
|
||||
pub config: DMatrix<f64>,
|
||||
pub nbhd: ConfigSubspace
|
||||
}
|
||||
|
||||
pub struct Realization {
|
||||
pub result: Result<ConfigNeighborhood, String>,
|
||||
pub history: DescentHistory
|
||||
}
|
||||
|
||||
// seek a matrix `config` that matches the partial matrix `problem.frozen` and
|
||||
// has `config' * Q * config` matching the partial matrix `problem.gram`. start
|
||||
// at `problem.guess`, set the frozen entries to their desired values, and then
|
||||
|
@ -405,7 +416,7 @@ pub fn realize_gram(
|
|||
reg_scale: f64,
|
||||
max_descent_steps: i32,
|
||||
max_backoff_steps: i32
|
||||
) -> (DMatrix<f64>, ConfigSubspace, bool, DescentHistory) {
|
||||
) -> Realization {
|
||||
// destructure the problem data
|
||||
let ConstraintProblem {
|
||||
gram, guess, frozen
|
||||
|
@ -457,11 +468,12 @@ pub fn realize_gram(
|
|||
hess = DMatrix::from_columns(hess_cols.as_slice());
|
||||
|
||||
// regularize the Hessian
|
||||
let min_eigval = hess.symmetric_eigenvalues().min();
|
||||
let hess_eigvals = hess.symmetric_eigenvalues();
|
||||
let min_eigval = hess_eigvals.min();
|
||||
if min_eigval <= 0.0 {
|
||||
hess -= reg_scale * min_eigval * DMatrix::identity(total_dim, total_dim);
|
||||
}
|
||||
history.min_eigval.push(min_eigval);
|
||||
history.hess_eigvals.push(hess_eigvals);
|
||||
|
||||
// project the negative gradient and negative Hessian onto the
|
||||
// orthogonal complement of the frozen subspace
|
||||
|
@ -480,30 +492,40 @@ pub fn realize_gram(
|
|||
if state.loss < tol { break; }
|
||||
|
||||
// compute the Newton step
|
||||
/* TO DO */
|
||||
/*
|
||||
we need to either handle or eliminate the case where the minimum
|
||||
eigenvalue of the Hessian is zero, so the regularized Hessian is
|
||||
singular. right now, this causes the Cholesky decomposition to return
|
||||
`None`, leading to a panic when we unrap
|
||||
we should change our regularization to ensure that the Hessian is
|
||||
is positive-definite, rather than just positive-semidefinite. ideally,
|
||||
that would guarantee the success of the Cholesky decomposition---
|
||||
although we'd still need the error-handling routine in case of
|
||||
numerical hiccups
|
||||
*/
|
||||
let base_step_stacked = hess.clone().cholesky().unwrap().solve(&neg_grad_stacked);
|
||||
let hess_cholesky = match hess.clone().cholesky() {
|
||||
Some(cholesky) => cholesky,
|
||||
None => return Realization {
|
||||
result: Err("Cholesky decomposition failed".to_string()),
|
||||
history
|
||||
}
|
||||
};
|
||||
let base_step_stacked = hess_cholesky.solve(&neg_grad_stacked);
|
||||
let base_step = base_step_stacked.reshape_generic(Dyn(element_dim), Dyn(assembly_dim));
|
||||
history.base_step.push(base_step.clone());
|
||||
|
||||
// use backtracking line search to find a better configuration
|
||||
match seek_better_config(
|
||||
if let Some((better_state, backoff_steps)) = seek_better_config(
|
||||
gram, &state, &base_step, neg_grad.dot(&base_step),
|
||||
min_efficiency, backoff, max_backoff_steps
|
||||
) {
|
||||
Some((better_state, backoff_steps)) => {
|
||||
state = better_state;
|
||||
history.backoff_steps.push(backoff_steps);
|
||||
},
|
||||
None => return (state.config, ConfigSubspace::zero(assembly_dim), false, history)
|
||||
state = better_state;
|
||||
history.backoff_steps.push(backoff_steps);
|
||||
} else {
|
||||
return Realization {
|
||||
result: Err("Line search failed".to_string()),
|
||||
history
|
||||
}
|
||||
};
|
||||
}
|
||||
let success = state.loss < tol;
|
||||
let tangent = if success {
|
||||
let result = if state.loss < tol {
|
||||
// express the uniform basis in the standard basis
|
||||
const UNIFORM_DIM: usize = 4;
|
||||
let total_dim_unif = UNIFORM_DIM * assembly_dim;
|
||||
|
@ -516,11 +538,13 @@ pub fn realize_gram(
|
|||
}
|
||||
|
||||
// find the kernel of the Hessian. give it the uniform inner product
|
||||
ConfigSubspace::symmetric_kernel(hess, unif_to_std, assembly_dim)
|
||||
let tangent = ConfigSubspace::symmetric_kernel(hess, unif_to_std, assembly_dim);
|
||||
|
||||
Ok(ConfigNeighborhood { config: state.config, nbhd: tangent })
|
||||
} else {
|
||||
ConfigSubspace::zero(assembly_dim)
|
||||
Err("Failed to reach target accuracy".to_string())
|
||||
};
|
||||
(state.config, tangent, success, history)
|
||||
Realization { result, history }
|
||||
}
|
||||
|
||||
// --- tests ---
|
||||
|
@ -539,7 +563,7 @@ pub mod examples {
|
|||
// "Japan's 'Wasan' Mathematical Tradition", by Abe Haruki
|
||||
// https://www.nippon.com/en/japan-topics/c12801/
|
||||
//
|
||||
pub fn realize_irisawa_hexlet(scaled_tol: f64) -> (DMatrix<f64>, ConfigSubspace, bool, DescentHistory) {
|
||||
pub fn realize_irisawa_hexlet(scaled_tol: f64) -> Realization {
|
||||
let mut problem = ConstraintProblem::from_guess(
|
||||
[
|
||||
sphere(0.0, 0.0, 0.0, 15.0),
|
||||
|
@ -590,7 +614,7 @@ pub mod examples {
|
|||
|
||||
// set up a kaleidocycle, made of points with fixed distances between them,
|
||||
// and find its tangent space
|
||||
pub fn realize_kaleidocycle(scaled_tol: f64) -> (DMatrix<f64>, ConfigSubspace, bool, DescentHistory) {
|
||||
pub fn realize_kaleidocycle(scaled_tol: f64) -> Realization {
|
||||
const N_HINGES: usize = 6;
|
||||
let mut problem = ConstraintProblem::from_guess(
|
||||
(0..N_HINGES).step_by(2).flat_map(
|
||||
|
@ -714,10 +738,10 @@ mod tests {
|
|||
}
|
||||
problem.frozen.push(3, 0, problem.guess[(3, 0)]);
|
||||
problem.frozen.push(3, 1, 0.5);
|
||||
let (config, _, success, history) = realize_gram(
|
||||
let Realization { result, history } = realize_gram(
|
||||
&problem, 1.0e-12, 0.5, 0.9, 1.1, 200, 110
|
||||
);
|
||||
assert_eq!(success, true);
|
||||
let config = result.unwrap().config;
|
||||
for base_step in history.base_step.into_iter() {
|
||||
for &MatrixEntry { index, .. } in &problem.frozen {
|
||||
assert_eq!(base_step[index], 0.0);
|
||||
|
@ -732,7 +756,7 @@ mod tests {
|
|||
fn irisawa_hexlet_test() {
|
||||
// solve Irisawa's problem
|
||||
const SCALED_TOL: f64 = 1.0e-12;
|
||||
let (config, _, _, _) = realize_irisawa_hexlet(SCALED_TOL);
|
||||
let config = realize_irisawa_hexlet(SCALED_TOL).result.unwrap().config;
|
||||
|
||||
// check against Irisawa's solution
|
||||
let entry_tol = SCALED_TOL.sqrt();
|
||||
|
@ -759,11 +783,11 @@ mod tests {
|
|||
for n in 0..ELEMENT_DIM {
|
||||
problem.frozen.push(n, 0, problem.guess[(n, 0)]);
|
||||
}
|
||||
let (config, tangent, success, history) = realize_gram(
|
||||
let Realization { result, history } = realize_gram(
|
||||
&problem, SCALED_TOL, 0.5, 0.9, 1.1, 200, 110
|
||||
);
|
||||
let ConfigNeighborhood { config, nbhd: tangent } = result.unwrap();
|
||||
assert_eq!(config, problem.guess);
|
||||
assert_eq!(success, true);
|
||||
assert_eq!(history.scaled_loss.len(), 1);
|
||||
|
||||
// list some motions that should form a basis for the tangent space of
|
||||
|
@ -831,8 +855,8 @@ mod tests {
|
|||
fn tangent_test_kaleidocycle() {
|
||||
// set up a kaleidocycle and find its tangent space
|
||||
const SCALED_TOL: f64 = 1.0e-12;
|
||||
let (config, tangent, success, history) = realize_kaleidocycle(SCALED_TOL);
|
||||
assert_eq!(success, true);
|
||||
let Realization { result, history } = realize_kaleidocycle(SCALED_TOL);
|
||||
let ConfigNeighborhood { config, nbhd: tangent } = result.unwrap();
|
||||
assert_eq!(history.scaled_loss.len(), 1);
|
||||
|
||||
// list some motions that should form a basis for the tangent space of
|
||||
|
@ -920,11 +944,11 @@ mod tests {
|
|||
problem_orig.gram.push_sym(0, 0, 1.0);
|
||||
problem_orig.gram.push_sym(1, 1, 1.0);
|
||||
problem_orig.gram.push_sym(0, 1, 0.5);
|
||||
let (config_orig, tangent_orig, success_orig, history_orig) = realize_gram(
|
||||
let Realization { result: result_orig, history: history_orig } = realize_gram(
|
||||
&problem_orig, SCALED_TOL, 0.5, 0.9, 1.1, 200, 110
|
||||
);
|
||||
let ConfigNeighborhood { config: config_orig, nbhd: tangent_orig } = result_orig.unwrap();
|
||||
assert_eq!(config_orig, problem_orig.guess);
|
||||
assert_eq!(success_orig, true);
|
||||
assert_eq!(history_orig.scaled_loss.len(), 1);
|
||||
|
||||
// find another pair of spheres that meet at 120°. we'll think of this
|
||||
|
@ -941,11 +965,11 @@ mod tests {
|
|||
guess: guess_tfm,
|
||||
frozen: problem_orig.frozen
|
||||
};
|
||||
let (config_tfm, tangent_tfm, success_tfm, history_tfm) = realize_gram(
|
||||
let Realization { result: result_tfm, history: history_tfm } = realize_gram(
|
||||
&problem_tfm, SCALED_TOL, 0.5, 0.9, 1.1, 200, 110
|
||||
);
|
||||
let ConfigNeighborhood { config: config_tfm, nbhd: tangent_tfm } = result_tfm.unwrap();
|
||||
assert_eq!(config_tfm, problem_tfm.guess);
|
||||
assert_eq!(success_tfm, true);
|
||||
assert_eq!(history_tfm.scaled_loss.len(), 1);
|
||||
|
||||
// project a nudge to the tangent space of the solution variety at the
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
mod add_remove;
|
||||
mod assembly;
|
||||
mod diagnostics;
|
||||
mod display;
|
||||
mod engine;
|
||||
mod outline;
|
||||
|
@ -13,6 +14,7 @@ use sycamore::prelude::*;
|
|||
|
||||
use add_remove::AddRemove;
|
||||
use assembly::{Assembly, Element};
|
||||
use diagnostics::Diagnostics;
|
||||
use display::Display;
|
||||
use outline::Outline;
|
||||
|
||||
|
@ -60,6 +62,7 @@ fn main() {
|
|||
div(id="sidebar") {
|
||||
AddRemove {}
|
||||
Outline {}
|
||||
Diagnostics {}
|
||||
}
|
||||
Display {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue