码迷,mamicode.com
首页 > 其他好文 > 详细

莫烦theano学习自修第二天【激励函数】

时间:2018-08-20 00:31:13      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:python   gis   log   cti   函数   project   style   imp   多个   

1. 代码如下:

#!/usr/bin/env python
#! _*_ coding:UTF-8 _*_

import numpy as np
import theano.tensor as T
import theano

x = T.dmatrix(x)
# 定义一个激励函数
s = 1 / (1 + T.exp(-x))
logistic = theano.function([x], s)
print logistic([[0, 1], [-2, -3]])


# 一个函数输出多个变量的结果
a, b = T.dmatrices(a, b)
diff = a - b
abs_diff = abs(diff)
diff_squared = diff ** 2
f = theano.function([a, b], [diff, abs_diff, diff_squared])
print f(np.ones((2, 2)),
        np.arange(4).reshape((2, 2))
    )
# 也可以写为
x1, x2, x3 = f(np.ones((2, 2)),
        np.arange(4).reshape((2, 2))
    )
print x1, x2, x3


# 变量的名称及默认值
x, y, w = T.dscalars(x, y, w)
z = (x + y) * w
f = theano.function([
    x,
    theano.In(y, value=1),
    theano.In(w, value=2, name=weights)
], z)
print f(23, )

结果:

/Users/liudaoqiang/PycharmProjects/numpy/venv/bin/python /Users/liudaoqiang/Project/python_project/theano_day2/theano_test.py
[[ 0.5         0.73105858]
 [ 0.11920292  0.04742587]]
[array([[ 1.,  0.],
       [-1., -2.]]), array([[ 1.,  0.],
       [ 1.,  2.]]), array([[ 1.,  0.],
       [ 1.,  4.]])]
[[ 1.  0.]
 [-1. -2.]] [[ 1.  0.]
 [ 1.  2.]] [[ 1.  0.]
 [ 1.  4.]]
48.0

Process finished with exit code 0

 

莫烦theano学习自修第二天【激励函数】

标签:python   gis   log   cti   函数   project   style   imp   多个   

原文地址:https://www.cnblogs.com/liuzhiqaingxyz/p/9503291.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!