Loss Functions API Reference
AutoLens provides two categories of loss functions: optimization losses (used during lens design) and PSF quality losses (neural network modules).
Optimization Losses
These are methods on GeoLensOptim (accessible via GeoLens). All return scalar tensors suitable for backpropagation.
loss_rms()
Primary optimization target. Computes RGB spot RMS error across sampled field positions, with optional error-adaptive field weighting.
loss_infocus()
Penalizes on-axis defocus when RMS exceeds a threshold:
loss_reg()
Composite regularization loss:
loss_surface()
Penalizes extreme surface shapes via three sub-penalties:
| Sub-penalty | Constraint | Description |
|---|---|---|
| Sag / diameter | \(\text{sag} / \text{diam} < 0.1\) | Prevents overly curved surfaces |
| Gradient | \(\|\nabla z\| < \tan(30°)\) | Limits surface steepness |
| D / T ratio | \(\text{diam} / \text{thickness} < 15\) | Prevents thin, wide elements |
loss_intersec()
Prevents surfaces from intersecting each other:
loss_thickness()
Enforces air gap, glass thickness, back focal length, and total track length constraints.
Cellphone lens constraints (\(r_{\text{sensor}} < 12\) mm):
| Parameter | Min (mm) | Max (mm) |
|---|---|---|
| Air gap (center) | 0.025 | 1.5 |
| Air gap (edge) | 0.025 | 3.0 |
| Glass (center) | 0.25 | 3.0 |
| Glass (edge) | 0.25 | 2.0 |
| BFL | 0.8 | 3.0 |
| TTL | — | 15 |
Camera lens constraints (\(r_{\text{sensor}} \geq 12\) mm): significantly looser bounds (air gaps up to 100 mm, TTL up to 300 mm).
loss_ray_angle()
Constrains chief ray angle at the sensor to prevent extreme incidence:
Default maximum: \(30°\) for cellphone, \(40°\) for camera lenses.
loss_mat()
Constrains material parameters during optimization:
PSF Quality Losses
Neural network modules (nn.Module) for evaluating PSF quality.
PSFLoss
src.loss.PSFLoss
Combines spatial concentration loss (variance of PSF spatial distribution) with achromatic loss (inter-channel PSF difference). Minimized during optimization.
PSFStrehlLoss
src.loss.PSFStrehlLoss
Bases: Module
forward
Compute Strehl-like score for PSFs with shape [B, 3, ks, ks].
The score is the center-pixel intensity after per-channel spatial normalization (sum over HxW equals 1), averaged over channels and batch. This value should be maximized during optimization.
Source code in src/loss.py
Strehl ratio proxy — center pixel intensity after normalization. Maximized during optimization (negate for gradient descent).