Common
ginjax.geometric.common
¤
permutation_matrix_from_sequence(seq: Sequence[int]) -> np.ndarray
¤
Give a sequence tuple, return the permutation matrix for that sequence
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence[int]
|
the sequence |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
the permutation matrix of that sequence |
Source code in ginjax/geometric/common.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
make_all_operators(D: int) -> list[np.ndarray]
¤
Construct all operators of dimension D that are rotations of 90 degrees, or reflections, or a combination of the two. This is equivalent to all the permutation matrices where each entry can either be +1 or -1
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the operator |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
the operators as a list of arrays |
Source code in ginjax/geometric/common.py
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 | |
make_D8_group(D: int) -> list[np.ndarray]
¤
Construct D_8, the Dihedral group with 16 elements, aka rotations of 45 degrees and flips. In D=2 this is the symmetries of an octagon.
Source code in ginjax/geometric/common.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
make_C2_group(D: int) -> list[np.ndarray]
¤
Construct the group C2 x C2 x ... x C2, D times. On a D-dimensional space this is the group which flips each axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
the dimension of the space |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
the operators as a list of numpy arrays |
Source code in ginjax/geometric/common.py
97 98 99 100 101 102 103 104 105 106 107 108 | |
get_basis(key: str, shape: tuple[int, ...]) -> jax.Array
¤
Return a basis for the given shape. Bases are cached so we only have to calculate them once. The result will be a jnp.array of shape (len, shape) where len is the shape all multiplied together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
basis cache key for this basis, will be combined with the shape |
required |
shape
|
tuple[int, ...]
|
the shape of the basis |
required |
Returns:
| Type | Description |
|---|---|
Array
|
the basis |
Source code in ginjax/geometric/common.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
scale_filters(filters: list[GeometricFilter], scale: FilterScaling, k2_irreps_basis: bool) -> list[GeometricFilter]
¤
Scale the filters according to a specific FilterScaling. Filters are assumed to have identical D, spatial shape, k, and parity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
list[GeometricFilter]
|
list of GeometricFilters |
required |
scale
|
FilterScaling
|
the scaling strategy, NORMALIZE (default) to make amplitudes of each tensor +/- 1, ONE to set them all to 1, GAUSSIAN to scale them according to a gaussian kernel, ZERO_SUM so they add up to zero, or ZERO_SUM_L2_DIST so they add up to zero scaled by the distance from the center pixel. |
required |
k2_irreps_basis
|
bool
|
whether k2 is using the irreducible representations basis, which is required for ZERO_SUM and ZERO_SUM_L2_DIST |
required |
Returns:
| Type | Description |
|---|---|
list[GeometricFilter]
|
list of geometric filters scaled appropriately |
Source code in ginjax/geometric/common.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 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 332 333 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 | |
get_unique_irrep_filters(M: int, k: int, parity: int, D: int, operators: Sequence[np.ndarray], basis: jax.Array, scale: FilterScaling = FilterScaling.NORMALIZE, max_pixel_l1: int | None = None, k2_irreps_basis: bool = True, combine_equal_l1: bool = False) -> list[GeometricFilter]
¤
Use group averaging to generate all the unique invariant filters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
M
|
int
|
filter side length |
required |
k
|
int
|
tensor order |
required |
parity
|
int
|
0 or 1, 0 is for normal tensors, 1 for pseudo-tensors |
required |
D
|
int
|
image dimension |
required |
operators
|
Sequence[ndarray]
|
array of operators of a group |
required |
basis
|
Array
|
basis elements of the filters for the group operators to act on |
required |
scale
|
FilterScaling
|
option for scaling the values of the filters, NORMALIZE (default) to make amplitudes of each tensor +/- 1, ONE to set them all to 1, GAUSSIAN to scale them according to a gaussian kernel, ZERO_SUM so they add up to zero, or ZERO_SUM_L2_DIST so they add up to zero scaled by the distance from the center pixel. |
NORMALIZE
|
max_pixel_l1
|
int | None
|
The max pixel l1 distance of the filters. These filters transfer to higher dimensions more easily. Defaults to None, so filters are determined by M. |
None
|
k2_irreps_basis
|
bool
|
for D=2, k=2 filters, use the irreps basis. Defaults to True. |
True
|
combine_equal_li
|
Combine filters whose nonempty pixels are equal l1 dist, default False. |
required |
Returns:
| Type | Description |
|---|---|
list[GeometricFilter]
|
the unique invariant filters |
Source code in ginjax/geometric/common.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 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 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 | |
get_unique_invariant_filters(M: int, k: int, parity: int, D: int, operators: Sequence[np.ndarray], scale: FilterScaling = FilterScaling.NORMALIZE, max_pixel_l1: int | None = None, k2_irreps_basis: bool = True, combine_equal_l1: bool = False) -> list[GeometricFilter]
¤
Use group averaging to generate all the unique invariant filters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
M
|
int
|
filter side length |
required |
k
|
int
|
tensor order |
required |
parity
|
int
|
0 or 1, 0 is for normal tensors, 1 for pseudo-tensors |
required |
D
|
int
|
image dimension |
required |
operators
|
Sequence[ndarray]
|
array of operators of a group |
required |
scale
|
FilterScaling
|
option for scaling the values of the filters, NORMALIZE (default) to make amplitudes of each tensor +/- 1, ONE to set them all to 1, GAUSSIAN to scale them according to a gaussian kernel, ZERO_SUM so they add up to zero, or ZERO_SUM_L2_DIST so they add up to zero scaled by the distance from the center pixel. |
NORMALIZE
|
max_pixel_l1
|
int | None
|
The max pixel l1 distance of the filters. These filters transfer to higher dimensions more easily. Defaults to None, so filters are determined by M. |
None
|
k2_irreps_basis
|
bool
|
for D=2, k=2 filters, use the irreps basis. Defaults to True. |
True
|
combine_equal_li
|
Combine filters whose nonempty pixels are equal l1 dist, default False. |
required |
Returns:
| Type | Description |
|---|---|
list[GeometricFilter]
|
the unique invariant filters |
Source code in ginjax/geometric/common.py
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 543 544 545 546 | |
get_invariant_filters_dict(Ms: Sequence[int], ks: Sequence[int], parities: Sequence[int], D: int, operators: Sequence[np.ndarray], scale: FilterScaling = FilterScaling.NORMALIZE, max_pixel_l1: int | None = None, k2_irreps_basis: bool = True, combine_equal_l1: bool = False) -> tuple[dict[tuple[int, int, int, int], list[GeometricFilter]], dict[tuple[int, int], int]]
¤
Use group averaging to generate all the unique invariant filters for the ranges of Ms, ks, and parities. Returns the filters as dictionary along with a dictionary of the number of filters of each type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Ms
|
Sequence[int]
|
filter side lengths |
required |
ks
|
Sequence[int]
|
tensor orders |
required |
parities
|
Sequence[int]
|
0 or 1, 0 is for normal tensors, 1 for pseudo-tensors |
required |
D
|
int
|
image dimension |
required |
operators
|
Sequence[ndarray]
|
array of operators of a group |
required |
scale
|
FilterScaling
|
option for scaling the values of the filters, NORMALIZE (default) to make amplitudes of each tensor +/- 1, ONE to set them all to 1, GAUSSIAN to scale them according to a gaussian kernel, ZERO_SUM so they add up to zero, or ZERO_SUM_L2_DIST so they add up to zero scaled by the distance from the center pixel. |
NORMALIZE
|
max_pixel_l1
|
int | None
|
The max pixel l1 distance of the filters. These filters transfer to higher dimensions more easily. Defaults to None, so filters are determined by Ms. |
None
|
k2_irreps_basis
|
bool
|
for D=2, k=2 filters, use the irreps basis. Defaults to True. |
True
|
combine_equal_li
|
Combine filters whose nonempty pixels are equal l1 dist, default False. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
allfilters |
dict[tuple[int, int, int, int], list[GeometricFilter]]
|
a dictionary of filters of the specified D, M, k, and parity |
maxn |
dict[tuple[int, int], int]
|
a dictionary that tracks the longest number of filters per key, for a particular D,M combo. |
Source code in ginjax/geometric/common.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 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 604 605 606 607 608 609 610 611 612 613 | |
get_invariant_filters_list(Ms: Sequence[int], ks: Sequence[int], parities: Sequence[int], D: int, operators: Sequence[np.ndarray], scale: FilterScaling = FilterScaling.NORMALIZE, max_pixel_l1: int | None = None, k2_irreps_basis: bool = True, combine_equal_l1: bool = False) -> list[GeometricFilter]
¤
Use group averaging to generate all the unique invariant filters for the ranges of Ms, ks, and parities. Returns the filters as a single list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Ms
|
Sequence[int]
|
filter side lengths |
required |
ks
|
Sequence[int]
|
tensor orders |
required |
parities
|
Sequence[int]
|
0 or 1, 0 is for normal tensors, 1 for pseudo-tensors |
required |
D
|
int
|
image dimension |
required |
operators
|
Sequence[ndarray]
|
array of operators of a group |
required |
scale
|
FilterScaling
|
option for scaling the values of the filters, NORMALIZE (default) to make amplitudes of each tensor +/- 1, ONE to set them all to 1, GAUSSIAN to scale them according to a gaussian kernel, ZERO_SUM so they add up to zero, or ZERO_SUM_L2_DIST so they add up to zero scaled by the distance from the center pixel. |
NORMALIZE
|
max_pixel_l1
|
int | None
|
The max pixel l1 distance of the filters. These filters transfer to higher dimensions more easily. Defaults to None, so filters are determined by Ms. |
None
|
k2_irreps_basis
|
bool
|
for D=2, k=2 filters, use the irreps basis. Defaults to True. |
True
|
combine_equal_li
|
Combine filters whose nonempty pixels are equal l1 dist, default False. |
required |
Returns:
| Type | Description |
|---|---|
list[GeometricFilter]
|
a list of filters of the specified D, M, k, and parity |
Source code in ginjax/geometric/common.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
get_invariant_filters(Ms: Sequence[int], ks: Sequence[int], parities: Sequence[int], D: int, operators: Sequence[np.ndarray], scale: FilterScaling = FilterScaling.NORMALIZE, max_pixel_l1: int | None = None, k2_irreps_basis: bool = True, combine_equal_l1: bool = False) -> MultiImage
¤
Use group averaging to generate all the unique invariant filters for the ranges of Ms, ks, and parities. Returns the filters as a single list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Ms
|
Sequence[int]
|
filter side lengths |
required |
ks
|
Sequence[int]
|
tensor orders |
required |
parities
|
Sequence[int]
|
0 or 1, 0 is for normal tensors, 1 for pseudo-tensors |
required |
D
|
int
|
image dimension |
required |
operators
|
Sequence[ndarray]
|
array of operators of a group |
required |
scale
|
FilterScaling
|
option for scaling the values of the filters, NORMALIZE (default) to make amplitudes of each tensor +/- 1, ONE to set them all to 1, GAUSSIAN to scale them according to a gaussian kernel, ZERO_SUM so they add up to zero, or ZERO_SUM_L2_DIST so they add up to zero scaled by the distance from the center pixel. |
NORMALIZE
|
max_pixel_l1
|
int | None
|
The max pixel l1 distance of the filters. These filters transfer to higher dimensions more easily. Defaults to None, so filters are determined by Ms. |
None
|
k2_irreps_basis
|
bool
|
for D=2, k=2 filters, use the irreps basis. Defaults to True. |
True
|
combine_equal_li
|
Combine filters whose nonempty pixels are equal l1 dist, default False. |
required |
Returns:
| Type | Description |
|---|---|
MultiImage
|
the filter of the specified D, M, k, and parity as a MultiImage |
Source code in ginjax/geometric/common.py
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | |
tensor_name(k: int, parity: int) -> str
¤
Return the given tensor name for the specified tensor order and parity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
tensor order |
required |
parity
|
int
|
tensor parity, either 0 or 1 |
required |
Returns:
| Type | Description |
|---|---|
str
|
a string of the tensor name |
Source code in ginjax/geometric/common.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |