<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Functions on davethehuman.com</title><link>https://davethehuman.com/tags/functions/</link><description>Recent content in Functions on davethehuman.com</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>© 2026 Dave the human</copyright><lastBuildDate>Tue, 13 Oct 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://davethehuman.com/tags/functions/index.xml" rel="self" type="application/rss+xml"/><item><title>softmax</title><link>https://davethehuman.com/notes/softmax/</link><pubDate>Tue, 13 Oct 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/softmax/</guid><description>&lt;p&gt;

The &lt;em&gt;softmax&lt;/em&gt; function (also known as &lt;em&gt;&lt;strong&gt;normalized exponential&lt;/strong&gt;&lt;/em&gt;) is a generalization and extension of the &lt;a href="https://davethehuman.com/notes/sigmoid/"&gt;sigmoid&lt;/a&gt; to move from &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;binary classification&lt;/a&gt; to &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;multi-class classification&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It takes a vector of $K$ real numbers (&lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;logits&lt;/a&gt;) and &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;normalizes&lt;/a&gt; it into a &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;probability distribution&lt;/a&gt; consisting of $K$ probabilities proportional to the exponentials of the input numbers.&lt;/p&gt;
&lt;p&gt;For an input vector $\mathbf{z} = (z_1, z_2, \dots, z_K) \in \mathbb{R}^K$, the Softmax function $\sigma(\mathbf{z})_i$ for a specific component $i$ is defined as: &lt;/p&gt;</description></item><item><title>tanh</title><link>https://davethehuman.com/notes/tanh/</link><pubDate>Sun, 27 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/tanh/</guid><description>&lt;p&gt;

The &lt;em&gt;tanh (hyperbolic tangent)&lt;/em&gt; function maps any real valued number in a range between -1 and 1.
Similar to the &lt;a href="https://davethehuman.com/notes/sigmoid/"&gt;sigmoid&lt;/a&gt;, its shape is a continuous &amp;ldquo;S&amp;rdquo; but it is centered over 0. It is commonly used in &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;hidden layers&lt;/a&gt; of shallow &lt;a href="https://davethehuman.com/notes/neural-network/"&gt;neural network&lt;/a&gt;s and &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;RNN&lt;/a&gt;s, since it helps them converge faster during training allowing both positive and negative values, and preventing the &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;vanishing gradient&lt;/a&gt; problem.&lt;/p&gt;
$$tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}$$&lt;p&gt;&lt;figure&gt;&lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="auto"
 alt="tanh"
 width="1600"
 height="1100"
 src="https://davethehuman.com/attachments/tanh_hu_b4eaaf476e8205a3.png"
 srcset="https://davethehuman.com/attachments/tanh_hu_b4eaaf476e8205a3.png 800w, https://davethehuman.com/attachments/tanh_hu_dab57123247c5a2d.png 1280w"
 sizes="(min-width: 768px) 50vw, 65vw"
 data-zoom-src="https://davethehuman.com/attachments/tanh.png"&gt;&lt;/figure&gt;
&lt;/p&gt;</description></item><item><title>sigmoid</title><link>https://davethehuman.com/notes/sigmoid/</link><pubDate>Sat, 26 Sep 2026 00:00:00 +0000</pubDate><guid>https://davethehuman.com/notes/sigmoid/</guid><description>&lt;p&gt;

The &lt;em&gt;sigmoid&lt;/em&gt; function is used in &lt;a href="https://davethehuman.com/notes/logistic-regression/"&gt;Logistic Regression&lt;/a&gt; to transform the linear output in a probability between 0 and 1.&lt;/p&gt;
&lt;p&gt;For a linear score $z = X\beta$, the sigmoid function is: &lt;/p&gt;
$$\sigma(z) = \frac{1}{1 + e^{-z}}$$&lt;p&gt;
&lt;figure&gt;&lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="auto"
 alt="sigmoid"
 width="1600"
 height="1100"
 src="https://davethehuman.com/attachments/sigmoid_hu_37d5cdef045797d8.png"
 srcset="https://davethehuman.com/attachments/sigmoid_hu_37d5cdef045797d8.png 800w, https://davethehuman.com/attachments/sigmoid_hu_60910846251427ee.png 1280w"
 sizes="(min-width: 768px) 50vw, 65vw"
 data-zoom-src="https://davethehuman.com/attachments/sigmoid.png"&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;When negative values are also needed while keeping the sigmoid&amp;rsquo;s smooth, bounded output, &lt;a href="https://davethehuman.com/notes/tanh/"&gt;tanh&lt;/a&gt; is used.&lt;/p&gt;

&lt;h2 class="relative group"&gt;Implementation
 &lt;div id="implementation" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#implementation" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;A correct implementation of sigmoid has two branches: one for negative values and one for positive values.&lt;br&gt;
The original formula at the top of the page is correct for every &lt;a href="https://davethehuman.com/coming-soon/" rel="nofollow"&gt;real number&lt;/a&gt;, but a computer has a largest representable floating-point value that can lead to overflow with exponential operation on large positive numbers.&lt;/p&gt;</description></item></channel></rss>