Robust losses¶
The loss and f_scale arguments of least_squares() and
least_squares_system(), and the same cost as a differentiable function.
- piazzi.robust_cost(r, loss='linear', f_scale=1.0)[source]¶
Robust least-squares cost
0.5 * sum(f_scale^2 * rho((r / f_scale)^2)).This is the cost that
piazzi.least_squares()minimises, written so that autograd can differentiate it. Use it withpiazzi.minimize()orpiazzi.lbfgs()to minimise the same cost without a Jacobian.- Parameters:
r (
torch.Tensor) – residuals, of any shape.loss (
strorCallable, optional) – a name frompiazzi.LOSSES, or a callablerho(z)written in PyTorch and applied elementwise. Default:"linear"f_scale (
float, optional) – soft margin between inlier and outlier residuals, in the units ofr. Default:1.0
- Returns:
Tensor – the cost, a scalar tensor.
Example:
>>> r = torch.tensor([0.1, -0.2, 3.0]) >>> piazzi.robust_cost(r) tensor(4.5250) >>> piazzi.robust_cost(r, loss="huber", f_scale=0.5) tensor(1.4000)
- piazzi.LOSSES: dict[str, Callable]¶
The built-in robust losses by name:
"linear","huber","soft_l1","cauchy"and"arctan", as inscipy.optimize.least_squares(). Each mapszto(rho(z), rho'(z), rho''(z))in closed form, so the normal equations need no autograd.