本文整理汇总了Python中theano.tensor.scalars函数的典型用法代码示例。如果您正苦于以下问题:Python scalars函数的具体用法?Python scalars怎么用?Python scalars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了scalars函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_ifelse
def test_ifelse(self):
config1 = theano.config.profile
config2 = theano.config.profile_memory
try:
theano.config.profile = True
theano.config.profile_memory = True
a, b = T.scalars('a', 'b')
x, y = T.scalars('x', 'y')
z = ifelse(T.lt(a, b), x * 2, y * 2)
p = theano.ProfileStats(False)
if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]:
m = "FAST_RUN"
else:
m = None
f_ifelse = theano.function([a, b, x, y], z, profile=p, name="test_ifelse",
mode=m)
val1 = 0.
val2 = 1.
big_mat1 = 10
big_mat2 = 11
out = f_ifelse(val1, val2, big_mat1, big_mat2)
finally:
theano.config.profile = config1
theano.config.profile_memory = config2
开发者ID:Abioy,项目名称:Theano,代码行数:33,代码来源:test_profiling.py
示例2: test_pickle
def test_pickle(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars('xs')
f = function([x, In(a, value=1.0, name='a'), In(s, value=0.0, update=s+a*x, mutable=True)], s+a*x)
try:
# Note that here we also test protocol 0 on purpose, since it
# should work (even though one should not use it).
g = pickle.loads(pickle.dumps(f, protocol=0))
g = pickle.loads(pickle.dumps(f, protocol=-1))
except NotImplementedError as e:
if e[0].startswith('DebugMode is not picklable'):
return
else:
raise
# if they both return, assume that they return equivalent things.
# print [(k,id(k)) for k in f.finder.keys()]
# print [(k,id(k)) for k in g.finder.keys()]
self.assertFalse(g.container[0].storage is f.container[0].storage)
self.assertFalse(g.container[1].storage is f.container[1].storage)
self.assertFalse(g.container[2].storage is f.container[2].storage)
self.assertFalse(x in g.container)
self.assertFalse(x in g.value)
self.assertFalse(g.value[1] is f.value[1]) # should not have been copied
self.assertFalse(g.value[2] is f.value[2]) # should have been copied because it is mutable.
self.assertFalse((g.value[2] != f.value[2]).any()) # its contents should be identical
self.assertTrue(f(2, 1) == g(2)) # they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) # they should be in sync, default value should be copied.
f(1, 2) # put them out of sync
self.assertFalse(f(1, 2) == g(1, 2)) # they should not be equal anymore.
开发者ID:ChienliMa,项目名称:Theano,代码行数:34,代码来源:test_function_module.py
示例3: test_multiple_functions
def test_multiple_functions(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars('xs')
v = T.vector('v')
# put in some inputs
list_of_things = [s, x, v]
# some derived thing, whose inputs aren't all in the list
list_of_things.append(a * x + s )
f1 = function([x, In(a, value=1.0, name='a'), In(s, value=0.0, update=s+a*x, mutable=True)], s+a*x)
list_of_things.append(f1)
# now put in a function sharing container with the previous one
f2 = function([x, In(a, value=1.0, name='a'), In(s, value=f1.container[s], update=s+a*x, mutable=True)], s+a*x)
list_of_things.append(f2)
assert isinstance(f2.container[s].storage, list)
assert f2.container[s].storage is f1.container[s].storage
# now put in a function with non-scalar
v_value = numpy.asarray([2, 3, 4.], dtype=config.floatX)
f3 = function([x, In(v, value=v_value)], x+v)
list_of_things.append(f3)
# try to pickle the entire things
try:
saved_format = cPickle.dumps(list_of_things, protocol=-1)
new_list_of_things = cPickle.loads(saved_format)
except NotImplementedError, e:
if e[0].startswith('DebugMode is not picklable'):
return
else:
raise
开发者ID:LEEKYOUNGHUN,项目名称:Theano,代码行数:35,代码来源:test_function_module.py
示例4: __init__
def __init__(self):
x, y, z = T.scalars('xyz')
e = T.nnet.sigmoid((x + y + z)**2)
op = th.OpFromGraph([x, y, z], [e])
e2 = op(x, y, z) + op(z, y, x)
self.inputs = [x, y, z]
self.outputs = [e2]
开发者ID:12190143,项目名称:Theano,代码行数:8,代码来源:models.py
示例5: test_callback_with_ifelse
def test_callback_with_ifelse(self):
a, b, c = tensor.scalars("abc")
f = function(
[a, b, c], ifelse(a, 2 * b, 2 * c), mode=Mode(optimizer=None, linker=vm.VM_Linker(callback=self.callback))
)
f(1, 2, 3)
assert self.n_callbacks["IfElse"] == 2
开发者ID:benmoran,项目名称:Theano,代码行数:8,代码来源:test_vm.py
示例6: test_callback
def test_callback(self):
a, b, c = tensor.scalars("abc")
f = function([a, b, c], (a + b) + c, mode=Mode(optimizer=None, linker=vm.VM_Linker(callback=self.callback)))
f(1, 2, 3)
assert sum(self.n_callbacks.values()) == len(f.maker.fgraph.toposort())
f(1, 2, 3)
assert sum(self.n_callbacks.values()) == len(f.maker.fgraph.toposort()) * 2
开发者ID:benmoran,项目名称:Theano,代码行数:8,代码来源:test_vm.py
示例7: test_naming_rule1
def test_naming_rule1(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars('xs')
f = function([a, s], a/s)
self.assertTrue(f(1, 2) == 0.5)
self.assertTrue(f(2, 1) == 2.0)
self.assertTrue(f(2, s=1) == 2.0)
checkfor(self, lambda: f(q=2, s=1), TypeError) # got unexpected keyword argument 'q'
checkfor(self, lambda: f(a=2, s=1), TypeError) # got unexpected keyword argument 'a'
开发者ID:ChienliMa,项目名称:Theano,代码行数:9,代码来源:test_function_module.py
示例8: test_weird_names
def test_weird_names(self):
a, x, s = T.scalars('xxx')
checkfor(self, lambda: function([In(a, name=[])], []), TypeError)
def t():
f = function([In(a, name=set(['adsf', ()]), value=1.0),
In(x, name=(), value=2.0),
In(s, name=T.scalar(), value=3.0)], a+x+s)
checkfor(self, t, TypeError)
开发者ID:ChienliMa,项目名称:Theano,代码行数:10,代码来源:test_function_module.py
示例9: test_naming_rule0
def test_naming_rule0(self):
x, s = T.scalars('xs')
f = function([x, s], x/s)
self.assertTrue(f(1, 2) == 0.5)
self.assertTrue(f(2, 1) == 2.0)
self.assertTrue(f(s=2, x=1) == 0.5)
self.assertTrue(f(x=2, s=1) == 2.0)
self.assertTrue(f(2, s=1) == 2.0)
checkfor(self, lambda : f(2, x=2.0), TypeError) # got multiple values for keyword argument 'x'
checkfor(self, lambda : f(x=1), TypeError) # takes exactly 2 non-keyword arguments (1 given)
checkfor(self, lambda : f(s=1), TypeError) # takes exactly 2 non-keyword arguments (0 given)
开发者ID:ChienliMa,项目名称:Theano,代码行数:11,代码来源:test_function_module.py
示例10: test_naming_rule2
def test_naming_rule2(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x,s = T.scalars('xs')
#x's name is ignored because it is followed by anonymous parameter a.
f = function([x, a, s], a/s)
self.assertTrue(f(9,1,2) == 0.5)
self.assertTrue(f(9,2,1) == 2.0)
self.assertTrue(f(9,2, s=1) == 2.0)
checkfor(self, lambda:f(x=9,a=2,s=1), TypeError) #got unexpected keyword argument 'x'
checkfor(self, lambda:f(5.0,x=9), TypeError) #got unexpected keyword argument 'x'
开发者ID:HaniAlmousli,项目名称:Theano,代码行数:11,代码来源:test_function_module.py
示例11: test_naming_rule3
def test_naming_rule3(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars('xs')
# x's name is not ignored (as in test_naming_rule2) because a has a default value.
f = function([x, In(a, value=1.0), s], a/s+x)
self.assertTrue(f(9, 2, 4) == 9.5) # can specify all args in order
self.assertTrue(f(9, 2, s=4) == 9.5) # can give s as kwarg
self.assertTrue(f(9, s=4) == 9.25) # can give s as kwarg, get default a
self.assertTrue(f(x=9, s=4) == 9.25) # can give s as kwarg, omit a, x as kw
checkfor(self, lambda: f(x=9, a=2, s=4), TypeError) # got unexpected keyword argument 'a'
checkfor(self, lambda: f(), TypeError) # takes exactly 3 non-keyword arguments (0 given)
checkfor(self, lambda: f(x=9), TypeError) # takes exactly 3 non-keyword arguments (1 given)
开发者ID:ChienliMa,项目名称:Theano,代码行数:13,代码来源:test_function_module.py
示例12: test_deepcopy
def test_deepcopy(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x,s = T.scalars('xs')
f = function([x, In(a, value=1.0,name='a'), In(s, value=0.0, update=s+a*x, mutable=True)], s+a*x)
try:
g = copy.deepcopy(f)
except NotImplementedError, e:
if e[0].startswith('DebugMode is not picklable'):
return
else:
raise
开发者ID:aelaguiz,项目名称:Theano,代码行数:13,代码来源:test_function_module.py
示例13: test_shared_state0
def test_shared_state0(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars('xs')
f = function([x, In(a, value=1.0, name='a'), In(s, value=0.0, update=s+a*x, mutable=True)], s+a*x)
g = function([x, In(a, value=1.0, name='a'), In(s, value=f.container[s], update=s-a*x, mutable=True)], s+a*x)
f(1, 2)
self.assertTrue(f[s] == 2)
self.assertTrue(g[s] == 2)
g(1, 2)
self.assertTrue(f[s] == 0)
self.assertTrue(g[s] == 0)
开发者ID:ChienliMa,项目名称:Theano,代码行数:13,代码来源:test_function_module.py
示例14: __init__
def __init__(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars('xs')
v = T.vector('v')
self.s = s
self.x = x
self.v = v
self.e = a * x + s
self.f1 = function([x, In(a, value=1.0, name='a'), In(s, value=0.0, update=s+a*x, mutable=True)], s+a*x)
self.f2 = function([x, In(a, value=1.0, name='a'), In(s, value=self.f1.container[s], update=s+a*x, mutable=True)], s+a*x)
开发者ID:ChienliMa,项目名称:Theano,代码行数:14,代码来源:test_function_module.py
示例15: test_naming_rule4
def test_naming_rule4(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars('xs')
f = function([x, In(a, value=1.0, name='a'), s], a/s+x)
self.assertTrue(f(9, 2, 4) == 9.5) # can specify all args in order
self.assertTrue(f(9, 2, s=4) == 9.5) # can give s as kwarg
self.assertTrue(f(9, s=4) == 9.25) # can give s as kwarg, get default a
self.assertTrue(f(9, a=2, s=4) == 9.5) # can give s as kwarg, a as kwarg
self.assertTrue(f(x=9, a=2, s=4) == 9.5) # can give all kwargs
self.assertTrue(f(x=9, s=4) == 9.25) # can give all kwargs
checkfor(self, lambda: f(), TypeError) # takes exactly 3 non-keyword arguments (0 given)
checkfor(self, lambda: f(5.0, x=9), TypeError) # got multiple values for keyword argument 'x'
开发者ID:ChienliMa,项目名称:Theano,代码行数:14,代码来源:test_function_module.py
示例16: test_pickle
def test_pickle(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
x,s = T.scalars('xs')
f = function([x, In(a, value=1.0,name='a'), In(s, value=0.0, update=s+a*x, mutable=True)], s+a*x)
try:
# Note that here we also test protocol 0 on purpose, since it
# should work (even though one should not use it).
g = cPickle.loads(cPickle.dumps(f, protocol=0))
g = cPickle.loads(cPickle.dumps(f, protocol=-1))
except NotImplementedError, e:
if e[0].startswith('DebugMode is not picklable'):
return
else:
raise
开发者ID:aelaguiz,项目名称:Theano,代码行数:16,代码来源:test_function_module.py
示例17: test_c_thunks
def test_c_thunks():
a = tensor.scalars('a')
b, c = tensor.vectors('bc')
cases = [False]
if theano.config.cxx:
cases.append(True)
for c_thunks in cases:
f = function([a, b, c], ifelse(a, a * b, b * c),
mode=Mode(
optimizer=None,
linker=vm.VM_Linker(c_thunks=c_thunks,
use_cloop=False)))
f(1, [2], [3, 2])
from nose.tools import assert_raises
assert_raises(ValueError, f, 0, [2], [3, 4])
assert any([hasattr(t, 'cthunk') for t in f.fn.thunks]) == c_thunks
开发者ID:bouthilx,项目名称:Theano,代码行数:16,代码来源:test_vm.py
示例18: _policy_function
def _policy_function(self):
epoch, gm, powr, step = T.scalars('epoch', 'gm', 'powr', 'step')
if self.lr_policy == 'inv':
decay = T.power(1.0+gm*epoch, -powr)
elif self.lr_policy == 'exp':
decay = gm ** epoch
elif self.lr_policy == 'step':
decay = T.switch(T.eq(T.mod_check(epoch, step), 0.0),
T.power(gm, T.floor_div(epoch, step)),
1.0)
elif self.lr_policy == 'fixed':
decay = T.constant(1.0, name='fixed', dtype=theano.config.floatX)
return theano.function([gm, epoch, powr, step],
decay,
allow_input_downcast=True,
on_unused_input='ignore')
开发者ID:hmendozap,项目名称:master-arbeit-projects,代码行数:17,代码来源:LogisticRegression.py
示例19: test_shared_state_not_implicit
def test_shared_state_not_implicit(self):
# This test is taken from the documentation in
# doc/topics/function.txt. If it does not pass anymore and yet the
# behavior is still intended the doc and the test should both be
# updated accordingly.
x, s = T.scalars('xs')
inc = function([x, In(s, update=(s+x), value=10.0)], [])
dec = function([x, In(s, update=(s-x), value=inc.container[s],
implicit=False)], [])
self.assertTrue(dec[s] is inc[s])
inc[s] = 2
self.assertTrue(dec[s] == 2)
dec(1)
self.assertTrue(inc[s] == 1)
dec(1, 0)
self.assertTrue(inc[s] == -1)
self.assertTrue(dec[s] == -1)
开发者ID:ChienliMa,项目名称:Theano,代码行数:17,代码来源:test_function_module.py
示例20: policy_update
def policy_update(self, lr_policy):
epoch, gm, powr, step = T.scalars('epoch', 'gm', 'powr', 'step')
if lr_policy == 'inv':
decay = T.power(1+gm*epoch, -powr)
elif lr_policy == 'exp':
decay = gm ** epoch
elif lr_policy == 'step':
decay = T.switch(T.eq(T.mod_check(epoch, step), 0),
T.power(gm, T.floor_div(epoch, step)),
1.0)
elif lr_policy == 'fixed':
decay = T.constant(1.0, name='fixed', dtype='float32')
return theano.function([gm, epoch, powr, step],
decay,
updates=[(self.shared_lr,
self.shared_lr * decay)],
on_unused_input='ignore')
开发者ID:hmendozap,项目名称:master-arbeit-projects,代码行数:18,代码来源:test_policies_updates.py
注:本文中的theano.tensor.scalars函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论