numpy.random.randn.astype - python examples

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

145 Examples 7

3 View Complete Implementation : simple_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
def test_send_to_node():
    network = tn.ContainerNode("c", [
        tn.SequentialNode(
            "s1",
            [tn.InputNode("in", shape=(3, 4, 5)),
             tn.SendToNode("stn1", reference="s2")]),
        tn.SequentialNode(
            "s2",
            [tn.SendToNode("stn2", reference="stn3")]),
        tn.SequentialNode(
            "s3",
            [tn.SendToNode("stn3", reference="i")]),
        tn.IdensatyNode("i"),
    ]).network()

    fn = network.function(["in"], ["i"])
    x = np.random.randn(3, 4, 5).astype(fX)
    np.testing.astert_allclose(fn(x)[0], x)

3 View Complete Implementation : stochastic_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
def test_gaussian_dropout_node():
    def make_network(p):
        return tn.SequentialNode("s", [
            tn.InputNode("i", shape=(3, 4, 5)),
            tn.GaussianDropoutNode("do", p=p)
        ]).network()

    x = np.random.randn(3, 4, 5).astype(fX)
    fn1 = make_network(0).function(["i"], ["s"])
    np.testing.astert_allclose(fn1(x)[0], x)

    @nt.raises(astertionError)
    def test_not_idensaty():
        fn2 = make_network(0.5).function(["i"], ["s"])
        np.testing.astert_allclose(fn2(x)[0], x)

    test_not_idensaty()

3 View Complete Implementation : recurrent_convolution_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
    def test_default_recurrent_conv_2d_node():
        network = tn.SequentialNode(
            "s",
            [tn.InputNode("i", shape=(3, 4, 5, 6)),
             rcl.DefaultRecurrentConv2DNode("a",
                                            num_filters=7,
                                            filter_size=(3, 3),
                                            pad="same")]
        ).network()
        fn = network.function(["i"], ["s"])
        res = fn(np.random.randn(3, 4, 5, 6).astype(fX))[0]
        np.testing.astert_equal((3, 7, 5, 6), res.shape)

3 View Complete Implementation : composite_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
def test_dense_combine_node():
    network = tn.SequentialNode(
        "seq",
        [tn.InputNode("in", shape=(3, 4, 5)),
         tn.DenseCombineNode("fc1", [tn.IdensatyNode("i1")], num_units=6),
         tn.DenseCombineNode("fc2", [tn.IdensatyNode("i2")], num_units=7),
         tn.DenseCombineNode("fc3", [tn.IdensatyNode("i3")], num_units=8)]
    ).network()
    x = np.random.randn(3, 4, 5).astype(fX)
    fn = network.function(["in"], ["fc3"])
    res = fn(x)[0]
    nt.astert_equal(res.shape, (3, 8))

3 View Complete Implementation : downsample_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
def test_custom_global_pool_node():
    network = tn.SequentialNode(
        "s",
        [tn.InputNode("i", shape=(6, 5, 4, 3)),
         tn.CustomGlobalPoolNode("gp", pool_function=T.mean)]
    ).network()
    fn = network.function(["i"], ["s"])
    x = np.random.randn(6, 5, 4, 3).astype(fX)
    ans = x.mean(axis=(2, 3))
    np.testing.astert_allclose(ans,
                               fn(x)[0],
                               rtol=1e-5,
                               atol=1e-7)

3 View Complete Implementation : theanode_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
def test_dimshuffle_node():
    network = tn.SequentialNode(
        "s",
        [tn.InputNode("in", shape=(3, 4, 5)),
         tn.DimshuffleNode("r", pattern=(1, "x", 0, 2))]
    ).network()
    fn = network.function(["in"], ["s"])
    x = np.random.randn(3, 4, 5).astype(fX)
    ans = T.constant(x).dimshuffle(1, "x", 0, 2).eval()
    res = fn(x)[0]
    np.testing.astert_equal(res.shape, ans.shape)
    np.testing.astert_equal(res, ans)

3 View Complete Implementation : downsample_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
def test_custom_global_pool_node():
    network = tn.SequentialNode(
        "s",
        [tn.InputNode("i", shape=(6, 5, 4, 3)),
         tn.CustomGlobalPoolNode("gp", pool_function=T.mean)]
    ).network()
    fn = network.function(["i"], ["s"])
    x = np.random.randn(6, 5, 4, 3).astype(fX)
    ans = x.mean(axis=(2, 3))
    np.testing.astert_allclose(ans,
                               fn(x)[0],
                               rtol=1e-5,
                               atol=1e-7)

3 View Complete Implementation : simple_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
def test_apply_node():
    network = tn.SequentialNode("s", [
        tn.InputNode("in", shape=(3, 4, 5)),
        tn.ApplyNode("a", fn=T.sum, shape_fn=lambda x: ()),
    ]).network()
    fn = network.function(["in"], ["s"])
    x = np.random.randn(3, 4, 5).astype(fX)
    np.testing.astert_allclose(fn(x)[0],
                               x.sum(),
                               rtol=1e-5)

3 View Complete Implementation : gradnet_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
def test_grad_net_interpolation_node():
    network = tn.SequentialNode(
        "s",
        [tn.InputNode("i", shape=(1, 10)),
         gradnet.GradNetInterpolationNode(
             "gradnet",
             {"early": tn.ReLUNode("r"),
              "late": tn.TanhNode("t")},
             late_gate=0.5)]
    ).network()

    fn = network.function(["i"], ["s"])
    x = np.random.randn(1, 10).astype(fX)
    ans = 0.5 * np.clip(x, 0, np.inf) + 0.5 * np.tanh(x)
    np.testing.astert_allclose(ans, fn(x)[0], rtol=1e-5)

3 View Complete Implementation : theanode_test.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : SBU-BMI
def test_repeat_node():
    network = tn.SequentialNode(
        "s",
        [tn.InputNode("in", shape=(3,)),
         tn.RepeatNode("r", repeats=2, axis=0)]
    ).network()
    fn = network.function(["in"], ["s"])
    x = np.random.randn(3).astype(fX)
    np.testing.astert_allclose(np.repeat(x, 2, 0),
                               fn(x)[0])