Ejemplo n.º 1
0
    def get_corrupted_input(self, input, corruption_level):
        """ This function keeps ``1-corruption_level`` entries of the inputs the same 
        and zero-out randomly selected subset of size ``coruption_level`` 
        Note : first argument of theano.rng.binomial is the shape(size) of 
               random numbers that it should produce
               second argument is the number of trials 
               third argument is the probability of success of any trial
        
                this will produce an array of 0s and 1s where 1 has a probability of 
                1 - ``corruption_level`` and 0 with ``corruption_level``

                The binomial function return int64 data type by default. 
                int64 multiplicated by the input type(floatX) always return float64.
                To keep all data in floatX when floatX is float32, we set the dtype
                of the binomial to floatX. As in our case the value of the binomial 
                is always 0 or 1, this don't change the result. This is needed to allow
                the gpu to work correctly as it only support float32 for now.
        """
        
        n = input.shape[0]
        shuffled = T.permute_row_elements(input.T, self.theano_rng.permutation(n=n)).T
        d = T.cast(self.n_visible * corruption_level, 'int32')
        start = self.theano_rng.random_integers(low = 0, high = self.n_visible - d) 
        end = start + d
        corrupted = T.set_subtensor(input[:, start:end], shuffled[:, start:end])
        return  self.theano_rng.binomial( size = input.shape, n = 1, p =  1 - corruption_level, dtype=theano.config.floatX) * corrupted
Ejemplo n.º 2
0
    def shuffle_row_elements(self, input):
        """Return a variable with every row (rightmost index) shuffled.

        This uses permutation random variable internally, available via
        the ``.permutation`` attribute of the return value.
        """
        perm = self.permutation(size=input.shape[:-1], n=input.shape[-1], ndim=input.ndim - 1)
        shuffled = tensor.permute_row_elements(input, perm)
        shuffled.permutation = perm
        return shuffled
Ejemplo n.º 3
0
    def shuffle_row_elements(self, input):
        """Return a variable with every row (rightmost index) shuffled.

        This uses permutation random variable internally, available via
        the ``.permutation`` attribute of the return value.
        """
        perm = self.permutation(size=input.shape[:-1], n=input.shape[-1],
                                ndim=input.ndim - 1)
        shuffled = tensor.permute_row_elements(input, perm)
        shuffled.permutation = perm
        return shuffled
 def inverse_map(self, y):
     return tt.permute_row_elements(y, self.perm, inverse=True)
 def forward_map(self, x):
     return tt.permute_row_elements(x, self.perm)
Ejemplo n.º 6
0
def theano_shuffled(input):
    n = input.shape[0]
    shuffled = T.permute_row_elements(input.T, _srng.permutation(n=n)).T
    return shuffled
Ejemplo n.º 7
0
 def _theano_shuffled(self, input):
     n = input.shape[0]
     shuffled = T.permute_row_elements(input.T, self.rng.permutation(n=n)).T
     return shuffled
Ejemplo n.º 8
0
        def theano_shuffled(in_vw):
            n = in_vw.shape[0]

            shuffled = T.permute_row_elements(in_vw.T, srng.permutation(n=n)).T
            return shuffled