数学计算 theano_Theano-计算图

数学计算 theano

数学计算 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

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

复杂图 (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

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值