python 自动微分の例1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 自动微分の例1相关的知识,希望对你有一定的参考价值。

#coding: utf-8
import theano
import theano.tensor as T

x = T.dscalar('x')

# 微分される数式のシンボルを定義
y = x ** 2

# yをxに関して微分
# y'=2xになる
gy = T.grad(cost=y, wrt=x)

# 微分係数を求める関数を定義
f = theano.function(inputs=[x], outputs=gy)
print theano.pp(f.maker.fgraph.outputs[0])

# 具体的なxを与えて微分係数を求める
print f(2)
print f(3)
print f(4)

以上是关于python 自动微分の例1的主要内容,如果未能解决你的问题,请参考以下文章

python 自动微分の例4

python 自动微分の例3

python 自动微分の例2

python 偏微分の例

python中几种自动微分库

python 线形回帰モデルの例