How to use the kymatio.scattering1d.filter_bank.scattering_filter_factory function in kymatio

To help you get started, we’ve selected a few kymatio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kymatio / kymatio / kymatio / scattering1d / scattering1d.py View on Github external
transform of the filters is periodic.
        `P_max = 5` is more than enough for double precision.
        Defaults to `5`.
    eps : float, optional
        required machine precision for the periodization (single
        floating point is enough for deep learning applications).
        Defaults to `1e-7`.

    Returns
    -------
    min_to_pad: int
        minimal value to pad the signal on one size to avoid any
        boundary error.
    """
    J_tentative = int(np.ceil(np.log2(T)))
    _, _, _, t_max_phi = scattering_filter_factory(
        J_tentative, J, Q, normalize=normalize, to_torch=False,
        max_subsampling=0, criterion_amplitude=criterion_amplitude,
        r_psi=r_psi, sigma0=sigma0, alpha=alpha, P_max=P_max, eps=eps)
    min_to_pad = 3 * t_max_phi
    return min_to_pad
github kymatio / kymatio / kymatio / scattering1d / scattering1d.py View on Github external
self.T, self.J, self.Q, r_psi=self.r_psi, sigma0=self.sigma0,
            alpha=self.alpha, P_max=self.P_max, eps=self.eps,
            criterion_amplitude=self.criterion_amplitude,
            normalize=self.normalize)
        # to avoid padding more than T - 1 on the left and on the right,
        # since otherwise torch sends nans
        J_max_support = int(np.floor(np.log2(3 * self.T - 2)))
        self.J_pad = min(int(np.ceil(np.log2(self.T + 2 * min_to_pad))),
                         J_max_support)
        # compute the padding quantities:
        self.pad_left, self.pad_right = compute_padding(self.J_pad, self.T)
        # compute start and end indices
        self.ind_start, self.ind_end = compute_border_indices(
            self.J, self.pad_left, self.pad_left + self.T)
        # Finally, precompute the filters
        phi_f, psi1_f, psi2_f, _ = scattering_filter_factory(
            self.J_pad, self.J, self.Q, normalize=self.normalize,
            criterion_amplitude=self.criterion_amplitude,
            r_psi=self.r_psi, sigma0=self.sigma0, alpha=self.alpha,
            P_max=self.P_max, eps=self.eps)

        # prepare for pytorch
        for k in phi_f.keys():
            if type(k) != str:
                # view(-1, 1).repeat(1, 2) because real numbers!
                phi_f[k] = torch.from_numpy(
                    phi_f[k]).view(-1, 1).repeat(1, 2)
        for psi_f in psi1_f:
            for sub_k in psi_f.keys():
                if type(sub_k) != str:
                    # view(-1, 1).repeat(1, 2) because real numbers!
                    psi_f[sub_k] = torch.from_numpy(
github kymatio / kymatio / kymatio / scattering1d / frontend / numpy_frontend.py View on Github external
min_to_pad = compute_minimum_support_to_pad(
            self.T, self.J, self.Q, r_psi=self.r_psi, sigma0=self.sigma0,
            alpha=self.alpha, P_max=self.P_max, eps=self.eps,
            criterion_amplitude=self.criterion_amplitude,
            normalize=self.normalize)
        # to avoid padding more than T - 1 on the left and on the right,
        # since otherwise torch sends nans
        J_max_support = int(np.floor(np.log2(3 * self.T - 2)))
        self.J_pad = min(int(np.ceil(np.log2(self.T + 2 * min_to_pad))),
                         J_max_support)
        # compute the padding quantities:
        self.pad_left, self.pad_right = compute_padding(self.J_pad, self.T)
        # compute start and end indices
        self.ind_start, self.ind_end = compute_border_indices(
            self.J, self.pad_left, self.pad_left + self.T)
        phi_f, psi1_f, psi2_f, _ = scattering_filter_factory(
            self.J_pad, self.J, self.Q, normalize=self.normalize,
            criterion_amplitude=self.criterion_amplitude,
            r_psi=self.r_psi, sigma0=self.sigma0, alpha=self.alpha,
            P_max=self.P_max, eps=self.eps)
        self.psi1_f = psi1_f
        self.psi2_f = psi2_f
        self.phi_f = phi_f
github kymatio / kymatio / examples / 1d / plot_filters.py View on Github external
# `Q` (between 4 and 16), since these signals are often highly oscillatory and
# are better localized in frequency than they are in time. We therefore set:

Q = 8

###############################################################################
# Note that it is currently not possible to control the number of wavelets
# per octave in the second-order filter bank, which is fixed to one.
#
# We are now ready to create the filters. These are generated by the
# `scattering_filter_factory` method, which takes the logarithm of `T` and
# the `J` and `Q` parameters. It returns the lowpass filter (`phi_f`), the
# first-order wavelet filters (`psi1_f`), and the second-order filters
# (`psi2_f`).

phi_f, psi1_f, psi2_f, _ = scattering_filter_factory(np.log2(T), J, Q)

###############################################################################
# The `phi_f` output is a dictionary where each integer key corresponds points
# to the instantiation of the filter at a certain resolution. In other words,
# `phi_f[0]` corresponds to the lowpass filter at resolution `T`, while 
# `phi_f[1]` corresponds to the filter at resolution `T/2`, and so on.
#
# While `phi_f` only contains a single filter (at different resolutions),
# the `psi1_f` and `psi2_f` outputs are lists of filters, one for each wavelet
# bandpass filter in the filter bank.

###############################################################################
# Plot the filters
# ================
# We are now ready to plot the filters. We first display the lowpass filter
# (at full resolution) in red. We then plot each of the bandpass filters in
github kymatio / kymatio / kymatio / scattering1d / frontend / tensorflow_frontend.py View on Github external
min_to_pad = compute_minimum_support_to_pad(
            self.T, self.J, self.Q, r_psi=self.r_psi, sigma0=self.sigma0,
            alpha=self.alpha, P_max=self.P_max, eps=self.eps,
            criterion_amplitude=self.criterion_amplitude,
            normalize=self.normalize)
        # to avoid padding more than T - 1 on the left and on the right,
        # since otherwise torch sends nans
        J_max_support = int(np.floor(np.log2(3 * self.T - 2)))
        self.J_pad = min(int(np.ceil(np.log2(self.T + 2 * min_to_pad))),
                         J_max_support)
        # compute the padding quantities:
        self.pad_left, self.pad_right = compute_padding(self.J_pad, self.T)
        # compute start and end indices
        self.ind_start, self.ind_end = compute_border_indices(
            self.J, self.pad_left, self.pad_left + self.T)
        phi_f, psi1_f, psi2_f, _ = scattering_filter_factory(
            self.J_pad, self.J, self.Q, normalize=self.normalize,
            criterion_amplitude=self.criterion_amplitude,
            r_psi=self.r_psi, sigma0=self.sigma0, alpha=self.alpha,
            P_max=self.P_max, eps=self.eps)
        self.psi1_f = psi1_f
        self.psi2_f = psi2_f
        self.phi_f = phi_f