theano.scan(fn, sequences=None, outputs_info=None,non_sequences=None, n_steps=None, truncate_gradient=-1,go_backwards=False, mode=None, name=None, profile=False)
創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)與策劃設(shè)計,鐘山網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務涵蓋:鐘山等地區(qū)。鐘山做網(wǎng)站價格咨詢:028-86922220outputs_info is the list of Theano variables or dictionaries describing the initial state of the outputs computed recurrently.
fn是每一步所用的函數(shù),sequences是輸入,outputs_info是scan輸出在起始的狀態(tài)。sequences and outputs_info are all parameters of fn in ordered sequence.
scan(fn, sequences = [ dict(input= Sequence1, taps = [-3,2,-1]) , Sequence2 , dict(input =Sequence3, taps = 3) ] , outputs_info = [ dict(initial =Output1, taps = [-3,-5]) , dict(initial = Output2, taps = None) , Output3 ] , non_sequences = [ Argument1, Argument2])
fn should expect the following arguments in this given order:
import theano
import theano.tensor as T
mode = theano.Mode(linker='cvm')
import numpy as np
def fun(a,b):
return a+b
input=T.vector("input")
output,update=theano.scan(fun,sequences=input,outputs_info=[T.as_tensor_variable(np.asarray(1,input.dtype))])
out=theano.function(inputs=[input],outputs=output)
in1=numpy.array([1,2,3])
print out(in1)
def fun(a,b):
return a+b
input=T.matrix("input")
output,update=theano.scan(fun,sequences=input,outputs_info=[T.as_tensor_variable(np.asarray([0,0,0],input.dtype))])
out=theano.function(inputs=[input,],outputs=output)
in1=numpy.array([[1,2,3],[4,5,6]])
print(in1)
print out(in1)
shared variables相當于全局變量,The value can be accessed and modified by the.get_value() and .set_value() methods. 在function里用updata來修改可以并行。
scan的輸出是一個symbol,用來在后面的theano function里作為output和update的規(guī)則。當sequences=None時,n_steps應有一個值來限制對后面theano function里的input的循環(huán)次數(shù)。當sequences不為空時,theano function直接對sequences循環(huán):
components, updates = theano.scan(fn=lambda coefficient, power, free_variable: coefficient * (free_variable ** power), outputs_info=None, sequences=[coefficients, theano.tensor.arange(max_coefficients_supported)], non_sequences=x)
這個例子中,
theano.tensor.arange(max_coefficients_supported)類似于enumerate的index,coefficientes相當與enumerate里到序列值。這里根據(jù)順序,x為free_variable.
Debug:
http://deeplearning.net/software/theano/tutorial/debug_faq.html
theano.config.compute_test_value = 'warn'
import theanodef inspect_inputs(i, node, fn): print i, node, "input(s) value(s):", [input[0] for input in fn.inputs],def inspect_outputs(i, node, fn): print "output(s) value(s):", [output[0] for output in fn.outputs]x = theano.tensor.dscalar('x')f = theano.function([x], [5 * x], mode=theano.compile.MonitorMode( pre_func=inspect_inputs, post_func=inspect_outputs))f(3)
mode = 'DEBUG_MODE' 很慢,無效?
使用print
x = theano.tensor.dvector('x')x_printed = theano.printing.Print('this is a very important value')(x)f = theano.function([x], x * 5)f_with_print = theano.function([x], x_printed * 5)#this runs the graph without any printingassert numpy.all( f([1, 2, 3]) == [5, 10, 15])#this runs the graph with the message, and value printedassert numpy.all( f_with_print([1, 2, 3]) == [5, 10, 15])
分享標題:Theano筆記-創(chuàng)新互聯(lián)
分享鏈接:http://jinyejixie.com/article34/jgpse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務、網(wǎng)站導航、軟件開發(fā)、定制開發(fā)、用戶體驗、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容