A short example to performing regression with JAXNS #18
Cyberface
started this conversation in
Show and tell
Replies: 2 comments 5 replies
-
@Cyberface jaxns 0.0.2 has been released. There's a slightly new API, along with a host of improvements. Can you check out an example for the API and update your example here? |
Beta Was this translation helpful? Give feedback.
5 replies
-
Hey @Cyberface would you be interested in pull latest version, 1.0 release candidate and running this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The following example can be found in this google colab notebook but I have reproduced it below.
This is a short example how to use the nested sampler JAXNS to perform some simple linear regression.
Thanks to @Joshuaalbert for helping me understand how to use JAXNS!
Preamble
first install JAXNS
This is using version 0.0.6
Next import the packages we need
Data Generation
We will generate some fake data based on a cubic function and use JAXNS to estimate the parameters of this polynomial.
You can plot the data with
Likelihood model
Let's define our likelihood function. Here we use the standard Gaussian likelihood, which assumes the noise is i.i.d with a Normal(loc=0, scale=sigma) distribution.
I believe JAXNS needs a likelihood function where the arguments of the function are the sampling parameters.
So we can use a lambda function to achieve this
Setup Priors
We will use uniform priors for the
a,b,c,d
parameters and a half Laplace prior for the noise terms, because we want the noise term to be positive definate.Setup and run nested sampler
Run the sampler
In the google colab notebook the first execution (with compilation) took about 28 seconds.
The second execution just took 1 second!
Plotting results
There are a couple nice built-in plotting function in JAXNS
Getting the posterior samples
To get the posterior samples you need to use the
jaxns.utils.resample
functionWhen we have the independent posterior samples we can compute statistical quantities like the 5th, 50th and 95th percentiles and plot the predictions over the data as a visual check.
Final result:
Beta Was this translation helpful? Give feedback.
All reactions