免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

Theano筆記-創新互聯

scan函數Theano筆記

theano.scan(fnsequences=Noneoutputs_info=None,non_sequences=Nonen_steps=Nonetruncate_gradient=-1,go_backwards=Falsemode=Nonename=Noneprofile=False)

創新互聯是一家專注于成都網站設計、網站建設與策劃設計,鐘山網站建設哪家好?創新互聯做網站,專注于網站建設10年,網設計領域的專業建站公司;建站業務涵蓋:鐘山等地區。鐘山做網站價格咨詢:028-86922220

 outputs_info is the list of Theano variables or dictionaries describing the initial state of the outputs computed recurrently.

fn是每一步所用的函數,sequences是輸入,outputs_info是scan輸出在起始的狀態。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的規則。當sequences=None時,n_steps應有一個值來限制對后面theano function里的input的循環次數。當sequences不為空時,theano function直接對sequences循環:

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里到序列值。這里根據順序,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筆記-創新互聯
分享鏈接:http://m.newbst.com/article34/jgpse.html

成都網站建設公司_創新互聯,為您提供電子商務網站導航軟件開發定制開發用戶體驗微信公眾號

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

網站托管運營