numpy.random.uniform.astype

Here are the examples of the python api numpy.random.uniform.astype taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

147 Examples 7

Example 1

Project: chainer
Source File: test_clipped_relu.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        # Avoid values around zero and z for stability of numerical gradient
        for i in numpy.ndindex(self.shape):
            if -0.01 < self.x[i] < 0.01 or 0.74 < self.x[i] < 0.76:
                self.x[i] = 0.5

        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.z = 0.75
        self.check_backward_options = {'dtype': numpy.float64}

Example 2

Project: chainer
Source File: test_elu.py
View license
    def setUp(self):
        # Avoid unstability of numeraical grad
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        for i in numpy.ndindex(self.shape):
            if -0.01 < self.x[i] < 0.01:
                self.x[i] = 0.5
        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.alpha = random.random()
        self.check_forward_options = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 5e-4, 'rtol': 5e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 3

Project: chainer
Source File: test_hard_sigmoid.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.g = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        # Avoid unstability of numerical grad
        for i in numpy.ndindex(self.shape):
            if -0.35 < self.x[i] < 0.15 or 0.15 < self.x[i] < 0.35:
                self.x[i] = 0.0

        self.check_forward_option = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype is numpy.float16:
            self.check_forward_option = {'atol': 1e-3, 'rtol': 1e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 4

Project: chainer
Source File: test_leaky_relu.py
View license
    def setUp(self):
        # Avoid unstability of numeraical grad
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        for i in numpy.ndindex(self.shape):
            if -0.05 < self.x[i] < 0.05:
                self.x[i] = 0.5
        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.slope = random.random()
        self.check_forward_options = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-4, 'rtol': 1e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 5

Project: chainer
Source File: test_lstm.py
View license
    def setUp(self):
        hidden_shape = (3, 2, 4)
        x_shape = (self.batch, 8, 4)
        y_shape = (self.batch, 2, 4)
        self.c_prev = numpy.random.uniform(
            -1, 1, hidden_shape).astype(self.dtype)
        self.x = numpy.random.uniform(-1, 1, x_shape).astype(self.dtype)

        self.gc = numpy.random.uniform(-1, 1, hidden_shape).astype(self.dtype)
        self.gh = numpy.random.uniform(-1, 1, y_shape).astype(self.dtype)

        self.check_forward_options = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-3, 'rtol': 1e-2}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 6

Project: chainer
Source File: test_prelu.py
View license
    def setUp(self):
        # Avoid unstability of numerical grad
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        for i in numpy.ndindex(self.shape):
            if -0.05 < self.x[i] < 0.05:
                self.x[i] = 0.5
        self.W = numpy.random.uniform(-1, 1, ()).astype(self.dtype)
        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.check_backward_options = {}
        if self.dtype == numpy.float16:
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 7

Project: chainer
Source File: test_relu.py
View license
    def setUp(self):
        # Avoid unstability of numerical grad
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        for i in numpy.ndindex(self.shape):
            if -0.1 < self.x[i] < 0.1:
                self.x[i] = 0.5
        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.check_backward_options = {}
        if self.dtype == numpy.float16:
            self.check_backward_options = {'dtype': numpy.float64}

Example 8

Project: chainer
Source File: test_sigmoid.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-.5, .5, self.shape).astype(self.dtype)
        self.gy = numpy.random.uniform(-.1, .1, self.shape).astype(self.dtype)
        self.check_forward_options = {}
        self.check_backward_options = {}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-4, 'rtol': 1e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 9

Project: chainer
Source File: test_slstm.py
View license
    def setUp(self):
        self.c_prev1 = numpy.random.uniform(-1,
                                            1, (3, 2, 4)).astype(self.dtype)
        self.c_prev2 = numpy.random.uniform(-1,
                                            1, (3, 2, 4)).astype(self.dtype)
        self.x1 = numpy.random.uniform(-1, 1, (3, 8, 4)).astype(self.dtype)
        self.x2 = numpy.random.uniform(-1, 1, (3, 8, 4)).astype(self.dtype)

        self.gc = numpy.random.uniform(-1, 1, (3, 2, 4)).astype(self.dtype)
        self.gh = numpy.random.uniform(-1, 1, (3, 2, 4)).astype(self.dtype)

        self.check_forward_options = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 5e-4, 'rtol': 5e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 10

Project: chainer
Source File: test_softplus.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.beta = numpy.random.uniform(1, 2, ())
        self.check_forward_options = {}
        self.check_backward_options = {}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 5e-4, 'rtol': 5e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 11

