theano —— shared, function(outputs, updates, givens)
来源:互联网 发布:京东秒杀的软件 编辑:程序博客网 时间:2024/04/29 19:21
- theano 下的 functions (from theano import function)的两个重要性质:
- 多个 outputs;
- 多个 updates;
1. shared
- shared 与 theano.tensor.matrix()/vector() 的区别在于,tensor.matrix/vector 符号变量不需要初始化,而 shared 变量则需要初始化赋值;
>>> import theano >>> import theano.tensor as T >>> state = theano.shared(0) >>> type(state)theano.tensor.sharedvar.ScalarSharedVariable>>> state.get_value(borrow=True)array(0) # shared 型变量,通过 get_value 取出其值;>>> x = T.iscalar('x')>>> type(x)theano.tensor.var.TensorVariable # tensor value(thenao.tensor模块下的变量?)是没有get_value成员函数的>>> type(x+state)theano.tensor.var.TensorVariable
2. updates
>>> counter = function([x], state, updates=[(state, state+x)])>>> counter(5)>>> state.get_value(borrow=True)5>>> counter(6)>>> state.get_value(borrow=True)11
不使用可选参数updates:
>>> state += x # 此时state的类型已自动转换为tensor value,不再具有get_value的成员>>> counter = theano.function([x], state)>>> counter(5)array(5)>>> state.get_value()AttributeError: 'TensorVariable' object has no attribute 'get_value'
theano.function 的 updates, 二元 tuple 构成的 list,
[(a, a+1), (b, b+1)]
其含义其实为,a = a+1, b = b+1;
所以常见与,梯度下降算法中的权值的更新,如下:
updates = [(W, W-eta*delta_W), (b, b-eta*delta_b)]
3. givens
test_model = theano.function( inputs=[idx], outputs=layer3.error(y), givens={ x: test_set_x[idx*batch_size:(idx+1)*batch_size], y: test_set_y[idx*batch_size:(idx+1)*batch_size] })valid_model = theano.function( inputs=[idx], outputs=layer3.error(y), givens={ x: valid_set_x[idx*batch_size:(idx+1)*batch_size], y: valid_set_y[idx*batch_size:(idx+1)*batch_size] })
0 0
- theano —— shared, function(outputs, updates, givens)
- theano.function中input和givens
- Theano——shared
- theano库中function函数output和updates执行的先后顺序
- theano-function
- Theano学习四----Theano shared
- Theano学习三----Theano function
- Theano 学习numpy.asarray(), theano.shared()
- python theano中的shared variable
- python theano中的shared variable
- theano.function、theano.scan 参数数据类型问题
- theano学习--theano.function
- theano学习--theano.shared共享变量
- 【theano-windows】学习笔记一——theano中的变量
- 【theano-windows】学习笔记三——theano中的导数
- toad安装错误—Failed to Download products and updates
- toad安装错误—Failed to Download products and updates
- toad安装错误—Failed to Download products and updates
- AngularJS去掉的URL里的#号
- 最近让交的实验内容:实验一
- Oracle查询前10条数据
- 快捷安装/卸载/重启Windows Service服务
- 回显
- theano —— shared, function(outputs, updates, givens)
- VS2012最常用的快捷键
- kali攻防第9章 Metasploit之我的远程控制软件
- Java基础_02_Java编程基础
- 大型网站系统架构演化之路
- IOS界面生命周期
- Mysql 多行插入数据
- 看看initramfs加载的完整流程
- Xcode中常用的快捷键操作