Ejemplo n.º 1
0
    def get_wavelet_fct(self, level):
        # try to get it from cache
        if self.wavelet_fct_level == level and self.wavelet_fct is not None:
            return self.wavelet_fct

        N = len(self.hk) - 1

        #tabbed coef
        hk = self.get_rec_hk()
        gk = self.get_rec_gk()
        tab_hk = np.r_[0, hk]
        tab_gk = np.r_[0, gk]

        # building the matrix
        m = [0, 0]
        p = [0, 0]
        nn, kk = np.ogrid[1:N + 1, 1:N + 1]

        index_m0 = nputils.clipreplace(2 * nn - kk, 1, N + 1, 0)
        index_m1 = nputils.clipreplace(2 * nn - kk + 1, 1, N + 1, 0)
        alpha = 2 / np.sum(hk)

        m[0] = alpha * np.take(tab_hk, index_m0)
        m[1] = alpha * np.take(tab_hk, index_m1)

        p[0] = alpha * np.take(tab_gk, index_m0)
        p[1] = alpha * np.take(tab_gk, index_m1)

        x = np.arange(-N/2., N/2., pow(2, -level))
        phi = np.zeros_like(x)
        psi = np.zeros_like(x)
        v = dict()

        # compute the starting point
        al, av = np.linalg.eig(m[0])
        v_0 = av[:, np.argmin(abs(al - 1))]
        v[0] = v_0 / v_0.sum()

        pointsDone = np.empty(0)

        for j in range(1, int(level + 1)):
            points = np.setdiff1d(np.arange(0, 1, pow(2, -j)), pointsDone)
            pointsDone = np.r_[points, pointsDone]
            for point in points:
                im = int(np.floor((point + 0.5)))
                iv = (2 * point) % 1
                v[point] = np.dot(m[im], v[iv])
                phi[point * pow(2, level)::pow(2, level)] = np.real(v[point])
                psi[point * pow(2, level)::pow(2, level)] = np.real(np.dot(p[im], v[iv]))

        # cache result
        self.wavelet_fct = (x, phi, psi)
        self.wavelet_fct_level = level

        return (x, phi, psi)
Ejemplo n.º 2
0
    def get_wavelet_fct(self, level):
        # try to get it from cache
        if self.wavelet_fct_level == level and self.wavelet_fct is not None:
            return self.wavelet_fct

        N = len(self.hk) - 1

        # tabbed coef
        hk = self.get_rec_hk()
        gk = self.get_rec_gk()
        tab_hk = np.r_[0, hk]
        tab_gk = np.r_[0, gk]

        # building the matrix
        m = [0, 0]
        p = [0, 0]
        nn, kk = np.ogrid[1 : N + 1, 1 : N + 1]

        index_m0 = nputils.clipreplace(2 * nn - kk, 1, N + 1, 0)
        index_m1 = nputils.clipreplace(2 * nn - kk + 1, 1, N + 1, 0)
        alpha = 2 / np.sum(hk)

        m[0] = alpha * np.take(tab_hk, index_m0)
        m[1] = alpha * np.take(tab_hk, index_m1)

        p[0] = alpha * np.take(tab_gk, index_m0)
        p[1] = alpha * np.take(tab_gk, index_m1)

        x = np.arange(-N / 2.0, N / 2.0, pow(2, -level))
        phi = np.zeros_like(x)
        psi = np.zeros_like(x)
        v = dict()

        # compute the starting point
        al, av = np.linalg.eig(m[0])
        v_0 = av[:, np.argmin(abs(al - 1))]
        v[0] = v_0 / v_0.sum()

        pointsDone = np.empty(0)

        for j in range(1, int(level + 1)):
            points = np.setdiff1d(np.arange(0, 1, pow(2, -j)), pointsDone)
            pointsDone = np.r_[points, pointsDone]
            for point in points:
                im = int(np.floor((point + 0.5)))
                iv = (2 * point) % 1
                v[point] = np.dot(m[im], v[iv])
                phi[point * pow(2, level) :: pow(2, level)] = np.real(v[point])
                psi[point * pow(2, level) :: pow(2, level)] = np.real(np.dot(p[im], v[iv]))

        # cache result
        self.wavelet_fct = (x, phi, psi)
        self.wavelet_fct_level = level

        return (x, phi, psi)