Bijectors
Define the bijectors used in the normalizing flows.
Bijector
Wrapper class for bijector functions
Source code in pzflow/bijectors.py
110 111 112 113 114 115 116 117 118 |
|
ForwardFunction
Return the output and log_det of the forward bijection on the inputs.
ForwardFunction of a Bijector, originally returned by the InitFunction of the Bijector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
a Jax pytree
|
A pytree of bijector parameters. This usually looks like a nested tuple or list of parameters. |
required |
inputs |
jnp.ndarray
|
The data to be transformed by the bijection. |
required |
Returns:
Name | Type | Description |
---|---|---|
outputs |
jnp.ndarray
|
Result of the forward bijection applied to the inputs. |
log_det |
jnp.ndarray
|
The log determinant of the Jacobian evaluated at the inputs. |
Source code in pzflow/bijectors.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
InitFunction
Initialize the corresponding Bijector.
InitFunction returned by the initialization of a Bijector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng |
jnp.ndarray
|
A Random Number Key from jax.random.PRNGKey. |
required |
input_dim |
int
|
The input dimension of the bijection. |
required |
Returns:
Name | Type | Description |
---|---|---|
params |
a Jax pytree
|
A pytree of bijector parameters. This usually looks like a nested tuple or list of parameters. |
forward_fun |
ForwardFunction
|
The forward function of the Bijector. |
inverse_fun |
InverseFunction
|
The inverse function of the Bijector. |
Source code in pzflow/bijectors.py
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 |
|
InverseFunction
Return the output and log_det of the inverse bijection on the inputs.
InverseFunction of a Bijector, originally returned by the InitFunction of the Bijector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
a Jax pytree
|
A pytree of bijector parameters. This usually looks like a nested tuple or list of parameters. |
required |
inputs |
jnp.ndarray
|
The data to be transformed by the bijection. |
required |
Returns:
Name | Type | Description |
---|---|---|
outputs |
jnp.ndarray
|
Result of the inverse bijection applied to the inputs. |
log_det |
jnp.ndarray
|
The log determinant of the Jacobian evaluated at the inputs. |
Source code in pzflow/bijectors.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
Chain(inputs)
Bijector that chains multiple InitFunctions into a single InitFunction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs |
Bijector1(), Bijector2(), ...
|
A container of Bijector calls to be chained together. |
()
|
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the total chained Bijector. |
Bijector_Info
|
Tuple('Chain', Tuple(Bijector_Info for each bijection in the chain)) This allows the chain to be recreated later. |
Source code in pzflow/bijectors.py
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 174 175 |
|
ColorTransform(ref_idx, mag_idx)
Bijector that calculates photometric colors from magnitudes.
Using ColorTransform restricts and impacts the order of columns in the corresponding normalizing flow. See the notes below for an example.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_idx |
int
|
The index corresponding to the column of the reference band, which serves as a proxy for overall luminosity. |
required |
mag_idx |
arraylike of int
|
The indices of the magnitude columns from which colors will be calculated. |
required |
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the ColorTransform Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
Notes
ColorTransform requires careful management of column order in the bijector. This is best explained with an example:
Assume we have data [redshift, u, g, ellipticity, r, i, z, y, mass] Then ColorTransform(ref_idx=4, mag_idx=[1, 2, 4, 5, 6, 7]) will output [redshift, ellipticity, mass, r, u-g, g-r, r-i, i-z, z-y]
Notice how the non-magnitude columns are aggregated at the front of the array, maintaining their relative order from the original array. These values are then followed by the reference magnitude, and the new colors.
Also notice that the magnitudes indices in mag_idx are assumed to be adjacent colors. E.g. mag_idx=[1, 2, 5, 4, 6, 7] would have produced the colors [u-g, g-i, i-r, r-z, z-y]. You can chain multiple ColorTransforms back-to-back to create colors in a non-adjacent manner.
Source code in pzflow/bijectors.py
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 216 217 218 219 220 221 222 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 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 |
|
InvSoftplus(column_idx, sharpness=1)
Bijector that applies inverse softplus to the specified column(s).
Applying the inverse softplus ensures that samples from that column will always be non-negative. This is because samples are the output of the inverse bijection -- so samples will have a softplus applied to them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_idx |
int
|
An index or iterable of indices corresponding to the column(s) you wish to be transformed. |
required |
sharpness |
float
|
The sharpness(es) of the softplus transformation. If more than one is provided, the list of sharpnesses must be of the same length as column_idx. |
1
|
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the Softplus Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
Source code in pzflow/bijectors.py
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 373 374 |
|
NeuralSplineCoupling(K=16, B=5, hidden_layers=2, hidden_dim=128, transformed_dim=None, n_conditions=0, periodic=False)
A coupling layer bijection with rational quadratic splines.
This Bijector is a Coupling Layer [1,2], and as such only transforms the second half of input dimensions (or the last N dimensions, where N = transformed_dim). In order to transform all of the dimensions, you need multiple Couplings interspersed with Bijectors that change the order of inputs dimensions, e.g., Reverse, Shuffle, Roll, etc.
NeuralSplineCoupling uses piecewise rational quadratic splines, as developed in [3].
If periodic=True, then this is a Circular Spline as described in [4].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
K |
int
|
Number of bins in the spline (the number of knots is K+1). |
16
|
B |
float
|
Range of the splines. If periodic=False, outside of (-B,B), the transformation is just the identity. If periodic=True, the input is mapped into the appropriate location in the range (-B,B). |
5
|
hidden_layers |
int
|
The number of hidden layers in the neural network used to calculate the positions and derivatives of the spline knots. |
2
|
hidden_dim |
int
|
The width of the hidden layers in the neural network used to calculate the positions and derivatives of the spline knots. |
128
|
transformed_dim |
int
|
The number of dimensions transformed by the splines. Default is ceiling(input_dim /2). |
None
|
n_conditions |
int
|
The number of variables to condition the bijection on. |
0
|
periodic |
bool
|
Whether to make this a periodic, Circular Spline [4]. |
False
|
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the NeuralSplineCoupling Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
References
[1] Laurent Dinh, David Krueger, Yoshua Bengio. NICE: Non-linear Independent Components Estimation. arXiv: 1605.08803, 2015. http://arxiv.org/abs/1605.08803 [2] Laurent Dinh, Jascha Sohl-Dickstein, Samy Bengio. Density Estimation Using Real NVP. arXiv: 1605.08803, 2017. http://arxiv.org/abs/1605.08803 [3] Conor Durkan, Artur Bekasov, Iain Murray, George Papamakarios. Neural Spline Flows. arXiv:1906.04032, 2019. https://arxiv.org/abs/1906.04032 [4] Rezende, Danilo Jimenez et al. Normalizing Flows on Tori and Spheres. arxiv:2002.02428, 2020 http://arxiv.org/abs/2002.02428
Source code in pzflow/bijectors.py
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 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 |
|
Reverse()
Bijector that reverses the order of inputs.
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the the Reverse Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
Source code in pzflow/bijectors.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
|
Roll(shift=1)
Bijector that rolls inputs along their last column using jnp.roll.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shift |
int
|
The number of places to roll. |
1
|
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the the Roll Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
Source code in pzflow/bijectors.py
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 |
|
RollingSplineCoupling(nlayers, shift=1, K=16, B=5, hidden_layers=2, hidden_dim=128, transformed_dim=None, n_conditions=0, periodic=False)
Bijector that alternates NeuralSplineCouplings and Roll bijections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nlayers |
int
|
The number of (NeuralSplineCoupling(), Roll()) couplets in the chain. |
required |
shift |
int
|
How far the inputs are shifted on each Roll(). |
1
|
K |
int
|
Number of bins in the RollingSplineCoupling. |
16
|
B |
float
|
Range of the splines in the RollingSplineCoupling. If periodic=False, outside of (-B,B), the transformation is just the identity. If periodic=True, the input is mapped into the appropriate location in the range (-B,B). |
5
|
hidden_layers |
int
|
The number of hidden layers in the neural network used to calculate the bins and derivatives in the RollingSplineCoupling. |
2
|
hidden_dim |
int
|
The width of the hidden layers in the neural network used to calculate the bins and derivatives in the RollingSplineCoupling. |
128
|
transformed_dim |
int
|
The number of dimensions transformed by the splines. Default is ceiling(input_dim /2). |
None
|
n_conditions |
int
|
The number of variables to condition the bijection on. |
0
|
periodic |
bool
|
Whether to make this a periodic, Circular Spline |
False
|
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the RollingSplineCoupling Bijector. |
Bijector_Info
|
Nested tuple of the Bijector name and input parameters. This allows it to be recreated later. |
Source code in pzflow/bijectors.py
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 631 632 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 658 659 660 661 662 663 664 665 666 667 668 |
|
Scale(scale)
Bijector that multiplies inputs by a scalar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale |
float
|
Factor by which to scale inputs. |
required |
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the the Scale Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
Source code in pzflow/bijectors.py
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 717 |
|
ShiftBounds(min, max, B=5)
Bijector shifts the bounds of inputs so the lie in the range (-B, B).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min |
float
|
The minimum of the input range. |
required |
min |
float
|
The maximum of the input range. |
required |
B |
float
|
The extent of the output bounds, which will be (-B, B). |
5
|
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the ShiftBounds Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
Source code in pzflow/bijectors.py
720 721 722 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 |
|
Shuffle()
Bijector that randomly permutes inputs.
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the Shuffle Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
Source code in pzflow/bijectors.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 |
|
StandardScaler(means, stds)
Bijector that applies standard scaling to each input.
Each input dimension i has an associated mean u_i and standard dev s_i. Each input is rescaled as (input[i] - u_i)/s_i, so that each input dimension has mean zero and unit variance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
means |
jnp.ndarray
|
The mean of each column. |
required |
stds |
jnp.ndarray
|
The standard deviation of each column. |
required |
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the StandardScaler Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
Source code in pzflow/bijectors.py
821 822 823 824 825 826 827 828 829 830 831 832 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 861 862 863 864 865 |
|
UniformDequantizer(column_idx)
Bijector that dequantizes discrete variables with uniform noise.
Dequantizers are necessary for modeling discrete values with a flow. Note that this isn't technically a bijector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_idx |
int
|
An index or iterable of indices corresponding to the column(s) with discrete values. |
required |
Returns:
Type | Description |
---|---|
InitFunction
|
The InitFunction of the UniformDequantizer Bijector. |
Bijector_Info
|
Tuple of the Bijector name and the input parameters. This allows it to be recreated later. |
Source code in pzflow/bijectors.py
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 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 |
|