-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:JakobRobnik/MicroCanonicalHMC
- Loading branch information
Showing
11 changed files
with
110 additions
and
6,456 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
123 changes: 0 additions & 123 deletions
123
notebooks/mathematica/theoretically_worst_case_convex.nb
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import sys | ||
sys.path.insert(0, '../../') | ||
sys.path.insert(0, './') | ||
|
||
import jax | ||
import jax.numpy as jnp | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from sampling.sampler import Sampler, Target | ||
|
||
nlogp = lambda x: 0.5*jnp.sum(jnp.square(x)) | ||
|
||
class StandardGaussian(Target): | ||
|
||
def __init__(self, d, nlogp): | ||
Target.__init__(self,d,nlogp) | ||
|
||
def transform(self, x): | ||
return x[:2] | ||
|
||
def prior_draw(self, key): | ||
"""Args: jax random key | ||
Returns: one random sample from the prior""" | ||
|
||
return jax.random.normal(key, shape = (self.d, ), dtype = 'float64') * 4 | ||
|
||
target = StandardGaussian(d = 10, nlogp=nlogp) | ||
sampler = Sampler(target, varEwanted = 5e-4) | ||
|
||
target_simple = Target(d = 10, nlogp=nlogp) | ||
|
||
def test_mclmc(): | ||
samples1 = sampler.sample(100, 1, random_key=jax.random.PRNGKey(0)) | ||
samples2 = sampler.sample(100, 1, random_key=jax.random.PRNGKey(0)) | ||
samples3 = sampler.sample(100, 1, random_key=jax.random.PRNGKey(1)) | ||
assert jnp.array_equal(samples1,samples2), "sampler should be pure" | ||
assert not jnp.array_equal(samples1,samples3), "this suggests that seed is not being used" | ||
# run with multiple chains | ||
sampler.sample(100, 3) | ||
|
||
Sampler(target_simple).sample(100, x_initial = jax.random.normal(shape=(10,), key=jax.random.PRNGKey(0))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters