<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://diegovelilla.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://diegovelilla.github.io/" rel="alternate" type="text/html" /><updated>2026-10-12T18:59:38+00:00</updated><id>https://diegovelilla.github.io/feed.xml</id><title type="html">Diego Velilla</title><subtitle>Diego Velilla&apos;s portfolio website.</subtitle><author><name>Diego Velilla</name><email>diegovelillarecio@gmail.com</email></author><entry><title type="html">Kernel Density Estimation</title><link href="https://diegovelilla.github.io/posts/kernel-density-estimation/" rel="alternate" type="text/html" title="Kernel Density Estimation" /><published>2026-10-12T00:00:00+00:00</published><updated>2026-10-12T00:00:00+00:00</updated><id>https://diegovelilla.github.io/posts/kernel-density-estimation</id><content type="html" xml:base="https://diegovelilla.github.io/posts/kernel-density-estimation/"><![CDATA[<p>A quick introduction to the <em>What</em>, <em>Why</em>, and <em>How</em> of Kernel Density Estimation.</p>

<h2 id="what">What?</h2>

<p>Estimate the shape of a probability density function from a set of observations. Most importantly, the shape of the resulting function is <strong>continuous</strong>.</p>

<h2 id="why">Why?</h2>

<p>Other simpler methods like <em>histograms</em> estimate the shape of these functions by counting the number of observations inside each bucket. This results in <em>“bumpy”</em> approximations of the original function that produced the data.</p>

<h2 id="how">How?</h2>

<p>Histograms estimate the value of the function at any given point as</p>

\[\hat{f}_X(x_0)=\frac{\#x_i \in \mathcal{N}(x_0)}{N\lambda}\]

<p>where $\mathcal{N}(x_0)$ is the set of observations that fall into the same bucket as $x_0$, $\lambda$ is the width of the bucket and $N$ is the number of observations.</p>

<p><img src="/images/kde-histogram-bins.png" alt="" /></p>
<p class="text-center"><em>Histogram of N(0,1) with 5, 20, and 100 bins. The number of bins determines our bias-variance trade-off. More bins, more variance, less bins, more bias.</em></p>

<p>As we said before, these are <em>bumpy</em> estimations of $f_X$. This is mainly because we are weighting all observations $x_i$ inside the bucket equally without taking into account that some might be closer to $x_0$ than others. This could be <em>kinda</em> patched by using more and more bins, however, a much more elegant solution solves this problem.</p>

<p>Instead of having each neighboring point of $x_0$ contribute equally, we could use</p>

\[\hat{f}_X(x_0)=\frac{1}{N\lambda}\sum_{i=1}^N K_\lambda(x_0, x_i)\]

<p>where choosing a continuous function as our $K_\lambda(x_0, x_i)$ results in a continuous estimate of $f_X$.</p>

<p>A common choice for $K_\lambda$ is the <em>Gaussian kernel</em></p>

\[K_\lambda(x_0,x) = \phi \left(\frac{x-x_0}{\lambda}\right)\]

<p>where each point’s weight decays like a $\mathcal{N}(0,\lambda^2)$, where $\lambda$ controls how fast.</p>

<p><img src="/images/kde-gaussian-lambda.png" alt="" /></p>
<p class="text-center"><em>Gaussian KDE of N(0,1) with increasing lambda. Again, lambda controls the bias-variance trade-off where a bigger lambda increases bias while a smaller one increases variance.</em></p>
<h2 id="main-takeaway">Main Takeaway</h2>

<p><strong>Kernel Density Estimation</strong> generalizes histograms by leveraging kernels to weight how much each observation contributes to estimating the density of each point.</p>

<h2 id="references">References</h2>

<p>Hastie, T., Tibshirani, R., Friedman, J. (2009). <em>The Elements of Statistical Learning: Data Mining, Inference, and Prediction.</em> 2nd ed. Springer. Section 6.6: Kernel Density Estimation and Classification.</p>]]></content><author><name>Diego Velilla</name><email>diegovelillarecio@gmail.com</email></author><category term="Statistics" /><category term="KDE" /><category term="Tutorial" /><summary type="html"><![CDATA[From histograms to smooth kernel density estimates with Gaussian kernels.]]></summary></entry><entry><title type="html">Language Models from Scratch!</title><link href="https://diegovelilla.github.io/posts/llms-from-scratch/" rel="alternate" type="text/html" title="Language Models from Scratch!" /><published>2026-07-25T00:00:00+00:00</published><updated>2026-07-25T00:00:00+00:00</updated><id>https://diegovelilla.github.io/posts/llms-from-scratch</id><content type="html" xml:base="https://diegovelilla.github.io/posts/llms-from-scratch/"><![CDATA[<p>In this meta-post I will be linking the many tutorials I write on building <strong>Language Models from scratch</strong>. In them I’ll try to cover the intuition behind the concepts by building them from the ground up. I will also be providing the link to the code repository, as well as the resources used to learn the concepts.</p>

<h1 id="building-a-small-language-model">Building a Small Language Model!</h1>]]></content><author><name>Diego Velilla</name><email>diegovelillarecio@gmail.com</email></author><category term="Metapost" /><category term="LMs from scratch" /><category term="Tutorial" /><summary type="html"><![CDATA[A meta-post linking my from-scratch tutorials on building Language Models, with intuition, code, and resources.]]></summary></entry></feed>