Project: chainer
Source File: test_tanh.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-.5, .5, self.shape).astype(self.dtype)
        self.gy = numpy.random.uniform(-.1, .1, self.shape).astype(self.dtype)
        self.check_backward_options = {}
        if self.dtype == numpy.float16:
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 1e-4, 'rtol': 1e-3}

Example 12

Project: chainer
Source File: test_dstack.py
View license
    def setUp(self):
        self.xs = [
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
            for i in six.moves.range(self.xs_length)
        ]
        self.g = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)

Example 13

Project: chainer
Source File: test_hstack.py
View license
    def setUp(self):
        self.xs = [
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
            for i in six.moves.range(self.xs_length)
        ]
        self.g = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)

Example 14

Project: chainer
Source File: test_select_item.py
View license
    def setUp(self):
        self.x_data = numpy.random.uniform(
            -1, 1, self.in_shape).astype(self.dtype)
        self.t_data = numpy.random.randint(
            0, 2, self.out_shape).astype(numpy.int32)
        self.gy_data = numpy.random.uniform(
            -1, 1, self.out_shape).astype(self.dtype)
        self.check_backward_options = {}
        if self.dtype == numpy.float16:
            self.check_backward_options = {'atol': 0.05, 'rtol': 0.05}

Example 15

Project: chainer
Source File: test_separate.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        yshape = list(self.shape)
        del yshape[self.axis]
        self.gys = [numpy.random.uniform(-1, 1, yshape).astype(self.dtype)
                    for _ in range(self.shape[self.axis])]
        self.check_backward_options = {}
        if self.dtype == numpy.float16:
            self.check_backward_options = {
                'eps': 2 ** -5, 'atol': 1e-3, 'rtol': 1e-2}

Example 16

Project: chainer
Source File: test_squeeze.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, (1, 1, 3, 1)).astype(self.dtype)
        self.g = numpy.random.uniform(-1, 1, self.out_shape).astype(self.dtype)

        self.check_forward_options = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 5e-4, 'rtol': 5e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 2 ** -4, 'rtol': 2 ** -4}

Example 17

Project: chainer
Source File: test_stack.py
View license
    def setUp(self):
        self.xs = [
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype),
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype),
        ]
        self.g = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)

Example 18

Project: chainer
Source File: test_tile.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.in_shape).astype(self.dtype)
        out_shape = numpy.tile(self.x, self.reps).shape
        self.g = numpy.random.uniform(-1, 1, out_shape).astype(self.dtype)

        self.check_forward_options = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 5e-4, 'rtol': 5e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 2 ** -4, 'rtol': 2 ** -4}

Example 19

Project: chainer
Source File: test_vstack.py
View license
    def setUp(self):
        self.xs = [
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
            for i in six.moves.range(self.xs_length)
        ]
        self.g = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)

Example 20

Project: chainer
Source File: test_linear.py
View license
    def setUp(self):
        self.W = numpy.random.uniform(
            -1, 1, (2, 3)).astype(self.W_dtype)
        self.b = numpy.random.uniform(
            -1, 1, 2).astype(self.x_dtype)

        self.x = numpy.random.uniform(-1, 1, (4, 3)).astype(self.x_dtype)
        self.gy = numpy.random.uniform(-1, 1, (4, 2)).astype(self.x_dtype)
        self.y = self.x.dot(self.W.T) + self.b
        self.check_forward_options = {}
        self.check_backward_options = {}
        if self.x_dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-3, 'rtol': 1e-2}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}
        elif self.W_dtype == numpy.float16:
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 21

Project: chainer
Source File: test_accuracy.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.x_shape).astype(self.dtype)
        if self.t_data == 'randint':
            self.t = numpy.random.randint(
                3, size=self.t_shape).astype(numpy.int32)
        elif self.t_data == 'zero':
            self.t = numpy.zeros(self.t_shape).astype(numpy.int32)
        self.check_forward_options = {}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-4, 'rtol': 1e-3}

Example 22

Project: chainer
Source File: test_binary_accuracy.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.t = numpy.random.randint(-1, 2, self.shape).astype(numpy.int32)
        self.check_forward_options = {}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-4, 'rtol': 1e-3}

Example 23

View license
    def setUp(self):
        t_upper = 3 if self.label_num is None else self.label_num
        self.label_num = 3
        self.y = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)
        self.t = make_ground_truth(t_upper, self.t_shape,
                                   self.ignore_label, self.has_ignore_label)
        self.check_forward_options = {}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-4, 'rtol': 1e-3}

        # Suppress warning that arises from zero division.
        warnings.filterwarnings('ignore', category=RuntimeWarning)

