成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Theano筆記-創(chuàng)新互聯(lián)

scan函數(shù)Theano筆記

theano.scan(fnsequences=Noneoutputs_info=None,non_sequences=Nonen_steps=Nonetruncate_gradient=-1,go_backwards=Falsemode=Nonename=Noneprofile=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-86922220

 outputs_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:

  1. Sequence1[t-3]
  2. Sequence1[t+2]
  3. Sequence1[t-1]
  4. Sequence2[t]
  5. Sequence3[t+3]
  6. Output1[t-3]
  7. Output1[t-5]
  8. Output3[t-1]
  9. Argument1
  10. Argument2

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'
  • off: Default behavior. This debugging mechanism is inactive.
  • raise: Compute test values on the fly. Any variable for which a test value is required, but not provided by the user, is treated as an error. An exception is raised accordingly.
  • warn: Idem, but a warning is issued instead of an Exception.
  • ignore: Silently ignore the computation of intermediate test values, if a variable is missing a test value.
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)

網(wǎng)站托管運營
五家渠市| 广宗县| 内江市| 红安县| 海淀区| 嘉善县| 永春县| 界首市| 淳安县| 宁武县| 灌南县| 蒙城县| 大城县| 织金县| 瑞金市| 诏安县| 三原县| 青岛市| 金昌市| 璧山县| 珲春市| 清水县| 平果县| 巴里| 扎鲁特旗| 治多县| 兴国县| 武冈市| 通州区| 平定县| 汤原县| 宁陵县| 阳山县| 禄劝| 拜城县| 新民市| 新巴尔虎左旗| 裕民县| 芒康县| 隆回县| 海阳市|