Skip to content

Optimization (bounded)

vertax.opt_bounded

Optimization methods for VertAX (bounded version).

T1Resets

Bases: NamedTuple

What one relaxation with T1TensionReset did to the line tensions.

he_params instance-attribute

he_params: Array

Edge parameters at the end of the relaxation, after every reset.

flips instance-attribute

flips: Array

Number of T1 transitions accepted on each edge during the relaxation (each one reset that edge).

T1ResetReport

Bases: NamedTuple

Line-tension resets during one outer step with T1TensionReset.

The outer update is applied to he_params, the parameters after the resets of the estimator's relaxation, so that a junction created by a T1 keeps its reset tension in the design.

he_params instance-attribute

he_params: Array

Post-reset edge parameters the outer update was applied to.

flips instance-attribute

flips: tuple[Array, ...]

Accepted T1 transitions per edge, one array per relaxation of the estimator (two for EP).

nudged_mismatch instance-attribute

nudged_mismatch: int

EP only: number of edges whose post-reset parameter differs between the two solves. When it is not 0, each solve's gradient is taken at its own post-reset parameters and the update is applied to those of the free solve (at -beta, or 0 for the one-sided variant), whose state is returned; the two halves of the EP difference then refer to different parameters, so the estimate is not a difference of one map. Always 0 for the other estimators.

inner_opt_bounded

inner_opt_bounded(vertTable: Array, angTable: Array, heTable: Array, faceTable: Array, vert_params: Array, he_params: Array, face_params: Array, L_in: InnerLossFunctionBounded, solver: GradientTransformation, min_dist_T1: float, iterations_max: int = 1000, tolerance: float = 0.0001, patience: int = 5, selected_verts: Array | None = None, selected_hes: Array | None = None, selected_faces: Array | None = None, update_T1_func: UpdateT1FuncBounded = update_T1_bounded, perform_energy_check: bool = False, cap_vertex_step: bool = False, reset_solver_on_t1: bool = False, tension_reset: T1TensionReset | None = None) -> tuple[tuple[Array, Array, Array, Array], Array] | tuple[tuple[Array, Array, Array, Array], Array, T1Resets]

Inner optimization for a bounded mesh.

Use cap_vertex_step=True with line-search solvers, and reset_solver_on_t1=True with optax.lbfgs(), whose curvature pairs otherwise outlive the topology they were measured on.

Parameters:

Name Type Description Default
cap_vertex_step bool

Clip each per-step vertex displacement to MAX_VERTEX_STEP_FACTOR * min_dist_T1. Intended for line-search solvers (cg_linesearch, gd_linesearch, lbfgs), which choose their own step size and can otherwise move a vertex across whole cells in one iteration. Off by default, so fixed-step solvers (adam, sgd) are untouched.

False
reset_solver_on_t1 bool

Re-initialise the solver state at the new vertex positions and arc angles after every iteration whose T1 step changed the topology. Off by default.

False
tension_reset T1TensionReset | None

Give every edge created by a T1 the mean tension of its kind (T1TensionReset). Off by default. When set, a third value is returned, a T1Resets with the edge parameters after the resets and the transitions accepted on each edge.

None

cost_ad_bounded

cost_ad_bounded(vertTable: Array, angTable: Array, heTable: Array, faceTable: Array, vert_params: Array, he_params: Array, face_params: Array, vertTable_target: Array | None, angTable_target: Array | None, heTable_target: Array | None, faceTable_target: Array | None, L_in: InnerLossFunctionBounded, L_out: OuterLossFunction, solver_inner: GradientTransformation, min_dist_T1: float, iterations_max: int = 1000, tolerance: float = 0.0001, patience: int = 5, selected_verts: Array | None = None, selected_hes: Array | None = None, selected_faces: Array | None = None, image_target: Array | None = None, update_T1_func: UpdateT1FuncBounded = update_T1_bounded, cap_vertex_step: bool = False, tension_reset: T1TensionReset | None = None) -> tuple[Array, tuple[Array, Array, Array, Array]] | tuple[Array, tuple[Array, Array, Array, Array, T1Resets]]

Automatic differentiation cost function.

