Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding additional prior class #45

Merged
merged 4 commits into from
Dec 4, 2023
Merged

Adding additional prior class #45

merged 4 commits into from
Dec 4, 2023

Conversation

tsunhopang
Copy link
Collaborator

@tsunhopang tsunhopang commented Dec 4, 2023

Adding Powerlaw and the Alignedspin prior class; test cases are shown below.

from jax import config
config.update("jax_enable_x64", True)
import jax.numpy as jnp
from jax.random import PRNGKey
from jimgw.prior import Powerlaw
import matplotlib.pyplot as plt

alpha=2
xmin=0.
xmax=100.

key = PRNGKey(42)

prior = Powerlaw(xmin=xmin,
                 xmax=xmax,
                 alpha=alpha,
                 naming=['d_L'])

samples = prior.sample(key, 100000)
log_pdf = prior.log_prob(samples)

samples_sorted = jnp.sort(samples['d_L'])
log_pdf_sorted = log_pdf[samples['d_L'].argsort()]

plt.figure(1)
plt.xlabel('x')
plt.ylabel('pdf')
plt.hist(samples['d_L'], bins=50, density=True)
plt.plot(samples_sorted, jnp.exp(log_pdf_sorted))
plt.yscale('log')
plt.xscale('log')

jim_powerlaw_test

from jax import config
config.update("jax_enable_x64", True)
import jax.numpy as jnp
from jax.random import PRNGKey
from jimgw.prior import Alignedspin
import matplotlib.pyplot as plt

amax = 0.99
key = PRNGKey(42)

prior = Alignedspin(
    amax=amax,
    naming=['s1_z']
)

samples = prior.sample(key, 100000)
log_pdf = prior.log_prob(samples)

samples_sorted = jnp.sort(samples['s1_z'])
log_pdf_sorted = log_pdf[samples['s1_z'].argsort()]

ref_x = jnp.linspace(-amax, amax, num=10000)
ref_y = -jnp.log(jnp.absolute(ref_x) / amax) / 2 / amax

plt.figure(1)
plt.xlabel('x')
plt.ylabel('pdf')
plt.ylim([0, 3])
plt.hist(samples['s1_z'], bins=50, density=True, label='Samples')
plt.plot(samples_sorted, jnp.exp(log_pdf_sorted), label='Probability')
plt.plot(ref_x, ref_y, label='Reference calculation', linestyle='--')
plt.legend()

test_jim_alignedspin

@tsunhopang tsunhopang changed the title Adding Powerlaw prior class Adding additional prior class Dec 4, 2023
@kazewong kazewong self-requested a review December 4, 2023 20:04
Copy link
Owner

@kazewong kazewong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed a couple of minor detail, it is ready to be merged now.

For styling, we can patch it up in a later patch.

@kazewong kazewong merged commit 151c219 into kazewong:main Dec 4, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants