History & Origin of Theano
Theano’s husband, Pythagoras (c. 582500 B.C.), was inspired one of the most influential sects in the ancient world. Best known for devising the Pythagorean Theoremâ€”which states that the sum of the squares of the sides of a right triangle is equal to the square of the hypotenuseâ€”Pythagoras was considered the greatest scientist of antiquity by classical Greek scholars and is considered to have been the first mathematician. However, given that Pythagoras lived seven generations before Plato, most of the information about him comes from fairly late sourcesâ€”a few as late as the third century A.D. Another problem is that some of these sources are of doubtful reliability. However, references to Pythagoras’s ideas can be found in earlier writings, including those of Empedocles, Heraclitus, Herodotus, Plato, and Aristotle.
What is Theano
TheanoÂ is a Python library that allows us to evaluate mathematical operations including multidimensional arrays so efficiently. It is mostly used in building Deep Learning Projects. It works a way more faster on Graphics Processing Unit (GPU) rather than on CPU. Theano attains high speeds that gives a tough competition to C implementations for problems involving large amounts of data. It can take advantage of GPUs which makes it perform better than C on a CPU by considerable orders of magnitude under some certain circumstances.
It knows how to take structures and convert them into very efficient code that uses numpy and some native libraries. It is mainly designed to handle the types of computation required for large neural network algorithms used in Deep Learning. That is why, it is a very popular library in the field of Deep Learning.
How to install Theano :
pip install theano
Several of the symbols we will need to use are in theÂ tensorÂ subpackage of Theano. We often import such packages with a handy name, letâ€™s say, T.
from theano import * import theano.tensor as T
Why Theano Python Library :
Theano is a sort of hybrid between numpy and sympy, an attempt is made to combine the two into one powerful library. Some advantages of theano are as follows:
 Stability Optimization:Â Theano can find out some unstable expressions and can use more stable means to evaluate them
 Execution Speed Optimization:Â As mentioned earlier, theano can make use of recent GPUs and execute parts of expressions in your CPU or GPU, making it much faster than Python
 Symbolic Differentiation:Â Theano is smart enough to automatically create symbolic graphs for computing gradients
Basics of Theano :
Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multidimensional arrays efficiently.Some Theano implementations are as follows.
Subtracting two scalars :
 Python
# Python program showing # subtraction of two scalars import theano from theano import tensor # Declaring variables a = tensor.dscalar() b = tensor.dscalar() # Subtracting res = a  b # Converting it to a callable object # so that it takes matrix as parameters func = theano.function([a, b], res) # Calling function assert 20.0 = = func( 30.5 , 10.5 ) 
It will not provide any output as the assertion of two numbers matches the number given, hence it results into a true value.
Adding two scalars :
 Python
# Python program showing # addition of two scalars # Addition of two scalars import numpy import theano.tensor as T from theano import function # Declaring two variables x = T.dscalar( 'x' ) y = T.dscalar( 'y' ) # Summing up the two numbers z = x + y # Converting it to a callable object # so that it takes matrix as parameters f = function([x, y], z) f( 5 , 7 ) 
Output:Â array(12.0)
How Theano works aka Theano architecture?
Theano itself is effectively dead, but the deep learning frameworks built on top of Theano, are still functioning. These include the more userfriendly frameworks Keras, Lasagne, and Blocks. These three provide highlevel frameworks for fast prototyping and model testing.
 Step 0: Import libraries. import numpy as np import theano.tensor as T from theano import function. …
 Step 1: Define variables. a = T.dscalar(‘a’) b = T.dscalar(‘b’) …
 Step 2: Define expression. c = a*b f = function([a,b],c) …
 Step 3: Evaluate Expression. f(1.5,3)
Use case ofÂ Theano
How to InstallÂ Theano
Theano provides extensive installation instructions for the major operating systems: Windows, OS X and Linux. Read theÂ Installing Theano guide for your platform.
Theano assumes a working Python 2 or Python 3 environment withÂ SciPy. There are ways to make the installation easier, such as usingÂ AnacondaÂ to quickly set up Python and SciPy on your machine as well as usingÂ Docker images.
With a working Python and SciPy environment, it is relatively straightforward to install Theano. from PyPI using pip, for example:
1

pip install Theano

At the time of writing the last official release of Theano was version 0.8 which was released 21th March 2016.
New releases may be announced and you will want to update to get any bug fixes and efficiency improvements. You can upgrade Theano using pip as follows:
1

sudo pip install –upgrade –nodeps theano

You may want to use the bleeding edge version of Theano checked directly out of Github.
This may be required for some wrapper libraries that make use of bleeding edge API changes. You can install Theano directly from a Github checkout as follows:
1

pip install –upgrade –nodeps git+git://github.com/Theano/Theano.git

