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

RENAME NONEUCLIDEAN TO ISOKINETIC #632

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions blackjax/mcmc/integrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"velocity_verlet",
"yoshida",
"implicit_midpoint",
"noneuclidean_leapfrog",
"noneuclidean_mclachlan",
"noneuclidean_yoshida",
"isokinetic_leapfrog",
"isokinetic_mclachlan",
"isokinetic_yoshida",
]


Expand Down Expand Up @@ -332,7 +332,7 @@ def esh_dynamics_momentum_update_one_step(
return next_momentum, next_momentum, kinetic_energy_change


def format_noneuclidean_state_output(
def format_isokinetic_state_output(
position,
momentum,
logdensity,
Expand All @@ -348,25 +348,25 @@ def format_noneuclidean_state_output(
)


def generate_noneuclidean_integrator(cofficients):
def noneuclidean_integrator(
def generate_isokinetic_integrator(cofficients):
def isokinetic_integrator(
logdensity_fn: Callable, *args, **kwargs
) -> GeneralIntegrator:
position_update_fn = euclidean_position_update_fn(logdensity_fn)
one_step = generalized_two_stage_integrator(
esh_dynamics_momentum_update_one_step,
position_update_fn,
cofficients,
format_output_fn=format_noneuclidean_state_output,
format_output_fn=format_isokinetic_state_output,
)
return one_step

return noneuclidean_integrator
return isokinetic_integrator


noneuclidean_leapfrog = generate_noneuclidean_integrator(velocity_verlet_cofficients)
noneuclidean_yoshida = generate_noneuclidean_integrator(yoshida_cofficients)
noneuclidean_mclachlan = generate_noneuclidean_integrator(mclachlan_cofficients)
isokinetic_leapfrog = generate_isokinetic_integrator(velocity_verlet_cofficients)
isokinetic_yoshida = generate_isokinetic_integrator(yoshida_cofficients)
isokinetic_mclachlan = generate_isokinetic_integrator(mclachlan_cofficients)

FixedPointSolver = Callable[
[Callable[[ArrayTree], Tuple[ArrayTree, ArrayTree]], ArrayTree],
Expand Down
4 changes: 2 additions & 2 deletions blackjax/mcmc/mclmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from jax.random import normal

from blackjax.base import SamplingAlgorithm
from blackjax.mcmc.integrators import IntegratorState, noneuclidean_mclachlan
from blackjax.mcmc.integrators import IntegratorState, isokinetic_mclachlan
from blackjax.types import ArrayLike, PRNGKey
from blackjax.util import generate_unit_vector

Expand Down Expand Up @@ -154,7 +154,7 @@ def __new__( # type: ignore[misc]
logdensity_fn: Callable,
L,
step_size,
integrator=noneuclidean_mclachlan,
integrator=isokinetic_mclachlan,
) -> SamplingAlgorithm:
kernel = cls.build_kernel(logdensity_fn, integrator)

Expand Down
18 changes: 9 additions & 9 deletions tests/mcmc/test_integrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def kinetic_energy(p, position=None):
"algorithm": integrators.implicit_midpoint,
"precision": 1e-4,
},
"noneuclidean_leapfrog": {"algorithm": integrators.noneuclidean_leapfrog},
"noneuclidean_mclachlan": {"algorithm": integrators.noneuclidean_mclachlan},
"noneuclidean_yoshida": {"algorithm": integrators.noneuclidean_yoshida},
"isokinetic_leapfrog": {"algorithm": integrators.isokinetic_leapfrog},
"isokinetic_mclachlan": {"algorithm": integrators.isokinetic_mclachlan},
"isokinetic_yoshida": {"algorithm": integrators.isokinetic_yoshida},
}


Expand Down Expand Up @@ -239,13 +239,13 @@ def test_esh_momentum_update(self, dims):
np.testing.assert_array_almost_equal(next_momentum, next_momentum1)

@chex.all_variants(with_pmap=False)
def test_noneuclidean_leapfrog(self):
def test_isokinetic_leapfrog(self):
cov = jnp.asarray([[1.0, 0.5, 0.1], [0.5, 2.0, -0.1], [0.1, -0.1, 3.0]])
logdensity_fn = lambda x: stats.multivariate_normal.logpdf(
x, jnp.zeros([3]), cov
)

step = self.variant(integrators.noneuclidean_leapfrog(logdensity_fn))
step = self.variant(integrators.isokinetic_leapfrog(logdensity_fn))

rng = jax.random.key(4263456)
key0, key1 = jax.random.split(rng, 2)
Expand Down Expand Up @@ -294,12 +294,12 @@ def test_noneuclidean_leapfrog(self):
@chex.all_variants(with_pmap=False)
@parameterized.parameters(
[
"noneuclidean_leapfrog",
"noneuclidean_mclachlan",
"noneuclidean_yoshida",
"isokinetic_leapfrog",
"isokinetic_mclachlan",
"isokinetic_yoshida",
],
)
def test_noneuclidean_integrator(self, integrator_name):
def test_isokinetic_integrator(self, integrator_name):
integrator = algorithms[integrator_name]
cov = jnp.asarray([[1.0, 0.5], [0.5, 2.0]])
logdensity_fn = lambda x: stats.multivariate_normal.logpdf(
Expand Down
2 changes: 1 addition & 1 deletion tests/mcmc/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def run_mclmc(self, logdensity_fn, num_steps, initial_position, key):

kernel = blackjax.mcmc.mclmc.build_kernel(
logdensity_fn=logdensity_fn,
integrator=blackjax.mcmc.integrators.noneuclidean_mclachlan,
integrator=blackjax.mcmc.integrators.isokinetic_mclachlan,
)

(
Expand Down