Ejemplo n.º 1
0
 def __call__(self, shape):
     self._assert_atleast2d(shape)
     if shape[1] < self.connections:
         raise InitializationError("Output dimension to small: {} < {}"
                                   "".format(shape[1], self.connections))
     sub_result = evaluate_initializer(self.sub_initializer, shape)
     connection_mask = np.zeros(shape)
     connection_mask[:, :self.connections] = 1.
     for i in range(shape[0]):
         self.rnd.shuffle(connection_mask[i, :])
     return sub_result * connection_mask
Ejemplo n.º 2
0
 def __call__(self, shape):
     if shape[0] % 4 != 0:
         raise InitializationError("First dim of LstmOpt shape needs to be "
                                   "divisible by 4. But shape was {}"
                                   .format(shape))
     weights = np.zeros(shape)
     n = shape[0] // 4
     sub_shape = (n,) + shape[1:]
     weights[:n] = evaluate_initializer(
         self.block_input, sub_shape, seed=self.rnd.generate_seed())
     weights[n:2 * n] = evaluate_initializer(
         self.input_gate, sub_shape, seed=self.rnd.generate_seed())
     weights[2 * n:3 * n] = evaluate_initializer(
         self.forget_gate, sub_shape, seed=self.rnd.generate_seed())
     weights[3 * n:] = evaluate_initializer(
         self.output_gate, sub_shape, seed=self.rnd.generate_seed())
     return weights
Ejemplo n.º 3
0
    def __call__(self, shape):
        if not self.array.shape == shape:
            raise InitializationError('Shape mismatch {} != {}'
                                      .format(self.array.shape, shape))

        return self.array
Ejemplo n.º 4
0
 def _assert_atleast2d(self, shape):
     if len(shape) < 2:
         raise InitializationError(
             "{} only works on >2D matrices, but shape was {}".format(
                 self.__class__.__name__, shape))