blog_20160805_1_1189617 18行 Python
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
import theano
import theano.tensor as T
from theano import function

# 假设神经元有两个输入,加上bias结点(其值始终为1)
# 所以我们需要一个三列的向量
x = T.dvector("x")
# 设置权值变量,第一列为神经元的bias
w = T.dvector("w")
# 求神经元的总输入
s = T.dot(x, w)
# 定义函数
sum = function([x, w], s)

x = [1.0, 1.5, 2.5]
w = [0.0, 0.2, 0.4]

print(sum(x, w))
blog_20160805_2_1647748 10行 Python
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
import theano
import theano.tensor as T
from theano import function

x = T.dscalar("x")
s = 1 / (1 + T.exp(-x))
logistic = function([x], s)

x = 10.0
print("logistic=%f" % logistic(x))
blog_20160805_3_9281196 16行 Python
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
import theano
import theano.tensor as T
from theano import function

d = T.dvector("d")
y = T.dvector("y")
diff = (d - y ) ** 2
f = function([d, y], diff)
r = T.dvector("r")
vectorSum = T.sum(r)
vectorSumF = function([r], vectorSum)


d = [1.0, 2.0, 3.0, 4.0, 5.0]
y = [1.1, 2.1, 3.5, 4.2, 5.3]
print(vectorSumF(f(d, y)))