Example 24

Project: chainer
Source File: test_basic_math.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        for i in numpy.ndindex(self.shape):
            if -0.1 < self.x[i] < 0.1:
                self.x[i] = 0.5
        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)

Example 25

Project: chainer
Source File: test_clip.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        # Avoid values around x_min and x_max for stability of numerical
        # gradient
        for ind in numpy.ndindex(self.x.shape):
            if -0.76 < self.x[ind] < -0.74:
                self.x[ind] = -0.5
            elif 0.74 < self.x[ind] < 0.76:
                self.x[ind] = 0.5
        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.x_min = -0.75
        self.x_max = 0.75

Example 26

Project: chainer
Source File: test_linear_interpolate.py
View license
    def setUp(self):
        self.p = numpy.random.uniform(0, 1, self.shape).astype(self.dtype)
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.y = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.g = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)

        self.check_forward_options = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-3, 'rtol': 1e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 27

Project: chainer
Source File: test_logsumexp.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, (3, 2, 4)).astype(self.dtype)
        self.gy = numpy.random.uniform(-1, 1, ()).astype(self.dtype)
        self.check_forward_option = {}
        self.check_backward_option = {
            'eps': 2.0 ** -5, 'rtol': 1.0e-4, 'atol': 1.0e-4}
        if self.dtype == numpy.float16:
            self.check_forward_option = {'rtol': 1.0e-2, 'atol': 1.0e-2}
            self.check_backward_option = {
                'eps': 2.0 ** -3, 'rtol': 1.0e-2, 'atol': 1.0e-2}

Example 28

Project: chainer
Source File: test_maximum.py
View license
    def setUp(self):
        shape = self.shape
        self.x1 = numpy.random.uniform(-1, 1, shape).astype(self.dtype)
        self.x2 = numpy.random.uniform(-1, 1, shape).astype(self.dtype)
        # Avoid close values for stability in numerical gradient.
        for i in numpy.ndindex(shape):
            if -0.125 < self.x1[i] - self.x2[i] < 0.125:
                self.x1[i] = -0.5
                self.x2[i] = 0.5
        self.y_expected = numpy.maximum(self.x1, self.x2)
        self.gy = numpy.random.uniform(-1, 1, shape).astype(self.dtype)
        self.check_forward_options = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-4, 'rtol': 1e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 29

Project: chainer
Source File: test_maximum.py
View license
    def test_maximum_inconsistent_types(self):
        if self.dtype1 == self.dtype2:
            return
        x1_data = numpy.random.uniform(-1, 1, (3, 2)).astype(self.dtype1)
        x2_data = numpy.random.uniform(-1, 1, (3, 2)).astype(self.dtype2)
        x1 = chainer.Variable(x1_data)
        x2 = chainer.Variable(x2_data)
        with self.assertRaises(type_check.InvalidType):
            functions.maximum(x1, x2)

Example 30

Project: chainer
Source File: test_maximum.py
View license
    def test_maximum_inconsistent_shapes(self):
        x1_data = numpy.random.uniform(-1, 1, (3, 2)).astype(self.dtype)
        x2_data = numpy.random.uniform(-1, 1, (2, 3)).astype(self.dtype)
        x1 = chainer.Variable(x1_data)
        x2 = chainer.Variable(x2_data)
        with self.assertRaises(type_check.InvalidType):
            functions.maximum(x1, x2)

Example 31

Project: chainer
Source File: test_minimum.py
View license
    def setUp(self):
        shape = self.shape
        self.x1 = numpy.random.uniform(-1, 1, shape).astype(self.dtype)
        self.x2 = numpy.random.uniform(-1, 1, shape).astype(self.dtype)
        # Avoid close values for stability in numerical gradient.
        for i in numpy.ndindex(shape):
            if -0.125 < self.x1[i] - self.x2[i] < 0.125:
                self.x1[i] = -0.5
                self.x2[i] = 0.5
        self.y_expected = numpy.minimum(self.x1, self.x2)
        self.gy = numpy.random.uniform(-1, 1, shape).astype(self.dtype)
        self.check_forward_options = {}
        self.check_backward_options = {'eps': 1e-2}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-4, 'rtol': 1e-3}
            self.check_backward_options = {
                'eps': 2 ** -3, 'atol': 1e-2, 'rtol': 1e-1}

Example 32