You are now ready to run Theano on your CPU, which is just fine for the development of small models.
Large models may run slowly on the CPU. If you have a Nvidia GPU, you may want to look into configuring Theano to use your GPU. Read theÂ Using the GPU guides for LinuxÂ orÂ Mac OS X to set up Theano to use the GPUÂ and theÂ Using the GPU guideÂ for how to test whether it is working.
Simple Theano Example
In this section we demonstrate a simple Python script that gives you a flavor of Theano.
It is taken from theÂ Theano at a Glance guide.Â In this example we define two symbolic floating point variablesÂ aÂ andÂ b.
We define an expression that uses these variablesÂ (c = a + b).
We then compile this symbolic expression into a function using Theano that we can use later.
Finally, we use our complied expression by plugging in some real values and performing the calculation using efficient compiled Theano code under the covers.
1
2
3
4
5
6
7
8
9
10
11
12

import theano
from theano import tensor
# declare two symbolic floatingpoint scalars
a = tensor.dscalar()
b = tensor.dscalar()
# create a simple expression
c = a + b
# convert the expression into a callable object that takes (a,b)
# values as input and computes a value for c
f = theano.function([a,b], c)
# bind 1.5 to ‘a’, 2.5 to ‘b’, and evaluate ‘c’
assert 4.0 == f(1.5, 2.5)

Running the example does not provide any output. The assertion thatÂ 1.5 + 2.5 = 4.0Â is true.
This is a useful example as it gives you a flavor for how a symbolic expression can be defined, compiled and used. You can see how this may be scaled up to large vector and matrix operations required for deep learning.
Extensions and Wrappers for Theano
If you are new to deep learning you do not have to use Theano directly.
In fact, you are highly encouraged to use one of many popular Python projects that make Theano a lot easier to use for deep learning.
These projects provide data structures and behaviors in Python, specifically designed to quickly and reliably create deep learning models whilst ensuring that fast and efficient models are created and executed by Theano under the covers.
The amount of Theano syntax exposed by the libraries varies.
 For example theÂ Lasagne libraryÂ provides convenience classes for creating deep learning model but still expects you to know and make use of Theano syntax. This is good for beginners that know or are willing to learn a little Theano as well.
 Another example isÂ KerasÂ that hides Theano completely and provides a very simple API to work with to create Deep Learning models. It hides Theano so well, that it can in fact run as a wrapper for another popular foundation framework calledÂ TensorFlow.
Feature and Advantage of using Theano
ABSTRACT
Theano is a linear algebra compiler that optimizes a userâ€™s symbolicallyspecified mathematical computations to produce efficient lowlevel implementations. In this paper, we present new features and efficiency improvements to Theano, and benchmarks demonstrating Theanoâ€™s performance relative to Torch7, a recently introduced machine learning library, and to RNNLM, a C++ library targeted at recurrent neural networks.
Best Alternative of Theano
 scikitlearn.
 Keysight Eggplant Platform.
 machinelearning in Python.
 V7.
 Personalizer.
 Kubeflow.
 Google Cloud TPU.
 Torch.
Free Video Tutorials of Theano
Interview Questions and Answer for Theano
1.Â Theano is a _______ library.
View Answer
Explanation: Theano is a Python library that allows us to evaluate mathematical operations including multidimensional arrays so efficiently.
2.Â Theano works a way _______ on Graphics Processing Unit (GPU) rather than on CPU.
View Answer
Explanation: It works a way more faster on Graphics Processing Unit (GPU) rather than on CPU.
3.Â Which command used to install Theano?
View Answer
Explanation: pip install theano command used to install Theano
4.Â Which of the following are advantages of theano ?
View Answer
Explanation: All of the above are advantages of theano.
5.Â Which theano type has 16bit integers?
View Answer
Explanation: 16bit integers : wscalar, wvector, wmatrix, wrow, wcol, wtensor3, wtensor4, wtensor5, wtensor6, wtensor7
6.Â fmatrix theano type has data type?
View Answer
Explanation: float : fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4, ftensor5, ftensor6, ftensor7
7.Â Theano function acts like a hook for interacting with the symbolic graph.
View Answer
Explanation: True, Theano function acts like a hook for interacting with the symbolic graph.
8.Â A Theano function is declared using the following syntax?
Â Answer
Explanation: A Theano function is declared using the following syntax : theano.function ([x], y)
9.Â The _________ method declares a decimal scalar variable.
View Answer
Explanation: The dscalar method declares a decimal scalar variable.
10.Â Theano was written at the LISA lab with the intention of providing rapid development of efficient machine learning algorithms.
View Answer
Explanation: True, Theano was written at the LISA lab with the intention of providing rapid development of efficient machine learning algorithms.