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)
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)
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)
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)
def __call__(self, array): fan_in, fan_out = initializer.get_fans(array.shape) s = self.scale * numpy.sqrt(3. / fan_in) Uniform(s)(array)
def test_invalid(self): with self.assertRaises(ValueError): initializer.get_fans(self.shape)
def test_get_fans(self): actual = initializer.get_fans(self.shape) self.assertTupleEqual(self.expect, actual)
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)
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)
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)
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)
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)