Commit 6bbeea6f authored by Martin Reinecke's avatar Martin Reinecke

fixes

parent 997cdaef
......@@ -73,7 +73,7 @@ if __name__ == '__main__':
# Minimize the Hamiltonian
H = ift.Hamiltonian(likelihood, ic_sampling)
H = ift.EnergyAdapter(position, H)
H = ift.EnergyAdapter(position, H, want_metric=True)
# minimizer = ift.L_BFGS(ic_newton)
H, convergence = minimizer(H)
......
......@@ -93,7 +93,7 @@ if __name__ == '__main__':
# Minimize the Hamiltonian
H = ift.Hamiltonian(likelihood)
H = ift.EnergyAdapter(position, H)
H = ift.EnergyAdapter(position, H, want_metric=True)
H, convergence = minimizer(H)
# Plot results
......
......@@ -87,14 +87,14 @@ N = ift.DiagonalOperator(ift.from_global_data(d_space, var))
IC = ift.GradientNormController(tol_abs_gradnorm=1e-8)
likelihood = ift.GaussianEnergy(d, N)(R)
Ham = ift.Hamiltonian(likelihood, IC)
H = ift.EnergyAdapter(params, Ham)
H = ift.EnergyAdapter(params, Ham, want_metric=True)
# Minimize
minimizer = ift.NewtonCG(IC)
H, _ = minimizer(H)
# Draw posterior samples
metric = Ham(ift.Linearization.make_var(H.position)).metric
metric = Ham(ift.Linearization.make_var(H.position, want_metric=True)).metric
samples = [metric.draw_sample(from_inverse=True) + H.position
for _ in range(N_samples)]
......
......@@ -12,6 +12,7 @@ class EnergyAdapter(Energy):
super(EnergyAdapter, self).__init__(position)
self._op = op
self._constants = constants
self._want_metric = want_metric
if len(self._constants) == 0:
tmp = self._op(Linearization.make_var(self._position, want_metric))
else:
......@@ -25,7 +26,8 @@ class EnergyAdapter(Energy):
self._metric = tmp._metric
def at(self, position):
return EnergyAdapter(position, self._op, self._constants)
return EnergyAdapter(position, self._op, self._constants,
self._want_metric)
@property
def value(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment