TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/itsubaki/autograd/llms.txt
Use this file to discover all available pages before exploring further.
cmd/dot tool generates a Graphviz DOT description of a computation graph. This is useful for understanding how a function’s graph changes as you compute higher-order derivatives.
Prerequisites
Install Graphviz to render DOT files as images:Generating a graph
Runcmd/dot/main.go to produce a DOT file, then pipe it to Graphviz:
tanh and writes it to sample.png.
Available flags
| Flag | Type | Default | Description |
|---|---|---|---|
-func | string | tanh | The function to visualize. See the table below for valid values. |
-order | int | 1 | The derivative order to visualize. 1 shows the first derivative graph, 2 the second, and so on. Must be ≥ 1. |
-x | float64 | 1.0 | The input value at which the graph is evaluated. |
-verbose | bool | false | Include variable values as node labels in the graph. |
Available functions
-func value | Mathematical function |
|---|---|
sin | sin(x) |
cos | cos(x) |
tanh | tanh(x) |
exp | exp(x) |
log | log(x) |
pow | x³ |
square | x² |
neg | -x |
Examples
First-order derivative of tanh
Second-order derivative of tanh
Third-order derivative with values shown
Sine function at a different input value
Output formats
Graphviz supports many output formats via the-T flag:
How it works
The tool:Evaluates the function
Creates an input variable
x with the given -x value, applies the chosen function, and names the output y.Runs backward with CreateGraph
Calls
y.Backward(variable.Opts{CreateGraph: true}) to retain the computation graph through the backward pass, making the gradient itself differentiable.Iterates to the requested order
For each additional order, calls
gx.Backward(variable.Opts{CreateGraph: true}) on the previous gradient, clearing x.Grad before each step.Next steps
Higher-Order Gradients
Learn how CreateGraph enables the multi-order differentiation that the dot tool visualizes.
Autograd Concepts
Understand computation graph construction and traversal.
Functions API
Browse all available differentiable functions.
Variable API
Reference for variable.Opts and Backward options.