Loss function¶
Loss functions are a central element of any inverse problem formulation. We
define ours as children of the base Loss class, which provides a common
interface to evaluate the loss. The Loss class overrides the __call__
method, which allows to call it as if it were a regular function:
loss_fn = L2Loss({'reduction': 'sum'})
loss = loss_fn(y, target, patterns)
As for other plugins, the loss parameters are passed as a dictionary to the constructor of the loss class.
The following parameters are common to all loss functions:
Key |
Type |
Description |
|---|---|---|
|
|
Most objective functions compute a loss per voxel, which is then
aggregated over the entire volume. The |
Reference value¶
The reference expected by the loss object differs depending on the choice of discretization (see Film). In the case of binary discretization, the reference is a single channel binary mask, while in the case of surface-aware discretization, the reference is a 2-channel tensor, containing the fractional volumes of the “inside” and “outside” sub-regions of each voxel. For both cases, the first 3 dimensions of the reference tensor should match the resolution of the film.
Supported objective functions¶
L2 Loss (L2Loss)¶
This loss function computes the squared error between the predicted and target
values.
It requires no additional parameter. We do not recommend using this loss as
the ThresholdedLoss provides better results and allows for finer control.
Thresholded loss (ThresholdedLoss)¶
This loss function uses two thresholds to penalize different parts of the predicted volume:
Non-object voxels whose recorded dose is higher than a lower threshold
tlare penalizedobject voxels whose recorded dose is lower than an upper threshold
tu > tlare penalized.Finally, object voxels whose recorded dose is higher than
1.0are also penalized, to avoid some regions being overexposed.Additionally, a sparsity loss can be added to increase the overall energy efficiency of the patterns. We prefer homogenous patterns without spiking values since those reduce the overall energy of the patterns.
With 'sum' reduction, its full expression is:
where $v_i$ is the intensity value at voxel $i$. This objective function was introduced by Wechsler et al. [2024].
It requires the following additional parameters:
Key |
Type |
Description |
|---|---|---|
|
|
The power to which to raise the error. Defaults to |
|
|
The power to which to raise the pattern values. Defaults to |
|
|
The lower threshold, in |
|
|
The upper threshold, in |
|
|
Weight of the object term. Defaults to |
|
|
Weight of the void term. Defaults to |
|
|
Weight of the overpolymerization term. Defaults to |
|
|
Weight of the sparsity term. Defaults to |