Set-based loss API
Combine centre classification with an output-enclosure size penalty.
The objective weights centre cross-entropy by 1 - tau and the norm of the output generators and independent radii by tau. The enclosure term is normalised by the number of classes and the scheduled raw-input eps. At eps=0, the function returns ordinary centre cross-entropy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Supported sequential network. |
required |
data
|
Tensor
|
Nominal batch in model coordinates. |
required |
target
|
Tensor
|
Integer class labels. |
required |
eps
|
float
|
Perturbation radius in model input coordinates. |
required |
radius
|
Tensor
|
Scheduled radius in model coordinates. |
required |
data_min
|
Tensor
|
Lower input-domain limit in model coordinates. |
required |
data_max
|
Tensor
|
Upper input-domain limit in model coordinates. |
required |
tau
|
float
|
Enclosure-penalty weight in [0, 1]. |
0.1
|
input_set
|
str
|
Training input representation: 'box' or an attack-generated 'zonotope'. |
'box'
|
num_generators
|
int
|
Number of attack directions. |
8
|
error_propagation
|
str
|
'interval' or 'generators' for nonlinear errors. |
'interval'
|
pgd_eps_factor
|
float
|
Positive attack-search scaling factor. |
1.0
|
bn_statistics
|
dict
|
Clean batch statistics shared with propagation. |
None
|
layers
|
list
|
Previously validated sequential layers. |
None
|
input_zonotope
|
Zonotope
|
Explicit training enclosure overriding set construction at positive eps. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Scalar set-based training loss. |
Source code in CTRAIN/train/certified/losses/set_based.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
Construct a contained input zonotope from random-start FGSM directions.
Attack points are fitted coordinatewise to the nominal clipped input box. Scaling the search radius changes candidate generation, while the resulting zonotope remains within the nominal box. The construction returns detached centres and generators for subsequent differentiable propagation.
Source code in CTRAIN/train/certified/losses/set_based.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |