Пример #1
0
 def test_norm_constant_calculation(self):
     custom_gauss = kernels.CustomKernel(lambda x: np.exp(-x**2 / 2.0))
     gauss_true_const = 0.3989422804014327
     npt.assert_almost_equal(gauss_true_const, custom_gauss.norm_const)
Пример #2
0
if __name__ == "__main__":
    #from statsmodels.sandbox.nonparametric import smoothers as s
    from statsmodels.sandbox.nonparametric import smoothers, kernels
    import matplotlib.pyplot as plt
    #from numpy import sin, array, random

    import time
    np.random.seed(500)
    x = np.random.normal(size=250)
    y = np.array(
        [np.sin(i * 5) / i + 2 * i + (3 + i) * np.random.normal() for i in x])

    K = kernels.Biweight(0.25)
    K2 = kernels.CustomKernel(lambda x: (1 - x * x)**2,
                              0.25,
                              domain=[-1.0, 1.0])

    KS = smoothers.KernelSmoother(x, y, K)
    KS2 = smoothers.KernelSmoother(x, y, K2)

    KSx = np.arange(-3, 3, 0.1)
    start = time.time()
    KSy = KS.conf(KSx)
    KVar = KS.std(KSx)
    print time.time() - start  # This should be significantly quicker...
    start = time.time()  #
    KS2y = KS2.conf(KSx)  #
    K2Var = KS2.std(KSx)  #
    print time.time() - start  # ...than this.