Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to draw dot graph for higher order differentiation by tanh function #37

Open
young-hun-jo opened this issue Jul 9, 2022 · 0 comments

Comments

@young-hun-jo
Copy link

young-hun-jo commented Jul 9, 2022

I want to visualize below graph using second order differentiation by tanh function.
스크린샷 2022-07-09 오후 4 46 55

To realize this graph, I tried to the source code that you gave us. But this code only gives me the result that just first order differentiation graph by tanh. I wonder how to draw first, second, third, ..., and higher order differentiation. plz give me some guide. Thanks.

'''
Need the dot binary from the graphviz package (www.graphviz.org).
'''
import numpy as np
from dezero import Variable
from dezero.utils import plot_dot_graph
import dezero.functions as F

x = Variable(np.array(1.0))
y = F.tanh(x)
x.name = 'x'
y.name = 'y'
y.backward(create_graph=True)

iters = 3

for i in range(iters):
    gx = x.grad
    x.cleargrad()
    gx.backward(create_graph=True)

gx = x.grad
gx.name = 'gx' + str(iters + 1)
plot_dot_graph(gx, verbose=False, to_file='tanh.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant