Beispiel #1
0
def global_transform(X_batch, pad_data, encoder_, n_atoms, nonneg):
    X_batch = X_batch.swapaxes(0, 1).swapaxes(1, 2)

    h, w, n = X_batch.shape

    # Fourier transform
    X_new = _cdl.patches_to_vectors(X_batch, pad_data=pad_data)

    # Encode
    X_new = encoder_(X_new)

    X_new = _cdl.real2_to_complex(X_new)
    X_new = X_new.reshape((-1, X_new.shape[1] * n_atoms), order='F')
    X_new = _cdl.complex_to_real2(X_new)

    X_new = _cdl.vectors_to_patches(X_new, w, pad_data=pad_data, real=True)

    X_new = X_new.reshape((X_new.shape[0], X_new.shape[1], n_atoms, n),
                          order='F')

    X_new = X_new.swapaxes(3, 0).swapaxes(3, 2).swapaxes(3, 1)

    if nonneg:
        X_new = np.maximum(X_new, 0.0)

    return X_new
Beispiel #2
0
def global_transform(X_batch, pad_data, encoder_, n_atoms, nonneg):
    X_batch = X_batch.swapaxes(0, 1).swapaxes(1, 2)

    h, w, n = X_batch.shape

    # Fourier transform
    X_new = _cdl.patches_to_vectors(X_batch, pad_data=pad_data)

    # Encode
    X_new = encoder_(X_new)

    X_new = _cdl.real2_to_complex(X_new)
    X_new = X_new.reshape( (-1, X_new.shape[1] * n_atoms), order='F')
    X_new = _cdl.complex_to_real2(X_new)   

    X_new = _cdl.vectors_to_patches(X_new, w, 
                                    pad_data=pad_data, 
                                    real=True)

    X_new = X_new.reshape( (X_new.shape[0], X_new.shape[1], 
                                n_atoms, n), 
                            order='F')

    X_new = X_new.swapaxes(3, 0).swapaxes(3, 2).swapaxes(3, 1)

    if nonneg:
        X_new = np.maximum(X_new, 0.0)

    return X_new
Beispiel #3
0
    def fit(self, X):
        '''Fit the model to the data in X.

        Parameters
        ----------
        X : array-like, shape [n_samples, n_features_y, n_features_x]
            Training data patches.

        Returns
        -------
        self: object
            Returns the instance itself.
        '''

        width = X.shape[2]
        extra_args = {}
        if self.penalty == 'l1_space':
            extra_args['height']    = X.shape[1]
            extra_args['width']     = X.shape[2]
            extra_args['pad_data']  = self.pad_data
            extra_args['nonneg']    = self.nonneg


        encoder, D, diagnostics = _cdl.learn_dictionary(
                                        self.data_generator(X),
                                        self.n_atoms,
                                        reg         = self.penalty,
                                        alpha       = self.alpha,
                                        max_steps   = self.n_iter,
                                        verbose     = self.verbose,
                                        D           = self.fft_components_,
                                        **extra_args)

        self.fft_components_ = D
        D                   = _cdl.diags_to_columns(D)
        D                   = _cdl.vectors_to_patches(D, width, 
                                    pad_data=self.pad_data)
        self.components_    = D.swapaxes(1, 2).swapaxes(0, 1)
        self.encoder_       = encoder
        self.diagnostics_   = diagnostics
        return self
Beispiel #4
0
    def fit(self, X):
        '''Fit the model to the data in X.

        Parameters
        ----------
        X : array-like, shape [n_samples, n_features_y, n_features_x]
            Training data patches.

        Returns
        -------
        self: object
            Returns the instance itself.
        '''

        width = X.shape[2]
        extra_args = {}
        if self.penalty == 'l1_space':
            extra_args['height'] = X.shape[1]
            extra_args['width'] = X.shape[2]
            extra_args['pad_data'] = self.pad_data
            extra_args['nonneg'] = self.nonneg

        encoder, D, diagnostics = _cdl.learn_dictionary(self.data_generator(X),
                                                        self.n_atoms,
                                                        reg=self.penalty,
                                                        alpha=self.alpha,
                                                        max_steps=self.n_iter,
                                                        verbose=self.verbose,
                                                        D=self.fft_components_,
                                                        **extra_args)

        self.fft_components_ = D
        D = _cdl.diags_to_columns(D)
        D = _cdl.vectors_to_patches(D, width, pad_data=self.pad_data)
        self.components_ = D.swapaxes(1, 2).swapaxes(0, 1)
        self.encoder_ = encoder
        self.diagnostics_ = diagnostics
        return self