Theano is a python library dedicated to defining, optimizing, and evaluating mathematical expressions that are efficient and suitable for multi-dimensional arrays. Especially suitable for machine learning. In general, you need to install Python and numpy when you use it.
First look at what machine learning, define a model (function) f (x;w) x is input, W is the model parameter, then define a loss function C (f), by data driven in a bunch of model functions to select the best function is the process of training training, In machine learning training, gradient descent method is generally used to gradient descent.
The use of Theano to build a machine learning (deep learning) framework has the following advantages:
1, Theano can automatically calculate the gradient
2. It takes only two steps to build a framework, define functions and calculate gradients.
First, define the function
Step 0 declares the use of Theano import Theano
Step 1 Define the input x=theano.tensor.scalar ()
Step 2 Define the output y=2*x
Step 3 Define fuction f = theano.function ([x],y)
Step 4 Call function print f (-2)
Step 1 Define the input variables
A = Theano.tensor.scalar ()
b =theano.tensor.matrix ()
Simplified import theano.tensor as T
Step 2 Define the relationship of the output variable to the input variable
X1=t.matrix ()
X2=t.matrix ()
Y1=x1*x2
Y2=t.dot (X1,X2) #矩阵乘法
Step 3 declaring the function
F= theano.function ([x],y)
The function input must be a list band []
Example
1 ImportTheano2 ImportTheano.tensor as T3 4A=T.matrix ()5b=T.matrix ()6c = A *b7D =T.dot (A, b)8f1=theano.function ([a,b],c)9F2= theano.function ([a,b],d)
a=[[1,2],[3,4]]Tenb=[[2,4],[6,8]] #2 * * Matrix Onec=[[1,2],[3,4],[5,6]] #3 * * Matrix A PrintF1 (A, b) - PrintF2 (C,B)
Second, calculate the gradient
Calculate DY/DX G=t.grad (y,x)
Theano Getting Started CNN (i)