計算グラフの構築とスカラー順方向評価
Agent支援エンジニアリング確認
前提条件
第30日の数学基礎、Pythonオブジェクト指向の基礎、参照モデルの理解。
学習目標
スカラー算術式がどのように `Value` ノードからなる有向非巡回グラフ(DAG)にマッピングされ、順方向計算が評価されるかを理解する。
手順
自動微分では、計算グラフは数学演算を内部ノード、オペランドを入力エッジとして表現します。次のコマンドを実行してグラフ構造を確認してください:
python3 projects/autograd/cli.py graph --preset neuron --format ascii
$x_1 w_1 + x_2 w_2 + b$ が活性化関数 $o = \tanh(n)$ に流れ込む様子と、順方向の計算値を確認します。
演習と予測記録
$f(x, y) = (x \cdot y + 2)^2$ を $x = 1.5, y = -2.0$ において評価します:
1. 中間ノードを定義します: $u = x \cdot y$, $v = u + 2$, $f = v^2$。
2. $u, v, f$ の数値を計算します。
3. コードを実行する前に、予測値をエディタに記録してください。
順次計算します: $u = 1.5 \times (-2.0) = -3.0$、次に $v = -3.0 + 2 = -1.0$、最後に $f = (-1.0)^2 = 1.0$ です。
参考解答:
- $u = 1.5 \times (-2.0) = -3.0$
- $v = -3.0 + 2 = -1.0$
- $f = (-1.0)^2 = 1.0$
計算グラフは2つの葉ノード ($x, y$)、1つの定数ノード ($2$)、3つの演算ノード ($*, +, **2$) で構成されます。
スカラー算術演算を親依存ノード (`_prev`) とスカラー値 (`data`) を持つ DAG ノードとして正確に分解できること。
公式ソースリソースと権利証跡
micrograd: A tiny scalar-valued autograd engine
該当セクション・タイムスタンプ: micrograd/engine.py: class Value (_backward closures and backward() topological sort); README 'Example usage'
検証バージョンと日付: commit a9a9f94 (Verified: 2026-10-30)
Clear, minimal scalar DAG implementation demonstrating fundamental autograd data structures.
Basic Python and calculus fundamentals
Local engine implementation in projects/autograd/engine.py and offline documentation.
比較対象候補リソースと選定評価 (2)
Production scale, but too large and complex for tracing by hand in introductory lessons.
Vectorized autograd; micrograd's pure scalar model is pedagogical for hand backprop.