Project: chainer
Source File: test_minimum.py
View license
    def test_minimum_inconsistent_types(self):
        if self.dtype1 == self.dtype2:
            return
        x1_data = numpy.random.uniform(-1, 1, (3, 2)).astype(self.dtype1)
        x2_data = numpy.random.uniform(-1, 1, (3, 2)).astype(self.dtype2)
        x1 = chainer.Variable(x1_data)
        x2 = chainer.Variable(x2_data)
        with self.assertRaises(type_check.InvalidType):
            functions.minimum(x1, x2)

Example 33

Project: chainer
Source File: test_minimum.py
View license
    def test_minimum_inconsistent_shapes(self):
        x1_data = numpy.random.uniform(-1, 1, (3, 2)).astype(self.dtype)
        x2_data = numpy.random.uniform(-1, 1, (2, 3)).astype(self.dtype)
        x1 = chainer.Variable(x1_data)
        x2 = chainer.Variable(x2_data)
        with self.assertRaises(type_check.InvalidType):
            functions.minimum(x1, x2)

Example 34

Project: chainer
Source File: test_sum.py
View license
    @attr.gpu
    @condition.retry(3)
    def test_backward_zerodim_gpu(self):
        x = numpy.random.uniform(-1, 1, ()).astype(self.dtype)
        gy = numpy.random.uniform(-1, 1, ()).astype(self.dtype)
        self.check_backward(cuda.to_gpu(x), cuda.to_gpu(gy))

Example 35

Project: chainer
Source File: test_trigonometric.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(.5, 1, self.shape).astype(self.dtype)
        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        self.func = getattr(F, self.func_name)
        camel_name = self.func_name[0].upper() + self.func_name[1:]
        self.func_class = getattr(F, camel_name)
        self.np_func = getattr(numpy, self.func_name)

        if self.dtype == numpy.float16:
            self.backward_options = {
                'eps': 2 ** -4, 'atol': 2 ** -4, 'rtol': 2 ** -4}
        else:
            self.backward_options = {}

Example 36

Project: chainer
Source File: test_dropout.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, (2, 3)).astype(self.dtype)
        self.gy = numpy.random.uniform(-1, 1, (2, 3)).astype(self.dtype)

        self.check_backward_options = {}
        if self.dtype == numpy.float16:
            self.check_backward_options = {
                'atol': 5e-4, 'rtol': 5e-3}

Example 37

View license
    def setUp(self):
        self.x = numpy.random.uniform(
            -1, 1, (2, 7, 3, 2)).astype(self.dtype)
        self.gy = numpy.random.uniform(
            -1, 1, (2, 7, 3, 2)).astype(self.dtype)
        self.check_forward_optionss = {}
        self.check_backward_optionss = {}
        if self.dtype == numpy.float16:
            self.check_forward_optionss = {'atol': 1e-4, 'rtol': 1e-3}
            self.check_backward_optionss = {'atol': 5e-3, 'rtol': 5e-3}

Example 38

Project: chainer
Source File: test_average_pooling_2d.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1,
                                      (2, 3, 4, 3)).astype(self.dtype)
        self.gy = numpy.random.uniform(-1, 1,
                                       (2, 3, 2, 2)).astype(self.dtype)
        self.check_forward_options = {}
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 5e-4, 'rtol': 5e-3}
            self.check_backward_options = {
                'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3}

Example 39

Project: chainer
Source File: test_convolution_2d.py
View license
    def setUp(self):
        self.link = links.Convolution2D(
            3, 2, 3, stride=2, pad=1,
            initialW=chainer.initializers.Normal(1, self.W_dtype),
            initial_bias=chainer.initializers.Normal(1, self.x_dtype))
        self.link.cleargrads()

        self.x = numpy.random.uniform(-1, 1,
                                      (2, 3, 4, 3)).astype(self.x_dtype)
        self.gy = numpy.random.uniform(-1, 1,
                                       (2, 2, 2, 2)).astype(self.x_dtype)
        self.check_backward_options = {}
        if self.x_dtype == numpy.float16 or self.W_dtype == numpy.float16:
            self.check_backward_options = {'atol': 3e-2, 'rtol': 5e-2}

Example 40

View license
    def __init__(self, optimizer, dtype):
        self.dtype = dtype
        self.model = L.Linear(self.UNIT_NUM, 2)
        self.model.W.data = self.model.W.data.astype(dtype)
        self.model.b.data = self.model.b.data.astype(dtype)
        self.model.W.grad = self.model.W.grad.astype(dtype)
        self.model.b.grad = self.model.b.grad.astype(dtype)

        self.optimizer = optimizer
        # true parameters
        self.w = numpy.random.uniform(
            -1, 1, (self.UNIT_NUM, 1)).astype(dtype)
        self.b = numpy.random.uniform(-1, 1, (1, )).astype(dtype)

Example 41

Project: cupy
Source File: test_dstack.py
View license
    def setUp(self):
        self.xs = [
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
            for i in six.moves.range(self.xs_length)
        ]
        self.g = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)

