learnable_filters
¶
Learnable filters for custom decompositions.
Classes:
-
LearnableParsevalFilterBank–Base class for learnable filterbanks living in the Stiefel manifold.
-
ParsevalFilterBankND–N-dimensional Parseval filterbank.
Functions:
-
train_sparsity–Learn orthonormal filterbank (in the Stiefel manifold) by minimizing the l_1-norm of analysis coefficients.
LearnableParsevalFilterBank
¶
LearnableParsevalFilterBank(
k: int,
n_dims: int = 2,
in_ch: int = 1,
m: int | None = None,
shape_ref: Sequence[int] | None = None,
norm: (
Literal["backward", "forward", "ortho"] | None
) = "backward",
)
Bases: ConvolutionalDecompositionBase
Base class for learnable filterbanks living in the Stiefel manifold.
Parameters:
-
k(int) –Filter spatial size, k ** n_dims.
-
n_dims(int, default:2) –Number of dimensions (default is 2).
-
in_ch(int, default:1) –Input channels (1 = grayscale, default is 1).
-
m(int, default:None) –Total number of filters (including the constant one). If None, m is set to k**n_dims * in_ch.
-
shape_ref(Sequence[int] | None, default:None) –Reference image shape for Fourier penalty embedding (default is None).
-
norm(str | None, default:'backward') –Normalization type. Defaults to "backward".
Methods:
-
analyze–Apply the analysis (forward) transform using the kernels.
-
fourier_penalty–Return the Fourier penalty.
-
fourier_spectrum_penalty–Return the Fourier spectrum penalty.
-
get_custom_decomposition–Return a CustomFilterDecomposition object with the current kernels.
-
get_filter_freq–Return the main frequency associated to each filter, wrt the highest frequency.
-
get_filter_weights–Return the weights of the filters.
-
get_fourier_filter_power_spectrum–Return the Fourier power spectrum of the filters.
-
get_interior_error–Return the interior error.
-
get_kernels–Return the kernels for the convolutions.
-
gram_error–Return the Gram error.
-
plot_filters–Plot the filters.
-
print_diagnostics–Print diagnostics.
-
reconstruct–Reconstruct the input tensor using the current kernels.
-
synthesize–Apply the synthesis (inverse) transform using the kernels.
-
zero_mean_error–Return the zero mean error.
Source code in src/autoden/transforms/learnable_filters.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 | |
analyze
¶
analyze(x: Tensor) -> Tensor
Apply the analysis (forward) transform using the kernels.
Parameters:
-
x(Tensor) –Input tensor of shape (B, in_ch, [D, H], W).
Returns:
-
Tensor–Output tensor of shape (B, m, [D, H], W).
Source code in src/autoden/transforms/custom_filters.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
fourier_penalty
¶
fourier_penalty() -> Tensor
Return the Fourier penalty.
Returns:
-
Tensor–The Fourier penalty.
Notes
|| sum_i |hat{q}_i(w)|^2 - m ||^2 averaged over frequencies. Target is m because each filter has unit energy (condition A).
Source code in src/autoden/transforms/learnable_filters.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
fourier_spectrum_penalty
¶
fourier_spectrum_penalty(use_tanh: bool = False) -> Tensor
Return the Fourier spectrum penalty.
Parameters:
-
use_tanh(bool, default:False) –Whether to use tanh for the penalty (default is False).
Returns:
-
Tensor–The Fourier spectrum penalty.
Source code in src/autoden/transforms/learnable_filters.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
get_custom_decomposition
¶
get_custom_decomposition(
device: str | DeviceObjType | None = None,
) -> CustomFilterDecomposition
Return a CustomFilterDecomposition object with the current kernels.
Parameters:
-
device(str | DeviceObjType | None, default:None) –Device to use for the CustomFilterDecomposition (default is None).
Returns:
-
CustomFilterDecomposition–A CustomFilterDecomposition object with the current kernels.
Source code in src/autoden/transforms/learnable_filters.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
get_filter_freq
¶
get_filter_freq() -> NDArray
Return the main frequency associated to each filter, wrt the highest frequency.
Returns:
-
NDArray–The main frequency associated to each filter.
Source code in src/autoden/transforms/learnable_filters.py
123 124 125 126 127 128 129 130 131 | |
get_filter_weights
¶
get_filter_weights(ord: int = 2) -> NDArray
Return the weights of the filters.
Parameters:
-
ord(int, default:2) –Order of the norm (default is 2).
Returns:
-
NDArray–The weights of the filters.
Source code in src/autoden/transforms/learnable_filters.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_fourier_filter_power_spectrum
¶
get_fourier_filter_power_spectrum() -> Tensor
Return the Fourier power spectrum of the filters.
Returns:
-
Tensor–The Fourier power spectrum of the filters.
Source code in src/autoden/transforms/learnable_filters.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
get_interior_error
¶
get_interior_error(x_test: Tensor) -> float
Return the interior error.
Parameters:
-
x_test(Tensor) –Test tensor.
Returns:
-
float–The interior error.
Source code in src/autoden/transforms/learnable_filters.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
get_kernels
¶
get_kernels() -> Tensor
Return the kernels for the convolutions.
Returns:
-
Tensor–The kernels for the convolutions.
Notes
For 2D: (m, in_ch * k ** 2) -> (m, in_ch, k, k)
Source code in src/autoden/transforms/learnable_filters.py
109 110 111 112 113 114 115 116 117 118 119 120 121 | |
gram_error
¶
gram_error() -> float
Return the Gram error.
Returns:
-
float–The Gram error.
Source code in src/autoden/transforms/learnable_filters.py
260 261 262 263 264 265 266 267 268 269 270 | |
plot_filters
¶
Plot the filters.
Parameters:
-
fourier_space(bool, default:False) –Whether to plot the filters in Fourier space (default is False).
-
print_weights(bool, default:True) –Whether to print the weights of the filters (default is True).
Source code in src/autoden/transforms/learnable_filters.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
print_diagnostics
¶
print_diagnostics(x_test: Tensor, label: str = '')
Print diagnostics.
Parameters:
-
x_test(Tensor) –Test tensor.
-
label(str, default:'') –Label for the diagnostics (default is "").
Source code in src/autoden/transforms/learnable_filters.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
reconstruct
¶
reconstruct(x: Tensor) -> Tensor
Reconstruct the input tensor using the current kernels.
Parameters:
-
x(Tensor) –Input tensor.
Returns:
-
Tensor–Reconstructed tensor.
Notes
W^T Wx approx = x when both (A) and (B) hold.
Source code in src/autoden/transforms/learnable_filters.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
synthesize
¶
synthesize(c: Tensor) -> Tensor
Apply the synthesis (inverse) transform using the kernels.
Parameters:
-
c(Tensor) –Input tensor of shape (B, m, [D, H], W).
Returns:
-
Tensor–Output tensor of shape (B, in_ch, [D, H], W).
Source code in src/autoden/transforms/custom_filters.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
zero_mean_error
¶
zero_mean_error() -> float
Return the zero mean error.
Returns:
-
float–The zero mean error.
Notes
max |mean(q_i)| for i >= 1: should be ~0 (filters are q_0-orthogonal).
Source code in src/autoden/transforms/learnable_filters.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
ParsevalFilterBankND
¶
ParsevalFilterBankND(
k: int,
n_dims: int = 2,
in_ch: int = 1,
m: int | None = None,
shape_ref: Sequence[int] | None = None,
)
Bases: LearnableParsevalFilterBank
N-dimensional Parseval filterbank.
Parameters:
-
k(int) –Filter spatial size, k ** n_dims.
-
n_dims(int, default:2) –Number of dimensions (default is 2).
-
in_ch(int, default:1) –Input channels (1 = grayscale, default is 1).
-
m(int, default:None) –Total number of filters (including the constant one). If None, m is set to k**n_dims * in_ch.
-
shape_ref(Sequence[int] | None, default:None) –Reference image shape for Fourier penalty embedding (default is None).
Notes
The Parseval filterbank has the following properties: with: - Pinned constant first filter q_0 = 1/sqrt(k**n_dims * in_ch) - (m-1) learned filters in the q_0-orthogonal complement - FF^T = I_m enforced exactly via structured QR parametrisation - Spectral flatness (condition B) as optional soft penalty
Methods:
-
analyze–Apply the analysis (forward) transform using the kernels.
-
fourier_penalty–Return the Fourier penalty.
-
fourier_spectrum_penalty–Return the Fourier spectrum penalty.
-
get_F–Return F in R^{m x d} with FF^T = I_m and F[0] = q_0.
-
get_custom_decomposition–Return a CustomFilterDecomposition object with the current kernels.
-
get_filter_freq–Return the main frequency associated to each filter, wrt the highest frequency.
-
get_filter_weights–Return the weights of the filters.
-
get_fourier_filter_power_spectrum–Return the Fourier power spectrum of the filters.
-
get_interior_error–Return the interior error.
-
get_kernels–Return the kernels for the convolutions.
-
gram_error–Return the Gram error.
-
plot_filters–Plot the filters.
-
print_diagnostics–Print diagnostics.
-
reconstruct–Reconstruct the input tensor using the current kernels.
-
synthesize–Apply the synthesis (inverse) transform using the kernels.
-
zero_mean_error–Return the zero mean error.
Source code in src/autoden/transforms/learnable_filters.py
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 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
analyze
¶
analyze(x: Tensor) -> Tensor
Apply the analysis (forward) transform using the kernels.
Parameters:
-
x(Tensor) –Input tensor of shape (B, in_ch, [D, H], W).
Returns:
-
Tensor–Output tensor of shape (B, m, [D, H], W).
Source code in src/autoden/transforms/custom_filters.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
fourier_penalty
¶
fourier_penalty() -> Tensor
Return the Fourier penalty.
Returns:
-
Tensor–The Fourier penalty.
Notes
|| sum_i |hat{q}_i(w)|^2 - m ||^2 averaged over frequencies. Target is m because each filter has unit energy (condition A).
Source code in src/autoden/transforms/learnable_filters.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
fourier_spectrum_penalty
¶
fourier_spectrum_penalty(use_tanh: bool = False) -> Tensor
Return the Fourier spectrum penalty.
Parameters:
-
use_tanh(bool, default:False) –Whether to use tanh for the penalty (default is False).
Returns:
-
Tensor–The Fourier spectrum penalty.
Source code in src/autoden/transforms/learnable_filters.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
get_F
¶
get_F() -> Tensor
Return F in R^{m x d} with FF^T = I_m and F[0] = q_0.
F[0] = q_0 (constant, fixed) F[1:] = G @ V^T (learned, zero-mean, orthonormal)
where G = QR(A^T)^T in R^{(m-1) x (d-1)}, rows orthonormal.
Gradient flows through A -> G -> F[1:] automatically.
Returns:
-
Tensor–The F tensor.
Source code in src/autoden/transforms/learnable_filters.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
get_custom_decomposition
¶
get_custom_decomposition(
device: str | DeviceObjType | None = None,
) -> CustomFilterDecomposition
Return a CustomFilterDecomposition object with the current kernels.
Parameters:
-
device(str | DeviceObjType | None, default:None) –Device to use for the CustomFilterDecomposition (default is None).
Returns:
-
CustomFilterDecomposition–A CustomFilterDecomposition object with the current kernels.
Source code in src/autoden/transforms/learnable_filters.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
get_filter_freq
¶
get_filter_freq() -> NDArray
Return the main frequency associated to each filter, wrt the highest frequency.
Returns:
-
NDArray–The main frequency associated to each filter.
Source code in src/autoden/transforms/learnable_filters.py
123 124 125 126 127 128 129 130 131 | |
get_filter_weights
¶
get_filter_weights(ord: int = 2) -> NDArray
Return the weights of the filters.
Parameters:
-
ord(int, default:2) –Order of the norm (default is 2).
Returns:
-
NDArray–The weights of the filters.
Source code in src/autoden/transforms/learnable_filters.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_fourier_filter_power_spectrum
¶
get_fourier_filter_power_spectrum() -> Tensor
Return the Fourier power spectrum of the filters.
Returns:
-
Tensor–The Fourier power spectrum of the filters.
Source code in src/autoden/transforms/learnable_filters.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
get_interior_error
¶
get_interior_error(x_test: Tensor) -> float
Return the interior error.
Parameters:
-
x_test(Tensor) –Test tensor.
Returns:
-
float–The interior error.
Source code in src/autoden/transforms/learnable_filters.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
get_kernels
¶
get_kernels() -> Tensor
Return the kernels for the convolutions.
Returns:
-
Tensor–The kernels for the convolutions.
Notes
For 2D: (m, in_ch * k ** 2) -> (m, in_ch, k, k)
Source code in src/autoden/transforms/learnable_filters.py
109 110 111 112 113 114 115 116 117 118 119 120 121 | |
gram_error
¶
gram_error() -> float
Return the Gram error.
Returns:
-
float–The Gram error.
Source code in src/autoden/transforms/learnable_filters.py
260 261 262 263 264 265 266 267 268 269 270 | |
plot_filters
¶
Plot the filters.
Parameters:
-
fourier_space(bool, default:False) –Whether to plot the filters in Fourier space (default is False).
-
print_weights(bool, default:True) –Whether to print the weights of the filters (default is True).
Source code in src/autoden/transforms/learnable_filters.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
print_diagnostics
¶
print_diagnostics(x_test: Tensor, label: str = '')
Print diagnostics.
Parameters:
-
x_test(Tensor) –Test tensor.
-
label(str, default:'') –Label for the diagnostics (default is "").
Source code in src/autoden/transforms/learnable_filters.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
reconstruct
¶
reconstruct(x: Tensor) -> Tensor
Reconstruct the input tensor using the current kernels.
Parameters:
-
x(Tensor) –Input tensor.
Returns:
-
Tensor–Reconstructed tensor.
Notes
W^T Wx approx = x when both (A) and (B) hold.
Source code in src/autoden/transforms/learnable_filters.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
synthesize
¶
synthesize(c: Tensor) -> Tensor
Apply the synthesis (inverse) transform using the kernels.
Parameters:
-
c(Tensor) –Input tensor of shape (B, m, [D, H], W).
Returns:
-
Tensor–Output tensor of shape (B, in_ch, [D, H], W).
Source code in src/autoden/transforms/custom_filters.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
zero_mean_error
¶
zero_mean_error() -> float
Return the zero mean error.
Returns:
-
float–The zero mean error.
Notes
max |mean(q_i)| for i >= 1: should be ~0 (filters are q_0-orthogonal).
Source code in src/autoden/transforms/learnable_filters.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
train_sparsity
¶
train_sparsity(
filterbank: LearnableParsevalFilterBank,
data_trn: NDArray,
data_val: NDArray,
n_epochs: int = 50,
batch_size: int = 16,
lr: float = 0.003,
sched_starts: int = 0,
augmentation: str | Sequence[str] | None = None,
fourier_penalty: float = 0.0,
device: str = "cuda" if is_available() else "cpu",
verbose: bool = True,
) -> tuple[LearnableParsevalFilterBank, dict[str, NDArray]]
Learn orthonormal filterbank (in the Stiefel manifold) by minimizing the l_1-norm of analysis coefficients.
Parameters:
-
filterbank(LearnableParsevalFilterBank) –The filterbank to be trained.
-
data_trn(NDArray) –Training data consisting of CLEAN images only.
-
data_val(NDArray) –Validation data consisting of CLEAN images only.
-
n_epochs(int, default:50) –Number of training epochs (default is 50).
-
batch_size(int, default:16) –Batch size for training (default is 16).
-
lr(float, default:0.003) –Learning rate for the optimizer (default is 3e-3).
-
sched_starts(int, default:0) –Epoch at which the learning rate scheduler starts (default is 0).
-
augmentation(str | Sequence[str] | None, default:None) –Type of data augmentation to apply (default is None).
-
device(str, default:'cuda' if is_available() else 'cpu') –Device to use for training (default is "cuda" if available, else "cpu").
-
verbose(bool, default:True) –Whether to print training progress (default is True).
Returns:
-
tuple[LearnableStiefelFilterBank, dict[str, NDArray]]–A tuple containing the trained filterbank and a dictionary of training metrics.
Notes
Learn orthonormal filterbank (in the Stiefel manifold) by minimizing the l_1-norm of analysis coefficients:
- L = (1/N) sum_n ||W x_n||_1 subject to: FF^T = I_m
Only CLEAN images needed - no noise, no labels, no paired data. The Parseval constraint (via QR) handles reconstruction implicitly.
The the per-filter weights lambda_i are NOT learned here (set them afterwards for inference).
Key difference from denoising: - The gradient of the l_1-norm loss wrt F can be computed directly. - The QR reparametrization keeps F on the Stiefel manifold (m, k ** n_dims * in_ch) at every step. - No soft-thresholding / proximal operator involved in training.
Source code in src/autoden/transforms/learnable_filters.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | |