<code id="ymukc"><xmp id="ymukc">

Python的theano庫符號求導示例代碼

CarinAcosta的頭像 CarinAcosta 0 2016-03-02 19:36 0

 基本信息

× 1   

瀏覽數: 22924

分享時間: 2 年 前

#coding=utf-8
""" Symbolic computation of python theano

@Author: zhang zewang
@Date: 2016-3-2
"""
import sys
sys.path.append('../utils/')
import theano
import theano.tensor as T
import numpy as np
from functionUtils import shared_normal,shared_zeros
w = 1.5
def step(input):
    return w*input
input = T.dscalar('input')
output = step(input)
f = theano.function([input],[output])
gf = T.grad(output,input)
gf = theano.function([input],[gf])
i = 4
print f(4)
print gf(4)



#coding=utf-8
""" Symbolic computation of python theano

@Author: zhang zewang
@Date: 2016-3-2
"""
import sys
sys.path.append('../utils/')
import theano
import theano.tensor as T
import numpy as np
from functionUtils import shared_normal,shared_zeros
w = [[1.5,2],[3,4]]
w = np.array(w)
input = T.dmatrix('input')
output = w*(input)
f = theano.function([input],[output])
gf = T.grad(output.sum(),input)
gf = theano.function([input],[gf])
i = [[1,2],[5,6]]
print f(i)
print gf(i)




還沒有人評論,趕快來搶沙發吧!

  
六合特码资料
<code id="ymukc"><xmp id="ymukc">
<code id="ymukc"><xmp id="ymukc">