(self, layer_input, layer_dim)
return (z, y, p_X_chain)
Build a deep denoising autoencoder with tied weights. Implements
        walkback training (optional).

        Parameters
        ----------
        layer_dim : list
            Number of neurons for each layer of the autoencoder.

        Returns
        -------
        z : Tensor
            Inner-most latent representation.
        y : Tensor
            Output reconstruction of the input.
        p_X_chain : array
            Walkback training chain.
Build a deep denoising autoencoder with tied weights. Implements
        walkback training (optional).
Build a deep denoising autoencoder with tied weights . Implements walkback training ( optional ) .
def _autoencoder(self, layer_input, layer_dim):
        """Build a deep denoising autoencoder with tied weights. Implements
        walkback training (optional).

        Parameters
        ----------
        layer_dim : list
            Number of neurons for each layer of the autoencoder.

        Returns
        -------
        z : Tensor
            Inner-most latent representation.
        y : Tensor
            Output reconstruction of the input.
        p_X_chain : array
            Walkback training chain.
        """
        def corrupt_input(x, corrupt_prob, corrupt_std):
            """Corrupt data according to the corruption type.

            Parameters
            ----------
            x : Tensor
                Input placeholder to the network.
            corrupt_prob : float
                Probability of generating corrupted values.
            corrupt_std : float
                Standard deviation of corrupted values (Gaussian).

            Returns
            -------
            Corrupted data, x_corrupted.
            """
            if self.corrupt_type == 'salt_and_pepper':
                x_corrupted = salt_and_pepper_noise(x, corrupt_prob)
            elif self.corrupt_type == 'masking':
                x_corrupted = masking_noise(x, corrupt_prob)
            elif self.corrupt_type == 'gaussian':
                x_corrupted = gaussian_noise(x, std=corrupt_std) \
                    * corrupt_prob + x * (1 - corrupt_prob)
            else:
                x_corrupted = salt_and_pepper_noise(x, corrupt_prob)
            return x_corrupted

        def update_layers(x):
            """Perform layer updates.

            Parameters
            ----------
            x : Tensor
                Input placeholder to the network.

            Returns
            -------
            x : Tensor
                Input placeholder to the network.
            z : Tensor
                Inner-most latent representation.
            y : Tensor
                Output reconstruction of the input.
            """
            layer_input = corrupt_input(x, self.corrupt_prob, self.corrupt_std)

            # Build the encoder.
            encoder = []
            for layer_i, n_output in enumerate(layer_dim[1:]):
                n_input = int(layer_input.get_shape()[1])
                W = tf.Variable(self.W_init_fct(
                    [n_input, n_output]), dtype=tf.float32)
                b = tf.Variable(self.b_init_fct([n_output]), dtype=tf.float32)
                encoder.append(W)
                output = self.transfer_fct(
                    tf.add(tf.matmul(layer_input, W), b))
                layer_input = output

            # Latent representation.
            z = layer_input

            encoder.reverse()
            # Build the decoder using the same weights.
            for layer_i, n_output in enumerate(layer_dim[:-1][::-1]):
                n_input = int(layer_input.get_shape()[1])
                W = tf.transpose(encoder[layer_i])
                b = tf.Variable(self.b_init_fct([n_output]), dtype=tf.float32)
                output = self.transfer_fct(
                    tf.add(tf.matmul(layer_input, W), b))
                layer_input = output

            # Reconstruction through the network.
            y = layer_input

            return (x, y, z)

        # Define p(X|...).
        p_X_chain = []
        # Perform layer updates.
        if self.walkbacks > 0:
            x = layer_input
            for i in range(self.walkbacks):
                x, y, z = update_layers(x)
                p_X_chain.append(y)
                x = binomial_vec(y, shape=tf.shape(y))  # sample from p(X|...)
        else:
            x, y, z = update_layers(layer_input)

        return (z, y, p_X_chain)
def _autoencoder ( self , layer_input , layer_dim ) : def corrupt_input ( x , corrupt_prob , corrupt_std ) : """Corrupt data according to the corruption type.

            Parameters
            ----------
            x : Tensor
                Input placeholder to the network.
            corrupt_prob : float
                Probability of generating corrupted values.
            corrupt_std : float
                Standard deviation of corrupted values (Gaussian).

            Returns
            -------
            Corrupted data, x_corrupted.
            """ if self . corrupt_type == 'salt_and_pepper' : x_corrupted = salt_and_pepper_noise ( x , corrupt_prob ) elif self . corrupt_type == 'masking' : x_corrupted = masking_noise ( x , corrupt_prob ) elif self . corrupt_type == 'gaussian' : x_corrupted = gaussian_noise ( x , std = corrupt_std ) * corrupt_prob + x * ( 1 - corrupt_prob ) else : x_corrupted = salt_and_pepper_noise ( x , corrupt_prob ) return x_corrupted def update_layers ( x ) : """Perform layer updates.

            Parameters
            ----------
            x : Tensor
                Input placeholder to the network.

            Returns
            -------
            x : Tensor
                Input placeholder to the network.
            z : Tensor
                Inner-most latent representation.
            y : Tensor
                Output reconstruction of the input.
            """ layer_input = corrupt_input ( x , self . corrupt_prob , self . corrupt_std ) # Build the encoder. encoder = [ ] for layer_i , n_output in enumerate ( layer_dim [ 1 : ] ) : n_input = int ( layer_input . get_shape ( ) [ 1 ] ) W = tf . Variable ( self . W_init_fct ( [ n_input , n_output ] ) , dtype = tf . float32 ) b = tf . Variable ( self . b_init_fct ( [ n_output ] ) , dtype = tf . float32 ) encoder . append ( W ) output = self . transfer_fct ( tf . add ( tf . matmul ( layer_input , W ) , b ) ) layer_input = output # Latent representation. z = layer_input encoder . reverse ( ) # Build the decoder using the same weights. for layer_i , n_output in enumerate ( layer_dim [ : - 1 ] [ : : - 1 ] ) : n_input = int ( layer_input . get_shape ( ) [ 1 ] ) W = tf . transpose ( encoder [ layer_i ] ) b = tf . Variable ( self . b_init_fct ( [ n_output ] ) , dtype = tf . float32 ) output = self . transfer_fct ( tf . add ( tf . matmul ( layer_input , W ) , b ) ) layer_input = output # Reconstruction through the network. y = layer_input return ( x , y , z ) # Define p(X|...). p_X_chain = [ ] # Perform layer updates. if self . walkbacks > 0 : x = layer_input for i in range ( self . walkbacks ) : x , y , z = update_layers ( x ) p_X_chain . append ( y ) x = binomial_vec ( y , shape = tf . shape ( y ) ) # sample from p(X|...) else : x , y , z = update_layers ( layer_input ) return ( z , y , p_X_chain )