API reference

Everything below is importable from piazzi, except the optional backends in piazzi.scipy, piazzi.pypose and piazzi.torchmin. Start with the high-level interfaces; the method-specific solvers are the algorithms they run, for when you need a method’s full control.

High-level interfaces

SciPy-style entry points: give residuals or a scalar objective, choose the method by name. finite_difference() wraps an objective that autograd cannot differentiate.

least_squares

Minimise a sum of squared residuals, like scipy.optimize.least_squares().

minimize

Minimise a scalar function of a tensor, like scipy.optimize.minimize().

finite_difference

Make a black-box function look differentiable, so that any solver can use it.

The methods minimize() knows by name are in MINIMIZE_METHODS.

Method-specific solvers

The algorithms behind the interfaces, with every setting exposed. Use them directly when you build the normal equations yourself.

gauss_newton

Gauss-Newton or Levenberg-Marquardt on user-supplied normal equations.

levenberg_marquardt

Levenberg-Marquardt: piazzi.gauss_newton() with method="lm".

lbfgs

Minimise a scalar function with L-BFGS and a line search.

least_squares_system

Build normal equations from residuals, for piazzi.gauss_newton().

Results and callbacks

OptimizeResult

Outcome of a solver run, returned by every solver and wrapper.

IterationInfo

State of a solver run, passed to callback after every iteration, accepted or not.

print_progress

Make a callback that prints a table of the solver's progress, one row per iteration.

Robust losses

robust_cost

Robust least-squares cost 0.5 * sum(f_scale^2 * rho((r / f_scale)^2)).

The built-in losses by name are in LOSSES.

Manifolds and Lie groups

Manifold

Base class for manifolds: a parameter set with a retraction plus.

Euclidean

Plain vector space, with plus(x, delta) = x + delta.

Subset

A vector with some entries held fixed, like Ceres Solver's SubsetManifold.

SO3

Rotations, stored as (3, 3) matrices, with 3 degrees of freedom.

SE3

Rigid transforms, stored as (4, 4) matrices [[R, t], [0, 1]], with 6 degrees of freedom.

Product

Cartesian product of manifolds, stored as one flat vector with the blocks concatenated.

so3_exp

SO(3) exponential: the rotation matrix of a rotation vector (Rodrigues' formula).

so3_log

SO(3) logarithm: the rotation vector of a rotation matrix; inverts piazzi.so3_exp().

so3_hat

Skew-symmetric (cross-product) matrix of a vector, with hat(w) @ v == cross(w, v).

se3_exp

SE(3) exponential: the rigid transform of a twist.

se3_log

SE(3) logarithm: the twist of a rigid transform; inverts piazzi.se3_exp().

Linear solvers

dense_solver

Solve the damped normal equations directly, with torch.linalg.solve().

cg_solver

Make a preconditioned conjugate-gradient solver for large sparse normal equations.

Custom solvers follow the LinearSolver signature.

SciPy backend

Requires the piazzi[scipy] extra.

least_squares

Run scipy.optimize.least_squares() on a residual function written in PyTorch.

minimize

Run scipy.optimize.minimize() on a scalar function written in PyTorch.

t2n

Convert a tensor to a float64 NumPy array, as the SciPy wrappers do.

n2t

Convert an array-like to a tensor, as the SciPy wrappers do.

PyPose backend

Requires the piazzi[pypose] extra.

least_squares

Minimise a sum of squared residuals with PyPose's Gauss-Newton or Levenberg-Marquardt.

pytorch-minimize backend

Requires the piazzi[torchmin] extra.

minimize

Run torchmin.minimize (pytorch-minimize) on a scalar function written in PyTorch.