![数学计算 theano](https://i-blog.csdnimg.cn/blog_migrate/b9f59497671514d72d5daf24d843b4ac.png)
数学计算 theano
Theano-计算图 (Theano - Computational Graph)
From the above two examples, you may have noticed that in Theano we create an expression which is eventually evaluated using the Theano function. Theano uses advanced optimization techniques to optimize the execution of an expression. To visualize the computation graph, Theano provides a printing package in its library.
从上面的两个示例中,您可能已经注意到,在Theano中,我们创建了一个最终使用Theano 函数求值的表达式。 Theano使用高级优化技术来优化表达式的执行。 为了可视化计算图,Theano在其库中提供了一个打印程序包。
标量加法的符号图 (Symbolic Graph for Scalar Addition)
To see the computation graph for our scalar addition program, use the printing library as follows −
要查看我们标量加法程序的计算图,请使用打印库,如下所示:
theano.printing.pydotprint(f, outfile="scalar_addition.png", var_with_name_simple=True)
When you execute this statement, a file called scalar_addition.png will be created on your machine. The saved computation graph is displayed here for your quick reference −
执行此语句时,将在您的计算机上创建一个名为scalar_addition.png的文件。 保存的计算图显示在此处,供您快速参考-
![Scalar Addition](https://i-blog.csdnimg.cn/blog_migrate/d2b8161b6de3a8b593acc5574d963c3b.png)
The complete program listing to generate the above image is given below −
下面给出了生成上述图像的完整程序清单-
from theano import *
a = tensor.dscalar()
b = tensor.dscalar()
c = a + b
f = theano.function([a,b], c)
theano.printing.pydotprint(f, outfile="scalar_addition.png", var_with_name_simple=True)
矩阵乘法器的符号图 (Symbolic Graph for Matrix Multiplier)
Now, try creating the computation graph for our matrix multiplier. The complete listing for generating this graph is given below −
现在,尝试为矩阵乘法器创建计算图。 下面给出了生成此图的完整列表-
from theano import *
a = tensor.dmatrix()
b = tensor.dmatrix()
c = tensor.dot(a,b)
f = theano.function([a,b], c)
theano.printing.pydotprint(f, outfile="matrix_dot_product.png", var_with_name_simple=True)
The generated graph is shown here −
生成的图如下所示-
![Matrix Multiplier](https://i-blog.csdnimg.cn/blog_migrate/223984c2c0e6ef685e0b08b3002bc239.png)
复杂图 (Complex Graphs)
In larger expressions, the computational graphs could be very complex. One such graph taken from Theano documentation is shown here −
在较大的表达式中,计算图可能非常复杂。 从Theano文档中获取的一个这样的图显示在这里-
![Complex Graphs](https://i-blog.csdnimg.cn/blog_migrate/058a4a1553d4b2b45130bc78d664d432.png)
To understand the working of Theano, it is important to first know the significance of these computational graphs. With this understanding, we shall know the importance of Theano.
要了解Theano的工作原理,首先了解这些计算图的重要性很重要。 有了这些了解,我们将了解Theano的重要性。
为什么选择Theano? (Why Theano?)
By looking at the complexity of the computational graphs, you will now be able to understand the purpose behind developing Theano. A typical compiler would provide local optimizations in the program as it never looks at the entire computation as a single unit.
通过查看计算图的复杂性,您现在将能够了解开发Theano的目的。 典型的编译器会在程序中提供局部优化,因为它永远不会将整个计算视为一个单元。
Theano implements very advanced optimization techniques to optimize the full computational graph. It combines the aspects of Algebra with aspects of an optimizing compiler. A part of the graph may be compiled into C-language code. For repeated calculations, the evaluation speed is critical and Theano meets this purpose by generating a very efficient code.
Theano实现了非常先进的优化技术来优化整个计算图。 它结合了代数方面和优化编译器方面。 图的一部分可以被编译成C语言代码。 对于重复计算,评估速度至关重要,Theano通过生成非常有效的代码来达到此目的。
翻译自: https://www.tutorialspoint.com/theano/theano_computational_graph.htm
数学计算 theano