Exemple #1
0
 def __init__(self, data, Neff, correlation, do_correlation=True, fallback_t=None):
     size = data.shape[0]
     if size != data.shape[1]:
         raise ValueError('KernelOptimizer2D only handles square arrays currently')
     self.a2 = dct2d(data / np.sum(data))[1:, 1:] ** 2
     self.I = np.arange(1, size, dtype=np.float64) ** 2
     self.logI = np.log(self.I)
     self.do_correlation = do_correlation
     if do_correlation:
         self.aFFT = np.fft.fft2(data[:, :] / np.sum(data))
         self.aFFT *= np.conj(self.aFFT)
     self.N = Neff
     self.corr = correlation
     try:
         # t is the bandwidth squared (used for estimating moments), calculated using fixed point
         self.t_star = brentq(self._bandwidth_fixed_point_2D, 0, 0.1, xtol=0.001 ** 2)
         # noinspection PyTypeChecker
         if fallback_t and self.t_star > 0.01 and self.t_star > 2 * fallback_t:
             # For 2D distributions with boundaries, fixed point can overestimate significantly
             logging.debug('KernelOptimizer2D Using fallback (t* > 2*t_gallback)')
             self.t_star = fallback_t
     except Exception:
         if fallback_t is not None:
             # Note the fallback result actually appears to be better in some cases,
             # e.g. Gaussian with four cuts
             logging.debug('2D kernel density optimizer using fallback plugin width %s' % (np.sqrt(fallback_t)))
             self.t_star = fallback_t
         else:
             raise
Exemple #2
0
 def __init__(self, data, Neff, correlation, do_correlation=True):
     size = data.shape[0]
     if size != data.shape[1]:
         raise ValueError('KernelOptimizer2D only handles square arrays currently')
     self.a2 = dct2d(data / np.sum(data))[1:, 1:] ** 2
     self.I = np.arange(1, size, dtype=np.float64) ** 2
     self.logI = np.log(self.I)
     self.do_correlation = do_correlation
     if do_correlation:
         self.aFFT = np.fft.fft2(data[:, :] / np.sum(data))
         self.aFFT *= np.conj(self.aFFT)
     self.N = Neff
     self.corr = correlation
     self.t_star = brentq(self._bandwidth_fixed_point_2D, 0, 0.1, xtol=0.001 ** 2)
Exemple #3
0
 def __init__(self, data, Neff, correlation, do_correlation=True):
     size = data.shape[0]
     if size != data.shape[1]:
         raise ValueError(
             'KernelOptimizer2D only handles square arrays currently')
     self.a2 = dct2d(data / np.sum(data))[1:, 1:]**2
     self.I = np.arange(1, size, dtype=np.float64)**2
     self.logI = np.log(self.I)
     self.do_correlation = do_correlation
     if do_correlation:
         self.aFFT = np.fft.fft2(data[:, :] / np.sum(data))
         self.aFFT *= np.conj(self.aFFT)
     self.N = Neff
     self.corr = correlation
     self.t_star = brentq(self._bandwidth_fixed_point_2D,
                          0,
                          0.1,
                          xtol=0.001**2)