Theano Getting Started CNN (i)

Source: Internet
Author: User
Tags scalar theano

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.