Example 42

Project: cupy
Source File: test_hstack.py
View license
    def setUp(self):
        self.xs = [
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
            for i in six.moves.range(self.xs_length)
        ]
        self.g = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)

Example 43

Project: cupy
Source File: test_separate.py
View license
    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        yshape = list(self.shape)
        del yshape[self.axis]
        self.gys = [numpy.random.uniform(-1, 1, yshape).astype(self.dtype)
                    for _ in range(self.shape[self.axis])]
        self.check_backward_options = {}
        if self.dtype == numpy.float16:
            self.check_backward_options = {
                'eps': 2 ** -5, 'atol': 1e-3, 'rtol': 1e-2}

Example 44

Project: cupy
Source File: test_stack.py
View license
    def setUp(self):
        self.xs = [
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype),
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype),
        ]
        self.g = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)

Example 45

Project: cupy
Source File: test_vstack.py
View license
    def setUp(self):
        self.xs = [
            numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
            for i in six.moves.range(self.xs_length)
        ]
        self.g = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)

Example 46

Project: cupy
Source File: test_classification_summary.py
View license
    def setUp(self):
        t_upper = 3 if self.label_num is None else self.label_num
        self.label_num = 3
        self.y = numpy.random.uniform(-1, 1, self.y_shape).astype(self.dtype)
        self.t = make_ground_truth(t_upper, self.t_shape,
                                   self.ignore_label, self.has_ignore_label)
        self.check_forward_options = {}
        if self.dtype == numpy.float16:
            self.check_forward_options = {'atol': 1e-4, 'rtol': 1e-3}

        # Suppress warning that arises from zero division.
        warnings.filterwarnings('ignore', category=RuntimeWarning)

Example 47

Project: Dracula
Source File: train.py
View license
    def __init__(self, input, dim1, dim2):
        """Create the hidden layer"""
        self.W = theano.shared(name='W',
                               value=np.random.uniform(-0.2, 0.2, (dim1 * dim2))
                               .astype(theano.config.floatX))

        self.b = theano.shared(name='b',
                               value=np.zeros(dim2,).astype(theano.config.floatX))


        self.output = T.tanh(T.dot(input, self.W) + self.b)

        self.params = [self.W, self.b]

Example 48

Project: Dracula
Source File: train.py
View license
    def __init__(self, dim0, dim1, dim2):
        self.emb = theano.shared(name='embeddings',
                                 value=np.random.uniform(-0.2, 0.2, (dim0, dim1))
                                 .astype(theano.config.floatX))
        self.x = T.vector('x', dtype='int32')
        self.e = self.emb[self.x].reshape([dim0 * dim1])
        self.hidden = HiddenLayer(self.e, dim0*dim1, dim2)
        self.output = T.nnet.softmax(self.hidden.output)

        self.forward = theano.function(inputs=[self.x], outputs=[self.output])

Example 49

Project: neon
Source File: test_backend_batched_dot.py
View license
def setup_test_data(X, N, C, K, dtype):
    dimW = (K, C)
    dimI = (X, C, N)
    dimO = (X, K, N)

    cpuI = np.random.uniform(-1.0, 1.0, dimI).astype(dtype)
    cpuE = np.random.uniform(-1.0, 1.0, dimO).astype(dtype)
    cpuW = np.random.uniform(-1.0, 1.0, dimW).astype(dtype)

    return cpuI, cpuE, cpuW

Example 50

Project: neon
Source File: test_backend_tensor.py
View license
@pytest.mark.hasgpu
def test_reshape_separate(fargs_tests, backend_pair_dtype):
    dims = fargs_tests[0]

    gpu, cpu = backend_pair_dtype
    dtype = gpu.default_dtype

    array_np = np.random.uniform(-1, 1, dims).astype(dtype)
    array_ng = gpu.array(array_np, dtype=dtype)
    array_nc = cpu.array(array_np, dtype=dtype)

    assert array_ng.is_contiguous

    if (dims[0] % 2) == 0:
        reshaped_ng = array_ng.reshape((2, dims[0] // 2, dims[1]))
        reshaped_nc = array_nc.reshape((2, dims[0] // 2, dims[1]))

        assert tensors_allclose(reshaped_ng, reshaped_nc, rtol=0, atol=1e-6)