Scattering transform API documentation¶
ScatteringTransform ¶
ScatteringTransform(
n_scales,
n_layers,
nlin=torch.abs,
cached=False,
output="graph",
aggregation="mean",
moments=(1, 2, 3, 4),
)
Bases: Module
ScatteringTransform base class. Inherits from PyTorch nn.Module.
This class implements the base logic to compute graph scattering transforms with a pooling and an arbitrary wavelet transform operators.
This is a base class, and implements only the logic to compute
an arbitrary scattering transform. The method get_wavelets
must be implemented by the subclass.
Scattering coefficients are ordered depth-major, then by parent path, then by scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_scales
|
int
|
Number of scales to use in wavelet transform |
required |
n_layers
|
int
|
Number of layers in the scattering transform |
required |
nlin
|
Callable[[Tensor], Tensor]
|
Non-linearity used in the scattering transform. Defaults to torch.abs |
abs
|
cached
|
bool
|
If set to True, the filter bank is cached on first execution and reused while the same adjacency matrix is passed. A different adjacency, or one that requires grad, rebuilds it. Defaults to False |
False
|
output
|
Literal['graph', 'node']
|
"graph" pools each scattering path over the nodes, giving (batch, n_features, n_coefficients), the standard graph scattering transform. "node" skips pooling and returns the graph signal (batch, n_features, n_coefficients, n_nodes), used for node-level tasks). Defaults to "graph" |
'graph'
|
aggregation
|
Literal['mean', 'moments']
|
How "graph" output pools over nodes. "mean" averages each path, the
standard graph scattering transform.
"moments" averages |
'mean'
|
moments
|
tuple[int, ...]
|
Moment orders used by |
(1, 2, 3, 4)
|
Source code in gsxform/scattering.py
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 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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
forward ¶
forward(x, W_adj, mask=None)
Forward pass of a generic scattering transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
input batch of graph signals |
required |
W_adj
|
Tensor
|
Batch of weighted adjacency matrices |
required |
mask
|
Tensor | None
|
Padding mask, boolean tensor shaped (batch, n_nodes)
Padded entries of |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
phi |
Tensor
|
scattering representation of the input batch |
Source code in gsxform/scattering.py
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 332 333 334 335 336 337 338 339 340 341 342 343 | |
get_lowpass ¶
get_lowpass(mask, dtype)
Compute lowpass filtering/pooling operator.
This should roughly resemble an average, it alters the output scaling factor. For instance averaging with the norm of the degree vector scales towards zero, this implementation offers a more natural scaling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Tensor
|
Boolean tensor shaped (batch, n_nodes), true on real nodes |
required |
dtype
|
dtype
|
Floating point type of the operator |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lowpass |
Tensor
|
average pooling operator over each graph's real nodes |
Source code in gsxform/scattering.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
get_wavelets ¶
get_wavelets(W_adj, mask=None)
Compute the wavelet operator.
Subclasses are required to implement this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
W_adj
|
Tensor
|
Batch of weighted adjacency matrices. Padded nodes have no edges. |
required |
mask
|
Tensor | None
|
Boolean tensor shaped (batch, n_nodes), true on real nodes. None
when every graph fills all |
None
|
Source code in gsxform/scattering.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
path_index ¶
path_index()
List the scale path behind each scattering coefficient.
Returns:
| Type | Description |
|---|---|
list[tuple[int, ...]]
|
One tuple of scale indices per coefficient, in output order: |
Source code in gsxform/scattering.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
reset_parameters ¶
reset_parameters()
Clear the cached filter bank.
Source code in gsxform/scattering.py
192 193 194 195 196 | |
Diffusion ¶
Diffusion(
n_scales,
n_layers,
nlin=torch.abs,
cached=False,
output="graph",
aggregation="mean",
moments=(1, 2, 3, 4),
)
Bases: ScatteringTransform
Diffusion scattering transform.
Subclass of ScatteringTransform, implements get_wavelets method.
Diffusion scattering transform algorithm based on description
in Gama et. al 2018.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_scales
|
int
|
Number of scales to use in wavelet transform |
required |
n_layers
|
int
|
Number of layers in the scattering transform |
required |
nlin
|
Callable[[Tensor], Tensor]
|
Non-linearity used in the scattering transform. Defaults to torch.abs |
abs
|
cached
|
bool
|
Cache the filter bank while the adjacency is unchanged. Defaults to False |
False
|
output
|
Literal['graph', 'node']
|
"graph" or "node", see |
'graph'
|
aggregation
|
Literal['mean', 'moments']
|
"mean" or "moments", see |
'mean'
|
moments
|
tuple[int, ...]
|
Moment orders for |
(1, 2, 3, 4)
|
Source code in gsxform/scattering.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
get_wavelets ¶
get_wavelets(W_adj, mask=None)
Subclass method used to get wavelet filter bank.
This method returns diffusion wavelets
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
W_adj
|
Tensor
|
Batch of weighted adjacency matrices |
required |
mask
|
Tensor | None
|
Unused because T` is block diagonal |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
Tensor
|
diffusion wavelet operator |
Source code in gsxform/scattering.py
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 | |
TightHann ¶
TightHann(
n_scales,
n_layers,
nlin=torch.abs,
use_warp=True,
cached=False,
output="graph",
aggregation="mean",
moments=(1, 2, 3, 4),
)
Bases: ScatteringTransform
TightHann scattering transform.
Subclass of ScatteringTransform, implements get_wavelets methods.
Also additionally implements functions used to compute spectrum-adaptive
wavelets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_scales
|
int
|
Number of scales to use in wavelet transform |
required |
n_layers
|
int
|
Number of layers in the scattering transform |
required |
nlin
|
Callable[[Tensor], Tensor]
|
Non-linearity used in the scattering transform. Defaults to torch.abs |
abs
|
use_warp
|
bool
|
Use warping function. Defaults to True |
True
|
cached
|
bool
|
Cache the filter bank while the adjacency is unchanged. Defaults to False |
False
|
output
|
Literal['graph', 'node']
|
"graph" or "node", see |
'graph'
|
aggregation
|
Literal['mean', 'moments']
|
"mean" or "moments", see |
'mean'
|
moments
|
tuple[int, ...]
|
Moment orders for |
(1, 2, 3, 4)
|
Source code in gsxform/scattering.py
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 | |
get_kernel ¶
get_kernel(E, mask=None)
Compute TightHann kernel adaptively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
E
|
Tensor
|
Eigenvalues of each graph's Laplacian, shaped (batch, n_nodes) |
required |
mask
|
Tensor | None
|
Boolean tensor shaped (batch, n_nodes), true on real nodes |
None
|
Returns:
| Type | Description |
|---|---|
TightHannKernel
|
Kernel adapted to each graph's spectrum |
Source code in gsxform/scattering.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
get_wavelets ¶
get_wavelets(W_adj, mask=None)
Subclass method used to get wavelet filter bank.
This method returns tight Hann wavelets
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
W_adj
|
Tensor
|
Batch of weighted adjacency matrices |
required |
mask
|
Tensor | None
|
Padding mask, boolean tensor shaped (batch, n_nodes) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
Tensor
|
tight Hann wavelet operator |
Source code in gsxform/scattering.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
warp_func ¶
warp_func(spectra, mask=None)
Compute the spectrum-adaptive warping function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spectra
|
Tensor
|
Eigenvalues of each graph's Laplacian, sorted ascending, shaped (batch, n_nodes) |
required |
mask
|
Tensor | None
|
Boolean tensor shaped (batch, n_nodes), true on real nodes |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Tensor], Tensor]
|
Per-graph piecewise linear approximation of the spectral CDF |
Source code in gsxform/scattering.py
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 | |