Theano(4):Theano更多示例,默认参数值、多输出function;随机数;梯度、Jacobian雅克比矩阵、Hessian嗨森矩阵;

http://deeplearning.net/software/theano/tutorial/examples.html


这里讲构建机器学习算法最常用的几个东西:sigmoid函数;多输出、有默认参数值的函数;随机数;梯度。

下一篇对logistic regression进行建模。


先回顾一下之前的,定义sigmoid函数:

>>> import theano
>>> import theano.tensor as T
>>> x = T.dmatrix('x')
>>> s = 1 / (1 + T.exp(-x))
>>> logistic = theano.function([x], s)
>>> logistic([[0, 1], [-1, -2]])
array([[ 0.5       ,  0.73105858],
       [ 0.26894142,  0.11920292]])


定义 参数包含默认值、同时有多个输出 的function:

>>> import theano
>>> import theano.tensor as T
>>> x=T.scalar('x')
>>> y=T.scalar('y')
>>> z=x+y
>>> k=x-y
>>> fun=theano.function([x, theano.In(y, value=1)], [z, k])
>>> fun(5)
[array(6.0), array(4.0)]
>>> fun(5, 6)
[array(11.0), array(-1.0)]
>>> fun(5, y=6)
[array(11.0), array(-1.0)]
这里使用了theano.In这个类来实现默认参数;

Inputs with default values must follow inputs without default values (like Python’s functions). 

使用fun(5, y=6)能够更明确赋值(如果有多个默认参数的话)。



定义“共享变量”:

add = function([x], y, updates=[(y, y+x)])

TypeError: ('update target must be a SharedVariable', y)

>>> from theano import shared
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值