當前位置: 首頁>>代碼示例>>Python>>正文


Python tools.raises方法代碼示例

本文整理匯總了Python中nose.tools.raises方法的典型用法代碼示例。如果您正苦於以下問題:Python tools.raises方法的具體用法?Python tools.raises怎麽用?Python tools.raises使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nose.tools的用法示例。


在下文中一共展示了tools.raises方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_scipy_lbfgsb

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
def test_scipy_lbfgsb():
    sess = tf.Session()
    x = tf.Variable(np.float64(2), name='x')
    sess.run(tf.initialize_variables([x]))
    optimizer = ScipyLBFGSBOptimizer(verbose=True, session=sess)
    # With gradient
    results = optimizer.minimize([x], x**2, [2 * x])
    assert results.success
    # Without gradient
    results = optimizer.minimize([x], x**2)
    assert results.success
    # Test callback
    def callback(xs):
        pass
    optimizer = ScipyLBFGSBOptimizer(verbose=True, session=sess, callback=callback)
    assert optimizer.minimize([x], x**2).success
    @raises(ValueError)
    def test_illegal_parameter_as_variable1():
        optimizer.minimize([42], x**2)
    test_illegal_parameter_as_variable1()
    @raises(ValueError)
    def test_illegal_parameter_as_variable2():
        optimizer.minimize(42, x**2)
    test_illegal_parameter_as_variable2() 
開發者ID:tensorprob,項目名稱:tensorprob,代碼行數:26,代碼來源:test_optimizer.py

示例2: test_migrad

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
def test_migrad():
    sess = tf.Session()
    x = tf.Variable(np.float64(2), name='x')
    sess.run(tf.initialize_variables([x]))
    optimizer = MigradOptimizer(session=sess)
    # With gradient
    results = optimizer.minimize([x], x**2, [2 * x])
    assert results.success
    # Without gradient
    results = optimizer.minimize([x], x**2)
    assert results.success
    @raises(ValueError)
    def test_illegal_parameter_as_variable1():
        optimizer.minimize([42], x**2)
    test_illegal_parameter_as_variable1()
    @raises(ValueError)
    def test_illegal_parameter_as_variable2():
        optimizer.minimize(42, x**2)
    test_illegal_parameter_as_variable2() 
開發者ID:tensorprob,項目名稱:tensorprob,代碼行數:21,代碼來源:test_optimizer.py

示例3: test_init

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
def test_init():
    with tp.Model():
        X1 = tp.Uniform(lower=-1, upper=1)
        X2 = tp.Uniform(lower=-1)
        X3 = tp.Uniform(upper=1)
        X4 = tp.Uniform()
        X7 = tp.Uniform(lower=X1, upper=X2)


# @raises(ValueError)
# def test_uniform_fail_lower():
#     with tp.Model():
#         X1 = tp.Uniform()
#         X2 = tp.Uniform(lower=X1)


# @raises(ValueError)
# def test_uniform_fail_upper():
#     with tp.Model() as model:
#         X1 = tp.Uniform()
#         X2 = tp.Uniform(upper=X1) 
開發者ID:tensorprob,項目名稱:tensorprob,代碼行數:23,代碼來源:test_uniform.py

示例4: test_nose_import_error1

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
def test_nose_import_error1():
    _tmp = sys.modules['nose']
    sys.modules['nose'] = None
    try:
        from .. import test
        test()
    finally:
        sys.modules['nose'] = _tmp


# @raises(ImportError)
# def test_nose_import_error2():
#     _tmp = sys.modules['nose']
#     sys.modules['nose'] = None
#     try:
#         from .. import doctest
#         doctest()
#     finally:
#         sys.modules['nose'] = _tmp 
開發者ID:statlab,項目名稱:permute,代碼行數:21,代碼來源:test_importing.py

