https://github.com/bat/monotonicsplines.jl
[WIP] High performance monotonic splines in Julia
Science Score: 33.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
✓Committers with academic emails
3 of 6 committers (50.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.8%) to scientific vocabulary
Keywords from Contributors
Repository
[WIP] High performance monotonic splines in Julia
Basic Info
- Host: GitHub
- Owner: bat
- License: other
- Language: Julia
- Default Branch: main
- Size: 885 KB
Statistics
- Stars: 6
- Watchers: 4
- Forks: 3
- Open Issues: 3
- Releases: 11
Metadata Files
README.md
MonotonicSplines.jl
This package provides high-performance, GPU- and AD-friendly monotonic spline functions in Julia for use in Normalizing Flows, resp. parameter transformations in general.
This package currently includes the monotonic rational quadratic splines defined in "Neural Spline Flows, Durkan et al. 2019".
Please see the Documentation linked below for details.
Documentation
Quickstart
```julia using MonotonicSplines, Plots, InverseFunctions, ChangesOfVariables
f = rand(RQSpline) f.pX, f.pY, f.dYdX
plot(f, xlims = (-6, 6)); plot!(inverse(f), xlims = (-6, 6))
x = 1.2 y = f(x) withlogabsdetjacobian(f, x) inverse(f)(y) withlogabsdetjacobian(inverse(f), y) ```
Example usage of rational quadratic spline functions for use in Normalizing Flows
Given a set $\{ \mathbf{x}_i\}$ ($i = 1,..., N_{\text{samples}}$) of $D$ dimensional samples, a (partial) Normalizing Flow $\mathbf{f}$ using Splines transforms a number of $D-d~$ ($1 \leq d \leq D$) components of each sample $\mathbf{x}_i$ to obtain a set of partially transformed samples $\{ \mathbf{y}_i\}$:
math
\begin{align*}
\mathbf{f} : \mathbb{R}^D \rightarrow \mathbb{R}^D, ~~ \mathbf{x} =
\begin{pmatrix}
x_{1} \\
x_{2} \\
\vdots \\
x_{d-1} \\
x_{d} \\
\vdots \\
x_{D} \\
\end{pmatrix}
\mapsto
\begin{pmatrix}
x_{1} \\
x_{2} \\
\vdots \\
x_{d-1} \\
f_{\theta_d}(x_d) \\
\vdots \\
f_{\theta_{D}}(x_{D}) \\
\end{pmatrix}
= \mathbf{y}
\end{align*}
Here $f_{\theta_j} : \mathbb{R} \rightarrow \mathbb{R} ~~ (j = d,...,D)~$ denotes a single spline function, characterized by the parameters $~\theta_{j} = (\text{pX}_j~, ~\text{heigths}_j~,~\text{dYdX}_j)$ in the case of the rational quadratic spline functions defined in "Neural Spline Flows, Durkan et al. 2019".
Consider a single sample $\mathbf{x}_i \in \mathbb{R}^D$ from our sample set.
In the context of Normalizing Flows, the set of parameters $\{\theta_j\}$ that characterize the spline functions $\{f_{\theta_j}\}$ to transform the $d$ -th to $D$ -th components of $\mathbf{x}_i$ are obtained by processing the output of a neural net $NN$.
This neural net takes the first $d$ components $\{ x_{i,1},..., x_{i,d}\}$ of $\mathbf{x}_i$ that are not transformed by the Flow $\mathbf{f}$ as input. The output then is a vector of $(D-d) \cdot (3K-1)$ components, where $K$ is the number of segments in a spline function.
These "raw" spline parameters are then processed as described in "Neural Spline Flows, Durkan et al. 2019" to obtain $\{ \theta_j \}$.
MonotonicSplines.jl is designed with parallelism in mind, and this implementation allows for the simultaneous transformation of batches of samples using spline functions.
To this end, the parameters for characterizing sets of several spline functions are stored in the same struct.
Now consider the task of transforming the entire set of samples $\{\mathbf{x}_i\}$ via the Normalizing Flow $f$.
To achieve this, each of the $(D-d) \cdot N_{\text{samples}}$ components to be transformed obtains an individual spline function $f_{\theta_j}^{(i)}$.
So the spline function $f_{\theta_j}^{(i)}$ is applied to the $j$ -th component of the $i$ -th sample.
Given the output params_raw of the neural net $NN$, we can obtain the pX, pY, and dYdX to characterize the desired spline function as follows:
Julia
julia> pX, pY, dYdX = rqs_params_from_nn(params_raw, n_dims_to_transform)
Here, params_raw is a 3(K-1) * n_dims_to_transform x n_samples -matrix. K again is the number of spline segments and n_dims_to_transform $~= D-d~$ is the number of components to transform per sample.
The i -th column of this matrix params_raw is the output of the neural net $NN$ with the first $d$ components $\{ x_{i,1},..., x_{i,d}\}$ of the i -th sample $\mathbf{x}_i$ as the input.
pX, pY, and dYdX each are K x n_dims_to_transform x n_samples -arrays. The [:,j,i] entries hold the parameters to characterize $f_{\theta_j}^{(i)}$, the spline function to transform the j -th component of the i -th sample from the sample set.
We then define the set of spline functions by:
Julia
julia> rqs_splines = RQSpline(pX, pY, dYdX)
An object holding the parameters to characterize n_dims_to_transform x n_samples spline functions.
To apply the spline functions characterized by the parameters stored in rqs_splines, we first isolate the components of the sample set that are supposed to be transformed and then do:
Julia
julia> Y_partial = rqs_splines(X_partial)
X_partial is a n_dims_to_transform x n_samples -matrix, holding the components of the sample set $\{\mathbf{x}_i\}$ that are to be transformed. So the i -th column in X_partial holds the d -th to D -th elements of the i -th sample in $\{\mathbf{x}_i\}$.
Y_partial is a n_dims_to_transform x n_samples matrix, where the i,j -th component is the transformed value of the i,j -th entry in X_partial.
For further details on the implementation, see the Documentation for stable version.
Owner
- Name: Bayesian analysis toolkit
- Login: bat
- Kind: organization
- Email: bat@mpp.mpg.de
- Website: https://www.mpp.mpg.de/bat/
- Repositories: 24
- Profile: https://github.com/bat
GitHub Events
Total
- Create event: 5
- Commit comment event: 1
- Issues event: 3
- Watch event: 3
- Delete event: 3
- Issue comment event: 16
- Push event: 16
- Pull request event: 9
- Fork event: 2
Last Year
- Create event: 5
- Commit comment event: 1
- Issues event: 3
- Watch event: 3
- Delete event: 3
- Issue comment event: 16
- Push event: 16
- Pull request event: 9
- Fork event: 2
Committers
Last synced: over 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Oliver Schulz | o****z@m****e | 50 |
| Michael Dudkowiak | m****k@t****e | 11 |
| dependabot[bot] | 4****] | 3 |
| CompatHelper Julia | c****y@j****g | 2 |
| VasylHafych | v****h@g****m | 1 |
| Richard Hildebrandt | r****t@m****e | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 4
- Total pull requests: 27
- Average time to close issues: 2 months
- Average time to close pull requests: 21 days
- Total issue authors: 3
- Total pull request authors: 5
- Average comments per issue: 3.75
- Average comments per pull request: 2.37
- Merged pull requests: 21
- Bot issues: 0
- Bot pull requests: 9
Past Year
- Issues: 2
- Pull requests: 7
- Average time to close issues: N/A
- Average time to close pull requests: about 12 hours
- Issue authors: 2
- Pull request authors: 5
- Average comments per issue: 2.0
- Average comments per pull request: 0.86
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 3
Top Authors
Issue Authors
- oschulz (2)
- mmikhasenko (1)
- JuliaTagBot (1)
Pull Request Authors
- Micki-D (12)
- oschulz (11)
- dependabot[bot] (11)
- github-actions[bot] (4)
- rdebrand (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- julia 6 total
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 11
juliahub.com: MonotonicSplines
[WIP] High performance monotonic splines in Julia
- Documentation: https://docs.juliahub.com/General/MonotonicSplines/stable/
- License: MIT
-
Latest release: 0.3.3
published over 1 year ago
Rankings
Dependencies
- julia-actions/setup-julia v1 composite
- JuliaRegistries/TagBot v1 composite
- actions/checkout v3 composite
- codecov/codecov-action v3 composite
- julia-actions/cache v1 composite
- julia-actions/julia-buildpkg v1 composite
- julia-actions/julia-docdeploy v1 composite
- julia-actions/julia-processcoverage v1 composite
- julia-actions/julia-runtest v1 composite
- julia-actions/setup-julia v1 composite