deel.lip.normalizers
This module contains computation function, for Bjorck and spectral normalization. This is done for internal use only.
bjorck_normalization ¶
bjorck_normalization(
w,
eps=DEFAULT_EPS_BJORCK,
beta=DEFAULT_BETA_BJORCK,
maxiter=DEFAULT_MAXITER_BJORCK,
)
apply Bjorck normalization on w.
PARAMETER | DESCRIPTION |
---|---|
w |
weight to normalize, in order to work properly, we must have max_eigenval(w) ~= 1
TYPE:
|
eps |
epsilon stopping criterion: norm(wt - wt-1) must be less than eps
TYPE:
|
beta |
beta used in each iteration, must be in the interval ]0, 0.5]
TYPE:
|
maxiter |
maximum number of iterations for the algorithm
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tf.Tensor: the orthonormal weights |
Source code in deel/lip/normalizers.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
get_conv_operators ¶
get_conv_operators(
kernel,
u_shape,
stride=1.0,
conv_first=True,
pad_func=None,
)
Return two functions corresponding to the linear convolution operator and its adjoint.
PARAMETER | DESCRIPTION |
---|---|
kernel |
the convolution kernel to normalize
TYPE:
|
u_shape |
shape of a singular vector (as a 4D tensor).
TYPE:
|
stride |
stride parameter of convolutions. Defaults to 1.
TYPE:
|
conv_first |
RO or CO case , should be True in CO case (stride^2*C<M). Defaults to True.
TYPE:
|
pad_func |
function for applying padding (None is padding same). Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
two functions for the linear convolution operator and its adjoint operator. |
Source code in deel/lip/normalizers.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
reshaped_kernel_orthogonalization ¶
reshaped_kernel_orthogonalization(
kernel,
u,
adjustment_coef,
eps_spectral=DEFAULT_EPS_SPECTRAL,
eps_bjorck=DEFAULT_EPS_BJORCK,
beta=DEFAULT_BETA_BJORCK,
maxiter_spectral=DEFAULT_MAXITER_SPECTRAL,
maxiter_bjorck=DEFAULT_MAXITER_BJORCK,
)
Perform reshaped kernel orthogonalization (RKO) to the kernel given as input. It apply the power method to find the largest singular value and apply the Bjorck algorithm to the rescaled kernel. This greatly improve the stability and and speed convergence of the bjorck algorithm.
PARAMETER | DESCRIPTION |
---|---|
kernel |
the kernel to orthogonalize
TYPE:
|
u |
the vector used to do the power iteration method
TYPE:
|
adjustment_coef |
the adjustment coefficient as used in convolution
TYPE:
|
eps_spectral |
stopping criterion in spectral algorithm
TYPE:
|
eps_bjorck |
stopping criterion in bjorck algorithm
TYPE:
|
beta |
the beta used in the bjorck algorithm
TYPE:
|
maxiter_spectral |
maximum number of iterations for the power iteration
TYPE:
|
maxiter_bjorck |
maximum number of iterations for bjorck algorithm
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tf.Tensor: the orthogonalized kernel, the new u, and sigma which is the largest singular value |
Source code in deel/lip/normalizers.py
65 66 67 68 69 70 71 72 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 |
|
set_stop_grad_spectral ¶
set_stop_grad_spectral(value)
Set the global STOP_GRAD_SPECTRAL to values. This function must be called before
constructing the model (first call of reshaped_kernel_orthogonalization
) in
order to be accounted.
PARAMETER | DESCRIPTION |
---|---|
value |
boolean, when set to True, disable back-propagation through the power iteration algorithm. The back-propagation will account how updates affects the maximum singular value but not how it affects the largest singular vector. When set to False, back-propagate through the while loop.
TYPE:
|
Source code in deel/lip/normalizers.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
set_swap_memory ¶
set_swap_memory(value)
Set the global SWAP_MEMORY to values. This function must be called before
constructing the model (first call of reshaped_kernel_orthogonalization
) in
order to be accounted.
PARAMETER | DESCRIPTION |
---|---|
value |
boolean that will be used as the swap_memory parameter in while loops in spectral and bjorck algorithms.
TYPE:
|
Source code in deel/lip/normalizers.py
23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
spectral_normalization ¶
spectral_normalization(
kernel,
u,
eps=DEFAULT_EPS_SPECTRAL,
maxiter=DEFAULT_MAXITER_SPECTRAL,
)
Normalize the kernel to have its maximum singular value equal to 1.
PARAMETER | DESCRIPTION |
---|---|
kernel |
the kernel to normalize, assuming a 2D kernel.
TYPE:
|
u |
initialization of the maximum singular vector.
TYPE:
|
eps |
stopping criterion of the algorithm, when norm(u[t] - u[t-1]) is less than eps. Defaults to DEFAULT_EPS_SPECTRAL.
TYPE:
|
maxiter |
maximum number of iterations for the algorithm. Defaults to DEFAULT_MAXITER_SPECTRAL.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
the normalized kernel, the maximum singular vector, and the maximum singular value. |
Source code in deel/lip/normalizers.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
spectral_normalization_conv ¶
spectral_normalization_conv(
kernel,
u,
stride=1.0,
conv_first=True,
pad_func=None,
eps=DEFAULT_EPS_SPECTRAL,
maxiter=DEFAULT_MAXITER_SPECTRAL,
)
Normalize the convolution kernel to have its max eigenvalue == 1.
PARAMETER | DESCRIPTION |
---|---|
kernel |
the convolution kernel to normalize
TYPE:
|
u |
initialization for the max eigen vector (as a 4d tensor)
TYPE:
|
stride |
stride parameter of convolutions
TYPE:
|
conv_first |
RO or CO case , should be True in CO case (stride^2*C<M)
TYPE:
|
pad_func |
function for applying padding (None is padding same)
TYPE:
|
eps |
epsilon stopping criterion: norm(ut - ut-1) must be less than eps
TYPE:
|
maxiter |
maximum number of iterations for the power iteration algorithm.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
the normalized kernel w_bar, the maximum eigen vector, and the maximum eigen value |
Source code in deel/lip/normalizers.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|