示例5: test_find_axes

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
def test_find_axes():
    def axes(ndim, pos, neg):
        network = tn.HyperparameterNode(
            "a",
            tn.InputNode("b", shape=()),
            pos=pos,
            neg=neg,
        ).network()["a"]
        return treeano.utils.find_axes(network, ndim, ["pos"], ["neg"])

    @nt.raises(AssertionError)
    def axes_raises(*args):
        axes(*args)

    nt.assert_equal(axes(3, [2], None), (2,))
    nt.assert_equal(axes(3, [1], None), (1,))
    nt.assert_equal(axes(3, None, [1]), (0, 2))
    nt.assert_equal(axes(3, None, [0, 1]), (2,))
    axes_raises(3, [2], [1]) 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:21,代碼來源:utils_test.py

示例6: test_concatenate_node_wrong_shape

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
def test_concatenate_node_wrong_shape():

    @nt.raises(AssertionError)
    def build_concatenate(axis, s1, s2, s3):
        tn.ConcatenateNode(
            "concat",
            [tn.InputNode("i1", shape=s1),
             tn.InputNode("i2", shape=s2),
             tn.InputNode("i3", shape=s3)],
            axis=axis,
        ).network().build()

    for args in [[100] + [(3, 2, 4)] * 3,
                 [0, (3, 2, 4), (3, 2, 4), (3, 3, 4)],
                 [0, (3, 2, 4), (3, 2, 4), (3, None, 4)], ]:
        build_concatenate(*args) 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:18,代碼來源:combine_test.py

示例7: test_dropout_node

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
def test_dropout_node():
    def make_network(p):
        return tn.SequentialNode("s", [
            tn.InputNode("i", shape=(3, 4, 5)),
            tn.DropoutNode("do", p=p)
        ]).network()

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

    @nt.raises(AssertionError)
    def test_not_identity():
        fn2 = make_network(0.5).function(["i"], ["s"])
        np.testing.assert_allclose(fn2(x)[0], x)

    test_not_identity() 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:19,代碼來源:stochastic_test.py

示例8: test_gaussian_dropout_node

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
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.assert_allclose(fn1(x)[0], x)

    @nt.raises(AssertionError)
    def test_not_identity():
        fn2 = make_network(0.5).function(["i"], ["s"])
        np.testing.assert_allclose(fn2(x)[0], x)

    test_not_identity() 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:19,代碼來源:stochastic_test.py

示例9: test_spatial_dropout_node

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
def test_spatial_dropout_node():
    def make_network(p):
        return tn.SequentialNode("s", [
            tn.InputNode("i", shape=(3, 6, 4, 5)),
            tn.SpatialDropoutNode("do", p=p)
        ]).network()

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

    @nt.raises(AssertionError)
    def test_not_identity():
        fn2 = make_network(0.5).function(["i"], ["s"])
        np.testing.assert_allclose(fn2(x)[0], x)

    test_not_identity()

    x = np.ones((3, 6, 4, 5)).astype(fX)
    fn3 = make_network(0.5).function(["i"], ["s"])
    out = fn3(x)[0]
    np.testing.assert_equal(out.std(axis=(2, 3)), np.zeros((3, 6), dtype=fX)) 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:24,代碼來源:stochastic_test.py

示例10: test_nanguardmode

# 需要導入模塊: from nose import tools [as 別名]
# 或者: from nose.tools import raises [as 別名]
def test_nanguardmode():
        # this is the case which requires a custom nanguardmode
        srng = MRG_RandomStreams()
        x = srng.uniform((3, 4, 5))

        def random_number(mode):
            return theano.function([], [x], mode=mode)()

        @nt.raises(AssertionError)
        def fails():
            random_number(theano.compile.nanguardmode.NanGuardMode(
                nan_is_error=True,
                inf_is_error=True,
                big_is_error=True
            ))

        fails()

        random_number(treeano.theano_extensions.nanguardmode.NanGuardMode(
            nan_is_error=True,
            inf_is_error=True,
            big_is_error=True
        )) 
開發者ID:SBU-BMI,項目名稱:u24_lymphocyte,代碼行數:25,代碼來源:nanguardmode_test.py


注:本文中的nose.tools.raises方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。