Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
ppegolo committed Oct 15, 2024
1 parent 1245e3c commit f20b21d
Showing 1 changed file with 3 additions and 38 deletions.
41 changes: 3 additions & 38 deletions sportran/md/maxlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def __init__(
omega_fixed=None,
ext_guess=None,
alpha=10 ** (np.linspace(-10, -3, 10000)),
alpha=10 ** (np.linspace(-10, 2, 10000)),
):
"""
Initialize the MaxLikeFilter class with the provided parameters.
Expand Down Expand Up @@ -460,8 +459,6 @@ def _optimize_alpha(self, res):
cov = cov.todense()

samples = generate_samples_mc_alpha(w, cov)
dic_alpha = reweight_logev_alpha_vec(alpha=self.alpha, samples=samples)
samples = generate_samples_mc_alpha(res.x, res.hess_inv)
dic_alpha, self.alpha_plot = reweight_logev_alpha_vec(
alpha=self.alpha, samples=samples
)
Expand All @@ -483,9 +480,9 @@ def _store_optimization_results(self, res, write_log):
"Covariance matrix estimated through Laplace approximation."
)

# self.best_alpha, self.parameters_mean, self.parameters_cov = (
# self._optimize_alpha(res=res)
# )
self.best_alpha, self.parameters_mean, self.parameters_cov = (
self._optimize_alpha(res=res)
)

try:
cov = res.hess_inv.todense()
Expand All @@ -509,7 +506,6 @@ def _store_optimization_results(self, res, write_log):

self.optimizer_res = res
self.log_likelihood_value = -self.log_like(
# self.parameters_mean,
res.x,
self.model,
self.omega,
Expand Down Expand Up @@ -735,37 +731,6 @@ def reweight_alpha(alpha, samples):
return truth_mean, truth_cov


# def reweight_alpha(alpha, samples):
# """
# samples: shape is (N, P): N number of samples, P number of parameters
# array: scalar
# """
# truth_mean = (
# np.mean(
# samples.T[:, :] * np.exp(-alpha * np.linalg.norm(samples, axis=1) ** 2),
# axis=1,
# )
# ) / (np.mean(np.exp(-alpha * np.linalg.norm(samples, axis=1) ** 2), axis=0))
# print("truth_mean", truth_mean)

# truth_cov = (
# np.mean(
# samples.T[:, None, :]
# * samples.T[None, :, :]
# * np.exp(-alpha * np.linalg.norm(samples, axis=1) ** 2),
# axis=-1,
# )
# ) / (
# np.mean(np.exp(-alpha * np.linalg.norm(samples, axis=1) ** 2), axis=0)
# ) - truth_mean[
# :, None
# ] * truth_mean[
# None, :
# ]

# return truth_mean, truth_cov


def generate_samples_mc_alpha(w, cov_w, size=1000):
"""
samples shape is (N, P): N number of samples, P number of parameters
Expand Down

0 comments on commit f20b21d

Please sign in to comment.