Exemple #1
0
 def obs_info(self, steps=None, dlogp=1., n=3, err=False):
     """
     Calculated the observed information matrix for varying parameters,
     assuming their current values correspond to a mode (at which a fit
     has already been evaluated).
     """
     # *** Expand docstring.
     # Treat the current state as the mode.
     logp_max = self._log_like + self._log_prior
     mode = []
     for param in self.varying_params:
         mode.append(param.get_value())
     # Find scales for the parameters that change logp by dlogp.
     # Start with the steps arg if provided; otherwise use current
     # varying parameter scales.
     if steps is None:
         deltas = []
         for param in self.varying_params:
             deltas.append(param.delta)
     else:
         deltas = steps
     deltas = dllsteps(self._logp_func, mode, deltas, dlogp, logp_max)
     # Use those step sizes for estimating the observed info matrix.
     info, ierr = obsinfo(self._logp_func, mode, deltas, logp_max, niter=n)
     if err:
         return info, ierr
     else:
         return info
Exemple #2
0
dx = array([0.2, 0.4])
maxll = llike(mu)
print('*** Testing dllsteps ***')
print('dllsteps inputs:', mu, maxll, dx)
dx = dllsteps(llike, mu, dx, 1., maxll)
print('index, dx, x, llike (should be -1):')
for i in range(len(dx)):
    x = mu0.copy()
    x[i] += dx[i]
    print(i, dx[i], x, llike(x))
print()

niter = 5
#ws1, ws2 = zeros(niter,Float), zeros(niter,Float)
info, ierr = obsinfo(llike, mu, dx, maxll)

print('*** Testing obsinfo, 2x2 ***')
print('Unit sigmas, no correlation -> info, err:')
print(info)
print(ierr)
print()

print()
print('*** Correlated 2x2 tests ***')
sigmas = array([.3, 5.])
cross = 1.5
print('Sigmas:', sigmas)
print('squared inverses:', 1 / sigmas**2)
print('cross coef:', cross)