With tension_reset, the relaxation resets the tension of every edge a T1 creates, and the derivative is taken through those resets; the auxiliary output also holds the T1Resets.

outer_opt_bounded

outer_opt_bounded(vertTable: Array, angTable: Array, heTable: Array, faceTable: Array, vert_params: Array, he_params: Array, face_params: Array, vertTable_target: Array | None, angTable_target: Array | None, heTable_target: Array | None, faceTable_target: Array | None, L_in: InnerLossFunctionBounded, L_out: OuterLossFunction, solver_inner: GradientTransformation, solver_outer: GradientTransformation, min_dist_T1: float, iterations_max: int = 1000, tolerance: float = 0.0001, patience: int = 5, selected_verts: Array | None = None, selected_hes: Array | None = None, selected_faces: Array | None = None, image_target: Array | None = None, update_T1_func: UpdateT1FuncBounded = update_T1_bounded, params_regularizer: Callable | None = None, cap_vertex_step: bool = False, tension_reset: T1TensionReset | None = None) -> tuple[Array, Array, Array, Array, Array, Array, Array] | tuple[Array, Array, Array, Array, Array, Array, Array, T1ResetReport]

Outer optimization for a bounded mesh.

Returns the tables (vertices, angles, edges, faces) of the inner equilibrium and the updated parameters. With tension_reset, the gradient is the derivative through the relaxation and its resets, the update is applied to the post-reset parameters, and a T1ResetReport is returned as an eighth value.

inner_eq_prop_bounded

inner_eq_prop_bounded(vertTable: Array, angTable: Array, heTable: Array, faceTable: Array, vert_params: Array, he_params: Array, face_params: Array, loss_ep_static_bounded: LossEPFunction, vertTable_target: Array | None, angTable_target: Array | None, heTable_target: Array | None, faceTable_target: Array | None, L_in: InnerLossFunctionBounded, L_out: OuterLossFunction, solver_inner: GradientTransformation, min_dist_T1: float, iterations_max: int, tolerance: float, patience: int, selected_verts: Array | None, selected_hes: Array | None, selected_faces: Array | None, image_target: Array | None, beta: float, update_T1_func: UpdateT1FuncBounded = update_T1_bounded, perform_energy_check: bool = False, cap_vertex_step: bool = False, tension_reset: T1TensionReset | None = None) -> tuple[tuple[Array, Array, Array, Array], Array] | tuple[tuple[Array, Array, Array, Array], Array, T1Resets]

Inner optimization function for equilibrium propagation only and bounded meshes.

With tension_reset, a third value is returned, as for inner_opt_bounded.

outer_eq_prop_bounded

outer_eq_prop_bounded(vertTable: Array, angTable: Array, heTable: Array, faceTable: Array, vert_params: Array, he_params: Array, face_params: Array, vertTable_target: Array | None, angTable_target: Array | None, heTable_target: Array | None, faceTable_target: Array | None, L_in: InnerLossFunctionBounded, L_out: OuterLossFunction, solver_inner: GradientTransformation, solver_outer: GradientTransformation, min_dist_T1: float, iterations_max: int, tolerance: float, patience: int, selected_verts: Array | None, selected_hes: Array | None, selected_faces: Array | None, image_target: Array | None, beta: float, update_T1_func: UpdateT1FuncBounded = update_T1_bounded, params_regularizer: Callable | None = None, ep_variant: EPVariant = EPVariant.CENTERED, cap_vertex_step: bool = False, tension_reset: T1TensionReset | None = None) -> tuple[Array, Array, Array, Array, Array, Array, Array] | tuple[Array, Array, Array, Array, Array, Array, Array, T1ResetReport]

Outer optimization for equilibrium propagation.

ep_variant selects the estimator, as in the periodic vertax.opt._compute_ep_grads: CENTERED (default) solves at -beta and +beta and divides by 2 * beta; ONE_SIDED solves at 0 and +beta and divides by beta. The returned tables are those of the free solve. params_regularizer(vert_params, he_params, face_params) -> scalar, if given, has its gradient added to the EP gradient before the outer solver's update.

With tension_reset, each of the two solves resets the tension of the edges its T1 transitions create, and each half of the EP difference is evaluated at its own solve's post-reset parameters. When the two solves end with the same parameters this is the EP estimate at those parameters; when they do not (a T1 in one solve and not in the other), the mismatch is counted in the returned T1ResetReport (eighth value) rather than mixed in silently. The update is applied to the post-reset parameters of the free solve, whose state is returned.

Returns the tables (vertices, angles, edges, faces) of the free solve and the updated parameters.

outer_implicit_bounded

outer_implicit_bounded(vertTable: Array, angTable: Array, heTable: Array, faceTable: Array, vert_params: Array, he_params: Array, face_params: Array, vertTable_target: Array | None, angTable_target: Array | None, heTable_target: Array | None, faceTable_target: Array | None, L_in: InnerLossFunctionBounded, L_out: OuterLossFunction, solver_inner: GradientTransformation, solver_outer: GradientTransformation, min_dist_T1: float, iterations_max: int, tolerance: float, patience: int, selected_verts: Array | None, selected_hes: Array | None, selected_faces: Array | None, image_target: Array | None, update_T1_func: UpdateT1FuncBounded = update_T1_bounded, params_regularizer: Callable | None = None, cap_vertex_step: bool = False, tension_reset: T1TensionReset | None = None) -> tuple[Array, Array, Array, Array, Array, Array, Array] | tuple[Array, Array, Array, Array, Array, Array, Array, T1ResetReport]

Outer optimization for implicit differentiation method.

Returns the tables (vertices, angles, edges, faces) of the inner equilibrium and the updated parameters. With tension_reset, the derivatives are taken at the post-reset parameters of the relaxation, the update is applied to them, and a T1ResetReport is returned as an eighth value.

outer_adjoint_state_bounded

outer_adjoint_state_bounded(vertTable: Array, angTable: Array, heTable: Array, faceTable: Array, vert_params: Array, he_params: Array, face_params: Array, vertTable_target: Array | None, angTable_target: Array | None, heTable_target: Array | None, faceTable_target: Array | None, L_in: InnerLossFunctionBounded, L_out: OuterLossFunction, solver_inner: GradientTransformation, solver_outer: GradientTransformation, min_dist_T1: float, iterations_max: int, tolerance: float, patience: int, selected_verts: Array | None, selected_hes: Array | None, selected_faces: Array | None, image_target: Array | None, update_T1_func: UpdateT1FuncBounded = update_T1_bounded, params_regularizer: Callable | None = None, cap_vertex_step: bool = False, tension_reset: T1TensionReset | None = None) -> tuple[Array, Array, Array, Array, Array, Array, Array] | tuple[Array, Array, Array, Array, Array, Array, Array, T1ResetReport]

Outer optimization for adjoint state method.

Returns the tables (vertices, angles, edges, faces) it was given, unchanged, and the updated parameters. With tension_reset, the derivatives are taken at the post-reset parameters of the relaxation, the update is applied to them, the relaxed tables are returned instead (the post-reset parameters belong to the topology the relaxation reached), and a T1ResetReport is returned as an eighth value.

bilevel_opt_bounded

bilevel_opt_bounded(vertTable: Array, angTable: Array, heTable: Array, faceTable: Array, vert_params: Array, he_params: Array, face_params: Array, vertTable_target: Array | None, angTable_target: Array | None, heTable_target: Array | None, faceTable_target: Array | None, L_in: InnerLossFunctionBounded, L_out: OuterLossFunction, solver_inner: GradientTransformation, solver_outer: GradientTransformation, min_dist_T1: float, iterations_max: int, tolerance: float, patience: int, selected_verts: Array | None, selected_hes: Array | None, selected_faces: Array | None, image_target: Array | None, beta: float = 0.001, optimization_method: BilevelOptimizationMethod = BilevelOptimizationMethod.AUTOMATIC_DIFFERENTIATION, update_T1_func: UpdateT1FuncBounded = update_T1_bounded) -> tuple[tuple[Array, Array, Array, Array, Array, Array, Array], Array]

Bilevel optimization for bounded meshes.