当前位置: 首页>>代码示例>>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;未经允许,请勿转载。