Functional geometric image
ginjax.geometric.functional_geometric_image
¤
parse_shape(shape: tuple[int, ...], D: int) -> tuple[tuple[int, ...], int]
¤
Given a geometric image shape and dimension D, return the sidelength tuple and tensor order k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
the shape of the data of a single geometric image |
required |
D
|
int
|
dimension of the image |
required |
Returns:
| Type | Description |
|---|---|
tuple[tuple[int, ...], int]
|
tuple of spatial dimensions, tensor order |
Source code in ginjax/geometric/functional_geometric_image.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
hash(D: int, spatial_dims: tuple[int, ...], indices: ArrayLike) -> tuple[jax.Array, ...]
¤
Converts an array of indices to their pixels on the torus by modding the indices with the spatial dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the image |
required |
spatial_dims
|
tuple[int, ...]
|
the spatial dimensions of the data |
required |
indices
|
ArrayLike
|
array of indices, shape (num_idx, D) to apply the remainder to |
required |
Returns:
| Type | Description |
|---|---|
tuple[Array, ...]
|
the pixel indices as a d-tuple of jax arrays |
Source code in ginjax/geometric/functional_geometric_image.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
nonempty_pixels(D: int, data: jax.Array, n_lead: int = 0) -> jax.Array
¤
Get the nonempty pixels as a true/false array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
the dimension |
required |
data
|
Array
|
array of shape (n_lead,spatial,tensor) |
required |
n_lead
|
int
|
the number of leading batch axes |
0
|
Returns:
| Type | Description |
|---|---|
Array
|
a true/false array of flattened shape (n_lead,image_size) |
Source code in ginjax/geometric/functional_geometric_image.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
pixel_idxs(spatial_dims: tuple[int, ...]) -> jax.Array
¤
Get the idxs of pixels for spatial_dims, ordered in the flattened image order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spatial_dims
|
tuple[int, ...]
|
tuple of the spatial dimensions |
required |
Returns:
| Type | Description |
|---|---|
Array
|
pixels idxs, shape (num_pixels,D) |
Source code in ginjax/geometric/functional_geometric_image.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
get_torus_expanded(image: jax.Array, is_torus: tuple[bool, ...], filter_spatial_dims: tuple[int, ...], rhs_dilation: tuple[int, ...]) -> tuple[jax.Array, tuple[tuple[int, int], ...]]
¤
For a particular filter, expand the image so that we no longer have to do convolutions on the torus, we are just doing convolutions on the expanded image and will get the same result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Array
|
image data, (batch,spatial,channels) |
required |
is_torus
|
tuple[bool, ...]
|
d-length tuple of bools specifying which spatial dimensions are toroidal |
required |
filter_spatial_dims
|
tuple[int, ...]
|
d-length tuple of the spatial dimensions of the filter |
required |
rhs_dilation
|
tuple[int, ...]
|
dilation to apply to each filter dimension D |
required |
Returns:
| Type | Description |
|---|---|
tuple[Array, tuple[tuple[int, int], ...]]
|
The new expanded torus, and the appropriate padding_literal to use in convolve |
Source code in ginjax/geometric/functional_geometric_image.py
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 126 127 128 | |
get_same_padding(filter_spatial_dims: tuple[int, ...], rhs_dilation: tuple[int, ...], pad_dims: Optional[tuple[bool, ...]] = None) -> tuple[tuple[int, int], ...]
¤
Calculate the padding for each dimension D necessary for 'SAME' padding, including rhs_dilation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_spatial_dims
|
tuple[int, ...]
|
filter spatial dimensions, length D tuple |
required |
rhs_dilation
|
tuple[int, ...]
|
rhs (filter) dilation, length D tuple |
required |
pad_dims
|
Optional[tuple[bool, ...]]
|
d-tuple of dimensions to pad, default (None) is all dimensions |
None
|
Returns:
| Type | Description |
|---|---|
tuple[tuple[int, int], ...]
|
d-tuple of pairs of amount of pixels to pad |
Source code in ginjax/geometric/functional_geometric_image.py
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 | |
pre_tensor_product_expand(D: int, image_a: jax.Array, image_b: jax.Array, a_offset: int = 0, b_offset: int = 0, dtype: Optional[jnp.dtype] = None) -> tuple[jax.Array, jax.Array]
¤
Rather than take a tensor product of two tensors, we can first take a tensor product of each with a tensor of ones with the shape of the other. Then we have two matching shapes, and we can then do whatever operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the image |
required |
image_a
|
Array
|
one geometric image whose tensors we will later be doing tensor products on |
required |
image_b
|
Array
|
other geometric image |
required |
a_offset
|
int
|
number of axes of image_a prior to the spatial dims |
0
|
b_offset
|
int
|
number of axes of image_b prior to the spatial dims |
0
|
dtype
|
Optional[dtype]
|
if present, cast both outputs to dtype |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Array, Array]
|
tuple of the expanded images |
Source code in ginjax/geometric/functional_geometric_image.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
conv_contract_image_expand(D: int, image: jax.Array, filter_k: int) -> jax.Array
¤
For conv_contract, we will be immediately performing a contraction, so we don't need to fully expand each tensor, just the k image to the k+k' conv filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the space |
required |
image
|
Array
|
image data, shape (in_c,spatial,tensor) |
required |
filter_k
|
int
|
the filter tensor order |
required |
Returns:
| Type | Description |
|---|---|
Array
|
the expanded image data |
Source code in ginjax/geometric/functional_geometric_image.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
mul(D: int, image_a: jax.Array, image_b: jax.Array, a_offset: int = 0, b_offset: int = 0) -> jax.Array
¤
Multiplication operator between two images, implemented as a tensor product of the pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the images |
required |
image_a
|
Array
|
image data |
required |
image_b
|
Array
|
image data |
required |
a_offset
|
int
|
number of axes before the spatial axes (batch, channels, etc.) |
0
|
b_offset
|
int
|
number of axes before the spatial axes (batch, channels, etc.) |
0
|
Returns:
| Type | Description |
|---|---|
Array
|
the multiplied images |
Source code in ginjax/geometric/functional_geometric_image.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
convolve(D: int, image: jax.Array, filter_image: jax.Array, is_torus: Union[tuple[bool, ...], bool], stride: Union[int, tuple[int, ...]] = 1, padding: Optional[Union[str, int, tuple[tuple[int, int], ...]]] = None, lhs_dilation: Optional[tuple[int, ...]] = None, rhs_dilation: Union[int, tuple[int, ...]] = 1, tensor_expand: bool = True) -> jax.Array
¤
Here is how this function works:
- Expand the geom_image to its torus shape, i.e. add filter.m cells all around the perimeter of the image
- Do the tensor product (with 1s) to each image.k, filter.k so that they are both image.k + filter.k tensors. That is if image.k=2, filter.k=1, do (D,D) => (D,D) x (D,) and (D,) => (D,D) x (D,) with tensors of 1s
- Now we shape the inputs to work with jax.lax.conv_general_dilated
- Put image in NHWC (batch, height, width, channel). Thus we vectorize the tensor
- Put filter in HWIO (height, width, input, output). Input is 1, output is the vectorized tensor
- Plug all that stuff in to conv_general_dilated, and feature_group_count is the length of the vectorized tensor, and it is basically saying that each part of the vectorized tensor is treated separately in the filter.
It must be the case that channel = input * feature_group_count. See: https://jax.readthedocs.io/en/latest/notebooks/convolutions.html#id1 and https://www.tensorflow.org/xla/operation_semantics#conv_convolution
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the images |
required |
image
|
Array
|
image data, shape (batch,in_c,spatial,tensor) |
required |
filter_image
|
Array
|
the convolution filter, shape (out_c,in_c,spatial,tensor) |
required |
is_torus
|
Union[tuple[bool, ...], bool]
|
what dimensions of the image are toroidal |
required |
stride
|
Union[int, tuple[int, ...]]
|
convolution stride, defaults to (1,)*self.D |
1
|
padding
|
Optional[Union[str, int, tuple[tuple[int, int], ...]]]
|
either 'TORUS','VALID', 'SAME', or D length tuple of (upper,lower) pairs, defaults to 'TORUS' if image.is_torus, else 'SAME' |
None
|
lhs_dilation
|
Optional[tuple[int, ...]]
|
amount of dilation to apply to image in each dimension D, also transposed conv |
None
|
rhs_dilation
|
Union[int, tuple[int, ...]]
|
amount of dilation to apply to filter in each dimension D, defaults to 1 |
1
|
tensor_expand
|
bool
|
expand the tensor of image and filter to do tensor convolution, defaults to True. If there is something more complicated going on (e.g. conv_contract), you can skip this step. |
True
|
Returns:
| Type | Description |
|---|---|
Array
|
convolved_image, shape (batch,out_c,spatial,tensor) |
Source code in ginjax/geometric/functional_geometric_image.py
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 | |
convolve_ravel(D: int, image: jax.Array, filter_image: jax.Array, is_torus: Union[tuple[bool, ...], bool], stride: Union[int, tuple[int, ...]] = 1, padding: Optional[Union[str, int, tuple[tuple[int, int], ...]]] = None, lhs_dilation: Optional[tuple[int, ...]] = None, rhs_dilation: Union[int, tuple[int, ...]] = 1) -> jax.Array
¤
Raveled verson of convolution. Assumes the channels are all lined up correctly for the tensor convolution. This assumes that the feature_group_count is image in_c // filter in_c.
See convolve for a full description of this function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the images |
required |
image
|
Array
|
image data, shape (batch,spatial,tensor*in_c) |
required |
filter_image
|
Array
|
the convolution filter, shape (spatial,in_c,tensor*out_c) |
required |
is_torus
|
Union[tuple[bool, ...], bool]
|
what dimensions of the image are toroidal |
required |
stride
|
Union[int, tuple[int, ...]]
|
convolution stride, defaults to (1,)*self.D |
1
|
padding
|
Optional[Union[str, int, tuple[tuple[int, int], ...]]]
|
either 'TORUS','VALID', 'SAME', or D length tuple of (upper,lower) pairs, defaults to 'TORUS' if image.is_torus, else 'SAME' |
None
|
lhs_dilation
|
Optional[tuple[int, ...]]
|
amount of dilation to apply to image in each dimension D, also transposed conv |
None
|
rhs_dilation
|
Union[int, tuple[int, ...]]
|
amount of dilation to apply to filter in each dimension D, defaults to 1 |
1
|
Returns:
| Type | Description |
|---|---|
Array
|
convolved_image, shape (batch,spatial,tensor*out_c) |
Source code in ginjax/geometric/functional_geometric_image.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 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 | |
convolve_contract(D: int, image: jax.Array, filter_image: jax.Array, is_torus: Union[bool, tuple[bool, ...]], stride: Union[int, tuple[int, ...]] = 1, padding: Optional[Union[str, int, tuple[tuple[int, int], ...]]] = None, lhs_dilation: Optional[tuple[int, ...]] = None, rhs_dilation: Union[int, tuple[int, ...]] = 1) -> jax.Array
¤
Given an input k image and a k+k' filter, take the tensor convolution that contract k times with one index each from the image and filter. This implementation is slightly more efficient then doing the convolution and contraction separately by avoiding constructing the k+k+k' intermediate tensor. See convolve for a full description of the convolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the images |
required |
image
|
Array
|
image data, shape (batch,in_c,spatial,tensor) |
required |
filter_image
|
Array
|
the convolution filter, shape (out_c,in_c,spatial,tensor) |
required |
is_torus
|
Union[bool, tuple[bool, ...]]
|
what dimensions of the image are toroidal |
required |
stride
|
Union[int, tuple[int, ...]]
|
convolution stride, defaults to (1,)*self.D |
1
|
padding
|
Optional[Union[str, int, tuple[tuple[int, int], ...]]]
|
either 'TORUS','VALID', 'SAME', or D length tuple of (upper,lower) pairs, defaults to 'TORUS' if image.is_torus, else 'SAME' |
None
|
lhs_dilation
|
Optional[tuple[int, ...]]
|
amount of dilation to apply to image in each dimension D, also transposed conv |
None
|
rhs_dilation
|
Union[int, tuple[int, ...]]
|
amount of dilation to apply to filter in each dimension D, defaults to 1 |
1
|
Returns:
| Type | Description |
|---|---|
Array
|
convolved_image, shape (batch,out_c,spatial,tensor) |
Source code in ginjax/geometric/functional_geometric_image.py
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 | |
get_contraction_indices(initial_k: int, final_k: int, swappable_idxs: tuple[tuple[int, int], ...] = ()) -> list[tuple[tuple[int, int], ...]]
¤
Get all possible unique indices for multicontraction. Returns a list of indices. The indices are a tuple of tuples where each of the inner tuples are pairs of indices. For example, if initial_k=5, final_k = 4, one element of the list that is returned will be ((0,1), (2,3)), another will be ((1,4), (0,2)), etc.
Note that contracting (0,1) is the same as contracting (1,0). Also, contracting ((0,1),(2,3)) is the same as contracting ((2,3),(0,1)). In both of those cases, they won't be returned. There is also the optional argument swappable_idxs to specify indices that can be swapped without changing the contraction. Suppose we have A * c1 where c1 is a k=2, parity=0 invariant conv_filter. In that case, we can contract on either of its indices and it won't change the result because transposing the axes is a group operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_k
|
int
|
the starting number of indices that we have |
required |
final_k
|
int
|
the final number of indices that we want to end up with |
required |
swappable_idxs
|
tuple[tuple[int, int], ...]
|
Indices that can swapped w/o changing the contraction |
()
|
Returns:
| Type | Description |
|---|---|
list[tuple[tuple[int, int], ...]]
|
all the possible contraction indices |
Source code in ginjax/geometric/functional_geometric_image.py
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 547 548 549 550 | |
multicontract(data: jax.Array, indices: tuple[tuple[int, int], ...], idx_shift: int = 0) -> jax.Array
¤
Perform the Kronecker Delta contraction on the data. Must have at least 2 dimensions, and because we implement with einsum, must have at most 52 dimensions. Indices a tuple of pairs of indices, also tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
data to perform the contraction on |
required |
indices
|
tuple[tuple[int, int], ...]
|
index pairs to perform the contractions on |
required |
idx_shift
|
int
|
indices are the tensor indices, so if data has spatial indices or channel/batch indices in the beginning we shift over by idx_shift |
0
|
Returns:
| Type | Description |
|---|---|
Array
|
the contracted data |
Source code in ginjax/geometric/functional_geometric_image.py
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 | |
raise_lower(data: jax.Array, metric_tensor: jax.Array, metric_tensor_inv: jax.Array, from_axes: tuple[bool, ...], to_axes: tuple[bool, ...], precision: Optional[jax.lax.Precision] = None) -> jax.Array
¤
Raise or lower the axes of a tensor or tensor image according to the metric tensor and axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
a tensor, or tensor image, shape (...,tensor) |
required |
metric_tensor
|
Array
|
the metric tensor g_ij, shape (...,tensor) |
required |
metric_tensor_inv
|
Array
|
the inverse metric tensor, g^ij. Must be same spatial shape as this |
required |
from_axes
|
tuple[bool, ...]
|
covariant axes you are starting at, True for covariant, False contravariant |
required |
to_axes
|
tuple[bool, ...]
|
covariant axes to convert to, True for covariant, False contravariant |
required |
precision
|
Optional[Precision]
|
precision used for einsum |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
the data with the modified axes |
Source code in ginjax/geometric/functional_geometric_image.py
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 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
get_rotated_keys(D: int, spatial_dims: tuple[int, ...], gg: np.ndarray) -> np.ndarray
¤
Get the rotated keys of data when it will be rotated by gg. Note that we rotate the key vector indices by the inverse of gg per the definition (this is done by key_array @ gg, rather than gg @ key_array). When the spatial_dims are not square, this gets a little tricky. The gg needs to be a concrete (numpy) array, not a traced jax array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of image |
required |
spatial_dims
|
tuple[int, ...]
|
the spatial dimensions of the data to be rotated |
required |
gg
|
ndarray
|
group operation |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
the rotated keys |
Source code in ginjax/geometric/functional_geometric_image.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
times_group_element(D: int, data: jax.Array, parity: int, gg: np.ndarray, covariant_axes: tuple[bool, ...], precision: Optional[jax.lax.Precision] = None) -> jax.Array
¤
Apply a group element of O(d) to the geometric image. First apply the action to the location of the pixels, then apply the action to the pixels themselves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the data |
required |
data
|
Array
|
data block of image data to rotate, shape (batch,spatial,tensor) |
required |
parity
|
int
|
parity of the data, 0 for even parity, 1 for odd parity |
required |
gg
|
ndarray
|
a DxD matrix that rotates the tensor. Note that you cannot vmap by this argument because it needs to deal with concrete values |
required |
covariant_axes
|
tuple[bool, ...]
|
which axes of the tensor are covariant (True) or contravariant (False). Also specifies the number of tensor axes. |
required |
precision
|
Optional[Precision]
|
einsum precision, normally uses lower precision, use jax.lax.Precision.HIGHEST for testing equality in unit tests |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
the rotated image data |
Source code in ginjax/geometric/functional_geometric_image.py
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 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
times_D8_element(D: int, data: jax.Array, parity: int, gg: np.ndarray, covariant_axes: tuple[bool, ...], precision: Optional[jax.lax.Precision] = None) -> jax.Array
¤
For the very limited case of a 3x3 GeometricImage, we define the group action of D8 as treating the 8 pixels around the center pixel as if they were equally spaced radially around the center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the data |
required |
data
|
Array
|
data block of image data to rotate, shape (batch,spatial,tensor) |
required |
parity
|
int
|
parity of the data, 0 for even parity, 1 for odd parity |
required |
gg
|
ndarray
|
a DxD matrix that rotates the tensor. Note that you cannot vmap by this argument because it needs to deal with concrete values |
required |
covariant_axes
|
tuple[bool, ...]
|
which axes of the tensor are covariant (True) or contravariant (False). Also specifies the number of tensor axes. |
required |
precision
|
Optional[Precision]
|
einsum precision, normally uses lower precision, use jax.lax.Precision.HIGHEST for testing equality in unit tests |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
the rotated image data |
Source code in ginjax/geometric/functional_geometric_image.py
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 | |
tensor_times_gg(tensor: jax.Array, parity: int, gg: np.ndarray, precision: Optional[jax.lax.Precision] = None) -> jax.Array
¤
Apply a group element of SO(2) or SO(3) to a single tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Array
|
data of the tensor |
required |
parity
|
int
|
parity of the data, 0 for even parity, 1 for odd parity |
required |
gg
|
ndarray
|
a DxD matrix that rotates the tensor. Note that you cannot vmap by this argument because it needs to deal with concrete values |
required |
precision
|
Optional[Precision]
|
eisnum precision, normally uses lower precision, use jax.lax.Precision.HIGH for testing equality in unit tests |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
rotated tensor data |
Source code in ginjax/geometric/functional_geometric_image.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
translate(D: int, data: jax.Array, tau: jax.Array, n_lead: int = 0) -> jax.Array
¤
Translate an image by translation tau, on the torus. Translations on the data matrix are ij ordering. For example, a translation of [1,-1] moves the down one row, then to the left one column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of the image |
required |
data
|
Array
|
image data with n_lead batch axes, followed by spatial then tensor |
required |
tau
|
Array
|
the translation |
required |
n_lead
|
int
|
number of leading batch axes |
0
|
Returns:
| Type | Description |
|---|---|
Array
|
translated image data |
Source code in ginjax/geometric/functional_geometric_image.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 | |
norm(idx_shift: int, data: jax.Array, keepdims: bool = False) -> jax.Array
¤
Perform the frobenius norm on each pixel tensor, returning a scalar image
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx_shift
|
int
|
the number of leading axes before the tensor, should be D for spatial plus the batch and spatial axes if they |
required |
data
|
Array
|
image data, shape (spatial,tensor) |
required |
keepdims
|
bool
|
passed to jnp.linalg.norm |
False
|
Returns:
| Type | Description |
|---|---|
Array
|
the data of a scalar image after performing the norm |
Source code in ginjax/geometric/functional_geometric_image.py
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 | |
max_pool(D: int, image_data: jax.Array, patch_len: int, use_norm: bool = True, comparator_image: Optional[jax.Array] = None) -> jax.Array
¤
Perform a max pooling operation where the length of the side of each patch is patch_len. Max is determined by the value of comparator_image if present, then the norm of image_data if use_norm is true, then finally the image_data otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
the dimension of the space, must be between 1 and 4 inclusive |
required |
image_data
|
Array
|
the image data, shape (spatial,tensor) |
required |
patch_len
|
int
|
the side length of the patches, must evenly divide all spatial dims |
required |
use_norm
|
bool
|
if true, use the norm (over the tensor) of the image as the comparator image |
True
|
comparator_image
|
Optional[Array]
|
scalar image whose argmax is used to determine what value to use. |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
the image data that has been max pooled, shape (spatial,tensor) |
Source code in ginjax/geometric/functional_geometric_image.py
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 | |
average_pool(D: int, image_data: jax.Array, patch_len: int) -> jax.Array
¤
Perform a average pooling operation where the length of the side of each patch is patch_len. This is equivalent to doing a convolution where each element of the filter is 1 over the number of pixels in the filter, the stride length is patch_len, and the padding is 'VALID'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
D
|
int
|
dimension of data |
required |
image_data
|
Array
|
image data, shape (spatial,tensor) |
required |
patch_len
|
int
|
the side length of the patches, must evenly divide the sidelength |
required |
Returns:
| Type | Description |
|---|---|
Array
|
the image data after being averaged pooled, shape (spatial, tensor) |
Source code in ginjax/geometric/functional_geometric_image.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 | |