示例#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)
 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
 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
文件: uniform.py 项目: zwcdp/chainer
 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
文件: uniform.py 项目: 2php/chainer
 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
文件: uniform.py 项目: zwcdp/chainer
 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
文件: normal.py 项目: 2php/chainer
 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)