Stibor
Normalizing flows and neural flows for PyTorch.
- Normalizing flow defines a complicated probability density function as a transformation of the random variable.
- Neural flow defines continuous time dynamics with invertible neural networks.
Install package and dependencies
pip install stribor
Normalizing flows
Base densities
- Normal
st.Normalandst.UnitNormalandst.MultivariateNormal - Uniform
st.UnitUniform - Or, use distributions from
torch.distributions
Invertible transformations
- Activation functions
- ELU
st.ELU - Leaky ReLU
st.LeakyReLU - Sigmoid
st.Sigmoid - Logit (inverse sigmoid)
st.Logit
- ELU
- Affine
- Element-wise transformation
st.Affine - Linear layer with LU factorization
st.AffineLU - Matrix exponential
st.MatrixExponential
- Element-wise transformation
- Coupling layer that can be combined with any element-wise transformation
st.Coupling - Continuous normalizing flows
st.ContinuousTransform- Differential equations with stochastic trace estimation:
st.net.DiffeqMLPst.net.DiffeqDeepsetst.net.DiffeqSelfAttention
- Differential equations with fixed zero trace:
st.net.DiffeqZeroTraceMLPst.net.DiffeqZeroTraceDeepSetst.net.DiffeqZeroTraceAttention
- Differential equations with exact trace computation:
st.net.DiffeqExactTraceMLPst.net.DiffeqExactTraceDeepSetst.net.DiffeqExactTraceAttention
- Differential equations with stochastic trace estimation:
- Cummulative sum
st.Cumsumand differencest.Diff- Across single column
st.CumsumColumnandst.DiffColumn
- Across single column
- Permutations
- Flipping the indices
st.Flip - Random permutation of indices
st.Permute
- Flipping the indices
- Spline (quadratic or cubic) element-wise transformation
st.Spline
Example: Normalizing flow
To define a normalizing flow, define a base distribution and a series of transformations, e.g.:
import stribor as st
import torch
dim = 2
base_dist = st.UnitNormal(dim)
transforms = [
st.Coupling(
transform=st.Affine(dim, latent_net=st.net.MLP(dim, [64], 2 * dim)),
mask='ordered_right_half',
),
st.ContinuousTransform(
dim,
net=st.net.DiffeqMLP(dim + 1, [64], dim),
)
]
flow = st.NormalizingFlow(base_dist, transforms)
x = torch.rand(10, dim)
y = flow(x) # Forward transformation
log_prob = flow.log_prob(y) # Log-probability p(y)
Example: Neural flow
Neural flows are defined similarly but now we don't need the base density and all the invertible transformations must depend on time. In particular, at t=0, the transformation becomes an identity.
import torch
import stribor as st
dim = 2
f = st.NeuralFlow([
st.ContinuousAffineCoupling(
latent_net=st.net.MLP(dim, [32], 2 * dim),
time_net=st.net.TimeLinear(dim),
mask='ordered_0',
concatenate_time=False,
),
])
x = torch.randn(10, 4, dim)
t = torch.randn_like(x[...,:1])
y = f(x, t=t) # Outputs the same dimension as x
Run tests
pytest --pyargs stribor
Metadata
Release files for stribor 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stribor-0.2.0.tar.gz | 35.8 kB | Without provenance | Details for stribor-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stribor-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for stribor-0.2.0-py3-none-any.whl |
Total release size: 93.5 kB
Release files / stribor-0.2.0.tar.gz
| Download URL | stribor-0.2.0.tar.gz |
|---|---|
| Size | 35.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6941d681b0975e9dbb944c0cb220c2920e6979264b8475067ddd792fe537507
|
|
BLAKE2b-256 checksum How to use checksums |
2bc486f4fdfa7d53a0205e235dfcf468b0b924b3c2b623a7226426ab97664d75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.7.12
|
Release files / stribor-0.2.0-py3-none-any.whl
| Download URL | stribor-0.2.0-py3-none-any.whl |
|---|---|
| Size | 57.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
468e7029e8dae90a1952ecc23874aaf177e622b602f80e1ef710cb583e3f0c26
|
|
BLAKE2b-256 checksum How to use checksums |
1efed050225996c44f7d9292b9d02a2cc18565edf698ca760d8718bb53967ac8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.7.12
|
Security for stribor 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.