定義函式
import theano.tensor as tshared變數,一種用於公式中作為可被替換的部分,或迭代變數。from theano import function,pp
//標量
x=t.dscalar(『x』)
//向量
x=t.vector(「a」)
//矩陣
x=t.dmatrix(『x』)
y=t.dscalar(『y』)
z=x+y
f=function([x,y],z)
//函式f表示式
print(pp(z))
print(f(2.0,3.0))
//定義乙個shared變數,並賦予初始值shared,一般初始值為0或隨機值updates中每個括號中的pair(value,newvalue),在每次運算時更新迭代變數。b=theano.shared(value,name=』b』)
train=theano.function(inputs=[x,y],outputs=[prediction,error],updates=[(b,b+inc),(..)],givens=[(w,foo),(..)])
givens中每個括號中的pair(symbol,replace),運算時用replace替換公式中的symbol。
導數
y=x**2將資料放入矩陣(向量)中,提高計算導數的資料量的第1個引數必須是標量
gy=t.grad(y,x)
x=t.dmatrix(『x』)numpy.random隨機抽樣y=t.sum(1/(1+t.exp(-x)))
gy=t.grad(y,x)
func=function([x],gy)
import numpynumpy.random.randn()返回的樣本具有標準正態分佈。//產生乙個隨機值
numpy.random.rand()
//乙個隨機向量
numpy.random.rand(number)
//乙個隨機矩陣
numpy.random.rand(n,features)
a*numpy.random.randn(n,features)+b常用分布
import numpy.random as rtheano中的運算r.beta(a,b,size=(n,features)) //貝塔分布
r.binomial(n,p,size) //二項分布
r.dirichlet(alpha,size) //狄利克雷分布
r.exponential(scale,size) //指數分布
r.gamma(shape,scale,size) //伽馬分布
import theano.tensor as t//計算內積,對於兩個矩陣相當於矩陣相乘,對於兩個向量計算內積。
t.dot(x,y)
//計算元素內部資料的平均值
t.mean()
//計算元素內部資料的和
t.sum()
7 theano 安裝 學習theano的筆記
之前寫過有關theano在macos上的安裝部署,昨天又在windows上安裝了一版,發現還有theano.test 這種玩法,不知道有多少人的機器是全部通過的,6000多個測試程式,不發生問題的概率估計是不大。我自己的機器上現在還有7個failure,不打算找問題了,先用著再說。天天搞深度學習的,...
theano學習筆記 1 代數
theano教程 usr bin env python coding utf 8 from theano import function import theano.tensor as t 第1步 定義兩個變數及其型別 x t.dscalar x 雙精度浮點型的0 維陣列 也就是標量 y t.dsc...
Theano學習筆記(二) 邏輯回歸函式解析
有了前面的準備,可以用theano實現乙個邏輯回歸程式,邏輯回歸是典型的有監督學習。為了形象,這裡我們假設分類任務是區分人與狗的 首先是生成隨機數物件 importnumpy importtheano importtheano.tensor as t rng numpy.random 資料初始化 有...