Theano

来源:互联网 发布:土方工程量计算软件 编辑:程序博客网 时间:2024/05/11 01:51

基础

Theano.Tensor

>>> 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]])>>> x=T.dscalar("xname")>>> type(x)<class 'theano.tensor.var.TensorVariable'>>>> x.type#x是变量,x变量的类型是(float64, scalar)TensorType(float64, scalar)

共享变量

在不同的函数调用之间共享

>>> from theano import shared>>> state=shared(0)>>> inc = T.iscalar('inc')>>> accumulator = function([inc], state, updates=[(state, state+inc)])#update的格式为(shared-variable, new expression)或directory>>> accumulator(1)array(0)#返回原来的state值>>> state.get_value()1>>> accumulator(8)array(1)>>> state.get_value()9>>> state.set_value(1)>>> state.get_value()1

参考

1.图结构
http://www.deeplearning.net/software/theano/extending/graphstructures.html#graphstructures
2.

0 0
原创粉丝点击