<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Machine-Learning on Siddharth Mishra</title><link>http://brightprogrammer.in/tags/machine-learning/</link><description>Recent content in Machine-Learning on Siddharth Mishra</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sun, 14 Jun 2026 21:53:10 -0700</lastBuildDate><atom:link href="http://brightprogrammer.in/tags/machine-learning/index.xml" rel="self" type="application/rss+xml"/><item><title>AutoGrad - Algorithmic Differentiation in C</title><link>http://brightprogrammer.in/posts/autograd-algorithmic-differentiation/</link><pubDate>Sat, 28 Dec 2024 00:00:00 +0000</pubDate><guid>http://brightprogrammer.in/posts/autograd-algorithmic-differentiation/</guid><description>&lt;h2 id="background">Background&lt;/h2>
&lt;p>Let&amp;rsquo;s write an auto differentiation algorithm. We will take mathematical expressions
in prefix notation, build an expression tree like the one below for&lt;/p>
&lt;p>\[
\begin{align}
1338 * a + \frac{y^5}{x^{1335}}
\end{align}
\]&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c" data-lang="c">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#60a0b0;font-style:italic">// expression in prefix notation
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#60a0b0;font-style:italic">&lt;/span>Expr e &lt;span style="color:#666">=&lt;/span> &lt;span style="color:#06287e">ADD_EXPR&lt;/span>(
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#06287e">MUL_EXPR&lt;/span>(&lt;span style="color:#06287e">INT_CONSTANT_EXPR&lt;/span>(&lt;span style="color:#40a070">1338&lt;/span>), &lt;span style="color:#06287e">VAR_EXPR&lt;/span>(&lt;span style="color:#4070a0">&amp;#34;a&amp;#34;&lt;/span>, &lt;span style="color:#40a070">1&lt;/span>)),
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#06287e">DIV_EXPR&lt;/span>(&lt;span style="color:#06287e">VAR_EXPR&lt;/span>(&lt;span style="color:#4070a0">&amp;#34;y&amp;#34;&lt;/span>, &lt;span style="color:#40a070">5&lt;/span>), &lt;span style="color:#06287e">VAR_EXPR&lt;/span>(&lt;span style="color:#4070a0">&amp;#34;x&amp;#34;&lt;/span>, &lt;span style="color:#40a070">1337&lt;/span>))
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>);
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;pre tabindex="0">&lt;code class="language-mermaid" data-lang="mermaid">graph TD
 node0[&amp;#34;add&amp;#34;]
 node1[&amp;#34;mul&amp;#34;]
 node2[&amp;#34;1338&amp;#34;]
 node3[&amp;#34;$a^{1}$&amp;#34;]
 node4[&amp;#34;div&amp;#34;]
 node5[&amp;#34;$y^{5}$&amp;#34;]
 node6[&amp;#34;$x^{1337}$&amp;#34;]

 node0 --&amp;gt; node1
 node0 --&amp;gt; node4
 node1 --&amp;gt; node2
 node1 --&amp;gt; node3
 node4 --&amp;gt; node5
 node4 --&amp;gt; node6
&lt;/code>&lt;/pre>&lt;p>and then write an algorithm to traverse the expression tree, taking derivatives of each sub-expression
recursively and then generating a new expression tree that represents the derivative of the original
expression tree, like the one below by just doing &lt;code>ExprGrad(&amp;amp;e)&lt;/code>&lt;/p></description></item></channel></rss>