Пример #1
0
 def __call__(self, array):
     if len(array.shape) == 1:
         fan_in = array.shape[0]
     else:
         fan_in, fan_out = initializer.get_fans(array.shape)
     fill_value = self.scale / np.sqrt(fan_in)
     initializers.Constant(fill_value)(array)
Пример #2
0
 def __call__(self, array):
     if self.dtype is not None:
         assert array.dtype == self.dtype,\
             '{} != {}'.format(array.dtype, self.dtype)
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(3. / fan_in)
     Uniform(s, rng=self.rng)(array)
Пример #3
0
    def __call__(self, array):
        if self.dtype is not None:
            assert array.dtype == self.dtype
        fan_in, fan_out = initializer.get_fans(array.shape)

        if self.criterion == 'glorot':
            s = np.sqrt(1. / (fan_in + fan_out))
        elif self.criterion == 'he':
            s = np.sqrt(1. / fan_in)
        else:
            raise ValueError('Invalid criterion: ' + self.criterion)
        
        
        xp = cuda.get_array_module(array)
        if xp is not np:
            # Only CuPy supports dtype option
            if self.dtype == np.float32 or self.dtype == np.float16:
                # float16 is not supported in cuRAND
                args['dtype'] = np.float32

        [a,b,c,d] = array.shape
        #### Rayleigh distribution
        x_ran = xp.random.uniform(0,1,[a/2,b,c,d])
        modulus = s * xp.sqrt(-2*xp.log(x_ran))

        phase = xp.random.uniform(low=-np.pi, high=np.pi, size=[a/2,b,c,d])

        weight_real = modulus * xp.cos(phase)
        weight_imag = modulus * xp.sin(phase)
        weight = xp.concatenate([weight_real, weight_imag])

        array[...] = weight
Пример #4
0
 def __call__(self, array):
     if self.dtype is not None:
         assert array.dtype == self.dtype
     fan_in, _ = initializer.get_fans(array.shape)
     gain = self._calculate_gain(self._a)
     std = gain / np.sqrt(fan_in)
     bound = np.sqrt(3.0) * std
     Uniform(scale=bound, dtype=self.dtype)(array)
Пример #5
0
    def __call__(self, array):
        if self.dtype is not None:
            assert array.dtype == self.dtype

        if len(array.shape) == 1:
            Constant(self.scale / numpy.sqrt(array.shape[0]))(array)
        else:
            fan_in, _ = initializer.get_fans(array.shape)

            Constant(self.scale / numpy.sqrt(fan_in))(array)
Пример #6
0
 def __call__(self, array):
     if self.dtype is not None:
         assert array.dtype == self.dtype
     fan_in, fan_out = initializer.get_fans(array.shape)
     if self.fan_option == 'fan_in':
         s = self.scale * numpy.sqrt(2. / fan_in)
     elif self.fan_option == 'fan_out':
         s = self.scale * numpy.sqrt(2. / fan_out)
     else:
         raise ValueError(
             'fan_option should be either \'fan_in\' or \'fan_out\'.')
     Normal(s)(array)
Пример #7
0
 def __call__(self, array):
     if self.dtype is not None:
         assert array.dtype == self.dtype
     fan_in, fan_out = initializer.get_fans(array.shape)
     if self.fan_option == 'fan_in':
         s = self.scale * numpy.sqrt(2. / fan_in)
     elif self.fan_option == 'fan_out':
         s = self.scale * numpy.sqrt(2. / fan_out)
     else:
         raise ValueError(
             'fan_option should be either \'fan_in\' or \'fan_out\'.')
     Normal(s)(array)
Пример #8
0
 def __call__(self, array):
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(3. / fan_in)
     Uniform(s)(array)
Пример #9
0
 def test_invalid(self):
     with self.assertRaises(ValueError):
         initializer.get_fans(self.shape)
Пример #10
0
 def test_get_fans(self):
     actual = initializer.get_fans(self.shape)
     self.assertTupleEqual(self.expect, actual)
Пример #11
0
 def test_invalid(self):
     with self.assertRaises(ValueError):
         initializer.get_fans(self.shape)
Пример #12
0
 def test_get_fans(self):
     actual = initializer.get_fans(self.shape)
     self.assertTupleEqual(self.expect, actual)
Пример #13
0
 def __call__(self, array):
     if self.dtype is not None:
         assert array.dtype == self.dtype
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(2. / fan_in)
     Normal(s)(array)
Пример #14
0
 def __call__(self, array):
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(6. / (fan_in + fan_out))
     return Uniform(s)(array)
Пример #15
0
 def __call__(self, array):
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(6. / (fan_in + fan_out))
     return Uniform(s)(array)
Пример #16
0
 def __call__(self, array):
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(3. / fan_in)
     Uniform(s)(array)
Пример #17
0
 def __call__(self, array):
     if self.dtype is not None:
         assert array.dtype == self.dtype
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(6. / (fan_in + fan_out))
     Uniform(s)(array)
Пример #18
0
 def __call__(self, array):
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(2. / fan_in)
     return Normal(s)(array)
Пример #19
0
 def __call__(self, array):
     if self.dtype is not None:
         assert array.dtype == self.dtype
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(6. / (fan_in + fan_out))
     Uniform(s)(array)
Пример #20
0
 def __call__(self, array):
     if self.dtype is not None:
         assert array.dtype == self.dtype
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * np.sqrt(1. / fan_in)
     Normal(s)(array)
Пример #21
0
 def __call__(self, array):
     fan_in, fan_out = initializer.get_fans(array.shape)
     s = self.scale * numpy.sqrt(2. / fan_in)
     return Normal(s)(array)