Exemplo n.º 1
0
    def set_codebook(self, D):
        '''Clobber the existing codebook and encoder with a new one.'''

        self.components_ = D

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

        D = D.swapaxes(0, 1).swapaxes(1, 2)
        D = _cdl.patches_to_vectors(D, pad_data=self.pad_data)
        D = _cdl.columns_to_diags(D)
        self.fft_components_ = D

        encoder, D, diagnostics = _cdl.learn_dictionary([],
                                                        self.n_atoms,
                                                        reg=self.penalty,
                                                        alpha=self.alpha,
                                                        max_steps=0,
                                                        verbose=False,
                                                        D=D,
                                                        **extra_args)
        self.encoder_ = encoder
        return self
Exemplo n.º 2
0
Arquivo: CDL.py Projeto: CityU-HAN/CDL
    def set_codebook(self, D):
        '''Clobber the existing codebook and encoder with a new one.'''

        self.components_ = D

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

        D = D.swapaxes(0, 1).swapaxes(1, 2)
        D = _cdl.patches_to_vectors(D, pad_data=self.pad_data)
        D = _cdl.columns_to_diags(D)
        self.fft_components_ = D

        encoder, D, diagnostics = _cdl.learn_dictionary(
                                        [],
                                        self.n_atoms,
                                        reg         = self.penalty,
                                        alpha       = self.alpha,
                                        max_steps   = 0,
                                        verbose     = False,
                                        D           = D, 
                                        **extra_args)
        self.encoder_ = encoder
        return self
Exemplo n.º 3
0
Arquivo: CDL.py Projeto: CityU-HAN/CDL
    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
Exemplo n.º 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