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

Refactor KL divergence distance for Simulator #5749

Open
Tracked by #7053
ricardoV94 opened this issue May 6, 2022 · 0 comments
Open
Tracked by #7053

Refactor KL divergence distance for Simulator #5749

ricardoV94 opened this issue May 6, 2022 · 0 comments
Labels
help wanted SMC Sequential Monte Carlo v4

Comments

@ricardoV94
Copy link
Member

This was actually never refactored for the new Simulator / V4:

class KullbackLiebler:
"""Approximate Kullback-Liebler."""
def __init__(self, obs_data):
if obs_data.ndim == 1:
obs_data = obs_data[:, None]
n, d = obs_data.shape
rho_d, _ = cKDTree(obs_data).query(obs_data, 2)
self.rho_d = rho_d[:, 1]
self.d_n = d / n
self.log_r = np.log(n / (n - 1))
self.obs_data = obs_data
def __call__(self, epsilon, obs_data, sim_data):
if sim_data.ndim == 1:
sim_data = sim_data[:, None]
nu_d, _ = cKDTree(sim_data).query(self.obs_data, 1)
return self.d_n * np.sum(-np.log(nu_d / self.rho_d) / epsilon) + self.log_r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted SMC Sequential Monte Carlo v4
Projects
None yet
Development

No branches or pull requests

1 participant