<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="https://nazirnayal.xyz/feed.xml" rel="self" type="application/atom+xml"/><link href="https://nazirnayal.xyz/" rel="alternate" type="text/html" hreflang="en"/><updated>2026-10-26T12:26:56+00:00</updated><id>https://nazirnayal.xyz/feed.xml</id><title type="html">blank</title><subtitle>Doctoral researcher at the Max Planck Institute for Informatics working on diffusion and flow-based generative models and world models. </subtitle><entry><title type="html">A dive into 3D reconstruction literature</title><link href="https://nazirnayal.xyz/blog/2024/a-dive-into-3d-reconstruction-literature/" rel="alternate" type="text/html" title="A dive into 3D reconstruction literature"/><published>2024-10-09T00:00:00+00:00</published><updated>2024-10-09T00:00:00+00:00</updated><id>https://nazirnayal.xyz/blog/2024/a-dive-into-3d-reconstruction-literature</id><content type="html" xml:base="https://nazirnayal.xyz/blog/2024/a-dive-into-3d-reconstruction-literature/"><![CDATA[<h1 id="introduction">Introduction</h1> <p>The goal of this post is to build a knowledge graph of the literature of 3D reconstruction in computer vision, which would allow for a smoother entry into the field for anyone beginning to work on this problem. I am building this post as I am learning and traversing the literature myself, hoping that I can help other save time. Please note that this covers the works and literature up to the end of 2024, so if you are reading this blog at a later time be careful.</p> <hr/> <h1 id="what-is-the-problem-we-are-solving">What is the problem we are solving?</h1> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>The end goal of this area is to find ways to generate reliable representations for 3D scenes which can be used in different applications. The methods in this literature seek ways to build this representation. Most of these methods differ in terms of what kind of data is used to learn the 3D representations. Some tackle the problem using many 2D images of the same view, and other then try to generate the 3D representation by using fewer and fewer 2D images for efficiency and to overcome data scarcity.
</code></pre></div></div> <h1 id="3d-representations">3D representations</h1> <ul> <li>Meshes</li> <li>Point clouds</li> <li>NeRF</li> <li>Gaussian splats</li> </ul> <h1 id="methods-based-on-density-of-views">Methods based on density of views</h1> <h2 id="dense-views">Dense views</h2> <h2 id="sparse-views">Sparse views</h2> <h1 id="per-scene-vs-cross-scene-methods">Per-scene vs. cross-scene methods</h1> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Some existing methods optimize a model for a specific scene only, while other methods utilize large datasets to learn a strong prior such that a 3D scene representation can be achieved with a single forward pass.
</code></pre></div></div>]]></content><author><name>Nazir Nayal</name></author><category term="ai"/><category term="literature-review"/><category term="3d"/><category term="computer-vision"/><summary type="html"><![CDATA[A summary and literature review of the solutions proposed to solve the 3D reconstruction problem]]></summary></entry><entry><title type="html">Road to 3D Gaussian splatting</title><link href="https://nazirnayal.xyz/blog/2024/road-to-3dgs/" rel="alternate" type="text/html" title="Road to 3D Gaussian splatting"/><published>2024-10-04T00:00:00+00:00</published><updated>2024-10-04T00:00:00+00:00</updated><id>https://nazirnayal.xyz/blog/2024/road-to-3dgs</id><content type="html" xml:base="https://nazirnayal.xyz/blog/2024/road-to-3dgs/"><![CDATA[<h2 id="introduction">Introduction</h2> <p>The end goal of this blog is to go over the necessary concepts and explanations to understand 3D Gaussian splatting. I created this blog for my own learning and to simplify learning for others as well without the need to go around the internet gathering and intersecting the pieces of knowledge. This tutorial is based on several readings from different sources which will be cited with links.</p> <h2 id="problem-overview">Problem overview</h2> <p>3D Gaussian splatting is a deep learning-based method used to create an implicit 3D representation of a scene, which allows for projecting the scene on to a 2D surface from different view points.The 3D representation is learned from a view available images of the same scene from different view points, along with their camera position information. The goal is to make the representation general enough so that we can project the scene on to novel view points. Also, whatever representation we have, we need to have an algorithm to allow rendering for rendering to a 2D image.</p> <hr/> <h2 id="representations-of-a-3d-scene">Representations of a 3D scene</h2> <h3 id="classical-representations">Classical representations</h3> <p>A 3D scene can be represented by one of the following:</p> <ol> <li><strong>3D Mesh</strong>: a set of vertices, edges, and faces that outline the 3D shape.</li> <li><strong>Point clouds</strong>: a collection of points in 3D that represent an object. They can carry additional numerical information like color, density …etc.</li> <li><strong>Voxel grids</strong>: the 3D version of pixels. Essentially cubes that partition 3D space where each cube can carry additional information.</li> </ol> <h3 id="implicit-representations">Implicit representations</h3> <p>These include neural radiance fields (NeRFs) and Gaussian splatting, which will be discussed in detail in later sections.</p> <hr/> <h2 id="neural-radiance-fields-nerfs">Neural radiance fields (NeRFs)</h2> <p>In order to train a NeRF, we need to construct a dataset of \(N\) images, each with its corresponding camera position information. Then, a neural network, (usually an MLP) is trained to take 5 coordinates \((x, y, z, \theta, \phi)\) as input, where \((x, y, z)\) are the 3D location information, and \((\theta, \phi)\) are the angles determining the view point angle. The network outputs the color and density values for each pixel of an image of a particular view. The network hence can be optimized by matching the ground truth image with the generated one over the views available in the dataset <d-cite key="numbynum"></d-cite>.</p> <h3 id="volumetric-rendering">Volumetric rendering</h3> <h2 id="3d-gaussian-splatting">3D Gaussian splatting</h2> <h3 id="representation">Representation</h3> <p> </p> <ul> <li>Location (\(\mu\)): a tuple \((x,y,z)\) which also represents the “mean” of the Gaussian.</li> <li>Covariance (\(\Sigma = RSS^TR^T\)): where \(S \in \mathbb{R}^{3 \times 3}\) is diagonal scaling matrix showing the scale in 3D, and \(R \in \mathbb{R}^{3 \times 3}\) is the rotation matrix. It can be expressed analytically using 4 <strong>quaternions</strong>. This factorization is known as the <a href="https://www.visiondummy.com/2014/04/geometric-interpretation-covariance-matrix/#Covariance_matrix_as_a_linear_transformation">eigendecomposition of a covariance matrix</a>. <d-cite key="overviewyurkova"></d-cite></li> <li>Opacity: a value between 0 and 1</li> <li>Color parameters: either the RGB values or the coefficients of spherical harmonics.</li> </ul> ]]></content><author><name>Nazir Nayal</name></author><category term="ai"/><category term="tutorial"/><category term="3d"/><category term="computer-vision"/><summary type="html"><![CDATA[A simplified and self-contained tutorial for understanding 3D Gaussian splatting [Under construction]]]></summary></entry><entry><title type="html">Bayesian networks</title><link href="https://nazirnayal.xyz/blog/2020/bayesian-networks/" rel="alternate" type="text/html" title="Bayesian networks"/><published>2020-12-11T19:59:00+00:00</published><updated>2020-12-11T19:59:00+00:00</updated><id>https://nazirnayal.xyz/blog/2020/bayesian-networks</id><content type="html" xml:base="https://nazirnayal.xyz/blog/2020/bayesian-networks/"><![CDATA[<h1 id="bayesian-networks">Bayesian networks</h1> <p>A method used to represent joint distributions implicitly using conditional independence and local interactions.</p> <h1 id="representation">Representation</h1> <p>It is represented as a directed acyclic graph. Each variable is a node, and a directed edge from node <code class="language-plaintext highlighter-rouge">A</code> to node <code class="language-plaintext highlighter-rouge">B</code> means that the random variable <code class="language-plaintext highlighter-rouge">B</code> is a function of random variable <code class="language-plaintext highlighter-rouge">A</code>. In other words, a random variable is a function of the random variables in its parent nodes.</p> <p>Every node <code class="language-plaintext highlighter-rouge">A</code> stores a table that represents the conditional probability of random variable <code class="language-plaintext highlighter-rouge">A</code> given every combination of values its parents could take.</p> \[P(A | Parents(A))\] <div class="col-sm mt-3 mt-md-0" align="center"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/bayes_net/bayes_net_example.png" sizes="95vw"/> <img src="/assets/img/bayes_net/bayes_net_example.png" class="img-fluid rounded z-depth-1" width="100%" height="auto" data-zoomable="" loading="lazy" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h1 id="from-conditional-to-joint">From conditional to joint</h1> <p>In order to extract the joint distribution from the local conditionals, we can use the following formula:</p> \[P(X_1, X_2, \dots , X_n) = \prod_{i=1}^n P(X_i|Parents(X_i))\] <h1 id="size-of-a-bayesian-network">Size of a Bayesian network</h1> <p>In order to store a table that represents an ordinary joint distribution of <code class="language-plaintext highlighter-rouge">N</code> variables where each variable can take <code class="language-plaintext highlighter-rouge">d</code> values, one would need $O(d^N)$ entries which is too large.</p> <p>One important advantage of Bayesian networks is that they reduce this size needed to store a join distribution by storing different small parts from which we can reconstruct the joint distribution. Every node contains a table that determines its value for every combination of values of its parents. If we assume that every node has no more than <code class="language-plaintext highlighter-rouge">k</code> parents, this would mean that every node has a table of size $O(d^{k+1})$ ($k + 1$ comes from the fact that we encode the parents and the node itself), so for <code class="language-plaintext highlighter-rouge">N</code> nodes, we would get a total of $O(Nd^k)$, which is a reduction that depends on <code class="language-plaintext highlighter-rouge">k</code>, the maximum number of possible parents.</p> <h1 id="does-a-bayesian-network-graph-imply-causality">Does a Bayesian network graph imply causality?</h1> <p>No, not all the time. It is easier to think of the graph as if it means that a certain variable (parent) is causing another variable (child), but that is not always the case. Rather, it only means that there is a direct conditional dependency between variables.</p> <h1 id="how-to-check-for-independence-in-bayesian-networks">How to check for independence in Bayesian networks</h1> <p>If two variables do not have a direct connection, this does <strong>not</strong> mean that they are independent, they might indirectly influence each other through other nodes.</p> <p>For example in this graph below, <code class="language-plaintext highlighter-rouge">A</code> and <code class="language-plaintext highlighter-rouge">B</code> are not necessarily independent because they can influence each other through <code class="language-plaintext highlighter-rouge">B</code>.</p> <div class="col-sm mt-3 mt-md-0" align="center"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/bayes_net/causal_chain.png" sizes="95vw"/> <img src="/assets/img/bayes_net/causal_chain.png" class="img-fluid rounded z-depth-1" width="60%" height="auto" data-zoomable="" loading="lazy" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>Nevertheless, we can prove <strong>conditional independence</strong> of some cases. For example, in the network above, we can say that <code class="language-plaintext highlighter-rouge">C</code> is conditionally independent from <code class="language-plaintext highlighter-rouge">A</code> given <code class="language-plaintext highlighter-rouge">B</code>. The intuition is that since a value of <code class="language-plaintext highlighter-rouge">B</code> was given, it already holds the influence from <code class="language-plaintext highlighter-rouge">A</code>, or another way to think of it that the influence between <code class="language-plaintext highlighter-rouge">A</code> and <code class="language-plaintext highlighter-rouge">C</code> was blocked by <code class="language-plaintext highlighter-rouge">B</code>.</p> <p>There are 3 types of simple 3-node graphs which are simple to analyze and will be used to detect properties in Bayesian networks. These graphs are <strong>causal chains</strong>, <strong>common cause</strong>, and <strong>common effect</strong>.</p> <h2 id="causal-chains">Causal chains</h2> <p>From this structure we can only say that <code class="language-plaintext highlighter-rouge">C</code> is conditionally independent of <code class="language-plaintext highlighter-rouge">A</code> given <code class="language-plaintext highlighter-rouge">B</code>. (can be proven mathematically)</p> <div class="col-sm mt-3 mt-md-0" align="center"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/bayes_net/causal_chain.png" sizes="95vw"/> <img src="/assets/img/bayes_net/causal_chain.png" class="img-fluid rounded z-depth-1" width="60%" height="auto" data-zoomable="" loading="lazy" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h2 id="common-cause">Common cause</h2> <p>Here, we can say that <code class="language-plaintext highlighter-rouge">B</code> and <code class="language-plaintext highlighter-rouge">C</code> are independent given <code class="language-plaintext highlighter-rouge">A</code>. (can be proven mathematically)</p> <div class="col-sm mt-3 mt-md-0" align="center"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/bayes_net/common_cause.png" sizes="95vw"/> <img src="/assets/img/bayes_net/common_cause.png" class="img-fluid rounded z-depth-1" width="200" height="auto" data-zoomable="" loading="lazy" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h2 id="common-effect">Common effect</h2> <p>Here, <code class="language-plaintext highlighter-rouge">A</code> and <code class="language-plaintext highlighter-rouge">B</code> are in fact fully independent, but they are not independent given <code class="language-plaintext highlighter-rouge">C</code>.</p> <div class="col-sm mt-3 mt-md-0" align="center"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/bayes_net/common_effect.png" sizes="95vw"/> <img src="/assets/img/bayes_net/common_effect.png" class="img-fluid rounded z-depth-1" width="200" height="auto" data-zoomable="" loading="lazy" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h1 id="detect-if-2-nodes-are-conditionally-independent-from-the-graph-structure">Detect if 2 nodes are conditionally independent from the graph structure</h1> <p>We can do this by tracing the undirected path between any two nodes on the graph. For every 3 consecutive nodes on the path, we check if they satisfy conditional independence. In order to do the check, we simply identify to which type this triplet belongs (causal chain, common cause, common effect). If we find any triplet on the path to voilate independence then we assume that conditional independence between source and target node is <strong>not guaranteed</strong>. The triplets which imply conditional independence are called <strong>inactive triplets</strong>, whereas triplets that violate conditional independence are called <strong>active triplets</strong>. The following figure summarizes the triplet cases.</p> <div class="col-sm mt-3 mt-md-0" align="center"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/bayes_net/triplets.png" sizes="95vw"/> <img src="/assets/img/bayes_net/triplets.png" class="img-fluid rounded z-depth-1" width="400" height="auto" data-zoomable="" loading="lazy" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>This approach is called <strong>d-separation</strong>.</p> <h1 id="markov-blanket">Markov blanket</h1> <p>For a given node <code class="language-plaintext highlighter-rouge">X</code>, we can say that it is conditionally independent of all other nodes given its Markov blanket. A <strong>Markov blanket</strong> for a node consists of its parents, children, and children’s parents. Like in the image below.</p> <div class="col-sm mt-3 mt-md-0" align="center"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/bayes_net/markov_blanket.png" sizes="95vw"/> <img src="/assets/img/bayes_net/markov_blanket.png" class="img-fluid rounded z-depth-1" width="500" height="auto" data-zoomable="" loading="lazy" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h1 id="probabilistic-inference">Probabilistic inference</h1> <p>The act of calculating the probability that some random variables take certain values from a join distribution.</p> <h1 id="inference-by-enumeration">Inference by enumeration</h1> <p>This is basically the brute force way of calculating a certain probability, where we first take the sum of the probabilities of all the hidden random variables to eliminate them, and then calculate the desired probability of the target and evidence.</p> <p><strong>Note</strong>: Hidden variables are the rest of the random variables which are neither in the target set, nor in the evidence set. Evidence contains the random variables which make the condition of the probability calculated.</p> <p>Enumeration gives an exact answer but is exponential in complexity.</p> <p>Steps of performing inference by enumeration</p> <ol> <li>From each probability table, select the entries whose rows are consistent with the evidence. That is, if we have two variables <code class="language-plaintext highlighter-rouge">A</code> and <code class="language-plaintext highlighter-rouge">B</code> in the evidence, and both take values <code class="language-plaintext highlighter-rouge">a</code> and <code class="language-plaintext highlighter-rouge">b</code> respectively, then select all rows for which variables <code class="language-plaintext highlighter-rouge">A</code> and <code class="language-plaintext highlighter-rouge">B</code> have values <code class="language-plaintext highlighter-rouge">a</code> and <code class="language-plaintext highlighter-rouge">b</code> respectively.</li> <li> <p>For all the hidden variables, sum out their values. This means compute the sum of probabilities for all combinations of hidden variables values. This operation is called <strong>marginalization</strong>.</p> \[P(Q, e_1 \dots e_n) = \sum_{h_1 \dots h_r} P(Q, h_1 \dots h_r, e_1 \dots e_k)\] </li> <li>Normalize the the the values left so that their sum is 1 and they form a valid distribution.</li> </ol> \[Z = \sum_q P(Q, e_1 \dots e_k) \space \space , \space \space P(Q | e_1 \dots e_k) = \frac{1}{Z} P(Q | e_1 \dots e_k)\] <h1 id="variable-elimination">Variable elimination</h1> <p>In enumeration, what we did was build the whole join distribution and then marginalize in order to reduce it to the desired state of target and evidence variables. The idea suggested by variable elimination to speed up the calculations is to interleave between joining and marginalizing. It basically remains exponential but it helps speed up the calculations compared to enumerations.</p> <p>In order to understand how variable elimination works, we need to understand the concept of <strong>factors</strong> first.</p> <h2 id="factors">Factors</h2> <p>Factorization as a mathematical concept means to decompose an object into a product of other objects called factors.</p> <p><strong>Note</strong>: Capital letters in a distribution determine its dimensions, because small letters denote assigned values.</p> <p>For Bayesian networks, let’s see what kind of factors there can be:</p> <ul> <li>Joint distribution $P(X,Y)$ <ul> <li>Contains entries $P(x,y)$ for all $x,y$</li> <li>Sums to 1</li> </ul> </li> <li>Selected joint $P(x, Y)$ <ul> <li>A slice of the joint distribution</li> <li>Sums to $P(x)$, because it represent probability of $x$ for every value of $y$, which means that $P(x)$ is sort of partitioned over $y$ values.</li> </ul> </li> <li>Single conditional $P(Y|x)$ <ul> <li>Contains entries $P(y, x)$ for all $y$ and fixed $x$</li> <li>Sums to 1, because it is basically a conditional probability distribution for all values of y conditioned on a single value $x$.</li> </ul> </li> <li>Family of conditionals $P(Y|X)$ <ul> <li>Contains multiple conditionals.</li> <li>Contains entries $P(y|x)$ for all $x,y$</li> <li>sums to $|X|$, which is the number of values that can be taken by the random variable $X$. This is because for every value $X$, we have a conditional distribution for $Y$ over that particular $x$, which means we essentially have $|X|$ distributions where each one sums to 1.</li> <li>Specified family $P(y|X)$ <ul> <li>Contains entries $P(y|x)$ for fixed $y$, but for all $x$.</li> <li>Sums to an unknown value.</li> </ul> </li> </ul> </li> </ul> <p>So now back to variable elimination, we will use 2 main operations, <strong>join</strong> and <strong>eleminate</strong>. Join operation basically joins two tables in a similar way to the database join operations. In simpler terms, if table <code class="language-plaintext highlighter-rouge">A</code> has two variables <code class="language-plaintext highlighter-rouge">X</code> and <code class="language-plaintext highlighter-rouge">Y</code>, and table <code class="language-plaintext highlighter-rouge">B</code> has two variables <code class="language-plaintext highlighter-rouge">Y</code> and <code class="language-plaintext highlighter-rouge">Z</code>, then a join operation would result in a 3 dimensional table of <code class="language-plaintext highlighter-rouge">X</code>, <code class="language-plaintext highlighter-rouge">Y</code>, and <code class="language-plaintext highlighter-rouge">Z</code>. where probability of an entry in table <code class="language-plaintext highlighter-rouge">A</code> is multiplied by the a probability of table <code class="language-plaintext highlighter-rouge">B</code> where the common variable <code class="language-plaintext highlighter-rouge">Y</code> values match. Eliminate operations is simply summing for all the values of a certain variable to remove it from the table.</p> <ol> <li>Select all rows that match the evidence and delete rows that do not match it, that is only if a table contains an evidence variable. If a table does not contain an evidence variable don’t touch it. Here are the steps to follow in order to solve a query using variable elimination:</li> <li>Since we cannot eliminate a hidden variable unless it exists in only one facts, we join factors which have a common hidden variable.</li> <li>Then for every factor which contains a hidden variable and that hidden variable only exists in that factor, eliminate the hidden variable.</li> <li>Repeat steps 2 and 3 until the factor left consists of target and evidence.</li> <li>Finally we normalize the table we get, because the existence of evidence variables might cause a selected joint to appear.</li> </ol> <p><strong>Note:</strong> When joining two tables where each table contains some variables on the left side of the condition and variables on right side, the trick is to place all variables on the left side of the two tables to the left side of the output table, and then place the rest on the right. This would save time in a case where a variable exists on the left side of a table and the right side of another table. To understand what I mean by left and right: $P(X|Y)$, here $X$ is the left of the condition and $Y$ is the right of the condition.</p> <p><strong>Conclusion of variable elimination</strong>: The worst case complexity of variable elimination is not better than enumeration in theory but in practice it is faster. This difference in speed is due to the fact that eliminating some variables in a certain order decreases the <strong>maximum factor generated</strong>, which affects the computations significantly if we were able to find a good ordering.</p> <h1 id="approximate-inference">Approximate inference</h1> <p>Since it takes too long to calculate exact inferences using the method discussed earlier, we may sacrifice some of the exactness in order to speed up the calculation. One method to do this is <strong>sampling</strong>.</p> <h1 id="sampling">Sampling</h1> <p>The idea behind sampling is to draw $N$ samples from a distribution and then use these samples to compute an approximate posterior probability and show that this can converge to the true probability. <strong>How can we computer a posterior probability from samples ?</strong> Simply, we divide the number of samples matching the target over the samples matching the evidence, a very basic way of calculating probability.</p> <h2 id="how-to-sample-from-a-known-distribution">How to sample from a known distribution</h2> <p>Since it is a known distribution, then for each value the random variable takes we know its probability. Hence, we do the following steps:</p> <ol> <li>Get a sample $u$ from the uniform distribution over the interval [0, 1) (assume that we have the mechanism to do so).</li> <li>For every value of the random variable assign an interval in the range [0, 1) which is of length equal to the probability at that value. We can do this because the sum of all probabilities is equal to 1.</li> <li>Choose the value of the random variable that has the sample $u$ within it.</li> <li>Repeat this process $n$ times to get $n$ samples.</li> </ol> <p>Four main sampling methods will be discussed</p> <ul> <li>Prior sampling</li> <li>Rejection sampling</li> <li>Likelihood weighting</li> <li>Gibbs sampling (most used)</li> </ul> <h1 id="prior-sampling">Prior sampling</h1> <p>To apply prior sampling on a Bayesian network:</p> <ol> <li>Sort the nodes in the graph using topological sorting.</li> <li>Iterate over the variables in the sorted order and randomly sample from each. Sampling from a node would affect sampling of its children, because if a random variable <code class="language-plaintext highlighter-rouge">A</code> gets a value <code class="language-plaintext highlighter-rouge">a</code>, then when sampling from its child <code class="language-plaintext highlighter-rouge">B</code>, we sample from the distribution that is conditioned on <code class="language-plaintext highlighter-rouge">A</code> taking the value <code class="language-plaintext highlighter-rouge">a</code>. Topological sorting guarantees that a node will not be sampled until all its parents are sampled, which determines the value combinations the child needs to sample from.</li> <li>When the last node is reached, we would have gained a single sample of our Bayesian network. So we need to repeat the steps $n$ times to get $n$ samples.</li> <li>Once we get $n$ samples, we eliminate the samples which do not match the evidence, then the desired probability would be the number of samples which match the target divided by the number of samples left.</li> </ol> <p>As $n$ goes to infinity, then the probabilities computer using prior sampling would converge to the exact original probabilities. This is why we call this sampling method <strong>consistent</strong>.</p> <h1 id="rejection-sampling">Rejection sampling</h1> <p>The idea in rejection sampling is simple, given a desired query with targets and evidence, for every sample we get, we reject it if it does not match our desired evidence. That is, if we want to collect $n$ samples, we keep drawing samples such that all the $n$ chosen samples have our evidence satisfied, so we might perform more than $n$ sampling operations to get $n$ samples which match our evidence. The number of sampling operations can be very high if our evidence is unlikely because we would reject many of the samples we get.</p> <h1 id="likelihood-weighting">Likelihood weighting</h1> <p>Rejection sampling has a very serious limitation, which is the fact that many samples can be rejected if the evidence was unlikely. Likelihood weighting solves this issue with the following steps:</p> <ol> <li>Fix the evidence variables and sample from the others instead of rejecting.</li> <li>Fixing evidence alone would disrupt the distribution and make it inconsistent. Therefore, we modify the sampling algorithm maintain and return a constant weight which is initially set to 1.</li> <li>As we move through the network in topological order, if we encounter an evidence variable, we multiply its probability give its parents with the weight constant we have and update the value of the weight to the new value (old value times probability of evidence given its parents).</li> <li>The sampling algorithm returns the sample with accumulated weight, so in this way every sample will be associated with a certain weight.</li> </ol> <p>Likelihood weighting is <strong>consistent</strong> because the product of Sampling distribution that is a result of fixing evidence and the weight of every sample (which is an accumulated product of evidence variables given their parents) gives us the original join distribution (Mathematical equations to be added here later).</p> <p><strong>Note:</strong> After generating the samples, instead of counting the number of samples satisfying the target, we sum the weights instead. This is essential to produce a consistent answer.</p> <p><strong>Issues of Likelihood weighting</strong>: Fixing the evidence affects the downstream variables (variables which are reachable from an evidence in the directed graph and come after it in the topological sorting), but it does not affect the upstream variables (variables which can reach the evidence in the directed graph and come before it in the topological sorting). this is bad because when fixing the evidence, all its downstream will be affected by its value but it would still follow the distribution. On the other hand, fixing the value of an evidence regardless of its parents values creates an inconsistency which we approximately solve by using the weight approach. Therefore, the larger the number of upstream variables, the less accurate the approximation is. Following this logic, we prefer evidences that exist at the top of the hierarchy rather than the bottom.</p> <h1 id="gibbs-sampling">Gibbs sampling</h1> <p>Gibbs sampling addresses the issue with Likelihood weighting, which is that the upstream variables of a fixed evidence are sampled independently from the fixed evidence. Gibbs sampling attempts to sample all variables taking evidence into consideration.</p> <p>Approach to generate a single sample:</p> <ol> <li>Start with a random assignment to each variable except for the evidence variables which are already fixed with their pre-determined values.</li> <li>Sample each non-evidence variable one variable at a time (round robin style), conditioned on all the other variables while keeping the evidence fixed.</li> <li>Repeat this for a long time.</li> </ol> <p>This approach has the property that repeating it infinitely many times results in a sample that comes from the correct distribution. This way we also guarantee that both upstream and downstream variables are conditioned on evidence.</p> <p><strong>One might ask</strong>: How efficient is it to sample one variable conditioned on all the rest ? Well, the probability of a variable conditioned on all the rest is equal to the joint probability divided on the probability of all the rest. In this equation many terms would cancel out between the numerator and denominator. More specifically, all conditional probability tables which do not contain the re-sampled variables will be canceled out. In other words, to re-sample a variable we simply join the tables that contain it and use them for the calculations, which can be faster if the local interactions in the Bayesian network were limited.</p> <p><strong>Note</strong>: Sampling a variable given its Markov blanket is enough.</p> <p>As with the previous methods, once we have the samples, probabilities are computer by counting samples that match the target and divide by the number of samples (because they all match the evidence by definition).</p> <p><strong>Note</strong>: Gibbs sampling is special case of a more general method called <strong>Markov chain Monte Carlo (MCMC)</strong> methods. <strong>Metropolis-Hastings</strong> is another famous MCMC method.</p> <h1 id="decision-networks">Decision networks</h1> <p>They are an extension of Bayesian networks where we assign utilities to outcomes to help make decisions. Two new types of nodes are added to the Bayesian network:</p> <ul> <li>Actions (Rectangles): cannot have parents because agents decide on their actions.</li> <li>Utility node (Diamond): depends on action and chance nodes.</li> </ul> <div class="col-sm mt-3 mt-md-0" align="center"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/bayes_net/decision_net.png" sizes="95vw"/> <img src="/assets/img/bayes_net/decision_net.png" class="img-fluid rounded z-depth-1" width="340" height="auto" data-zoomable="" loading="lazy" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>How to select an action in this network:</p> <ol> <li>Instantiate all evidence variables.</li> <li>Calculate posterior of all parents of the utility node.</li> <li>For every possible action, calculate the expected utility.</li> <li>Choose action with maximum utility. This is called the <strong>maximum expected utility (MEU)</strong>.</li> </ol> <h1 id="value-of-information">Value of information</h1> <p>Finding the value of discovering new information or in the case of Bayesian network adding new evidence values can help in deciding to which direction we must put effort in order to collect data. Therefore we attempt to calculate the value of information to guide our choices and decisions better.</p> <p><strong>How to calculate the value of information ?</strong></p> <ol> <li>Calculate the maximum expected utility (MEU) before acquiring the new evidence.</li> <li>Calculate expected MEU after acquiring the new evidence</li> <li>value of information is equal to new expected MEU minus old MEU.</li> <li>If value of information is positive, then it would by worthwhile adding this evidence.</li> </ol> <p><strong>How to calculate the expected MEU after acquiring new evidence</strong> ?</p> <ol> <li>Assume evidence is added</li> <li>For every value of the evidence, calculated expected utility conditioned on that value.</li> <li>For every value of the evidence, multiply probability of evidence with expected utility conditioned on that evidence and sum all these values. The result is the expected MEU.</li> </ol> <p>Properties of value of information (VPI):</p> <ul> <li>Non-negative: we can never get a negative VPI.</li> <li>Non-additive</li> </ul> \[VPI(E_i, E_j \| e) \neq VPI(E_i \| e) + VPI(E_j \| e)\] <ul> <li>Order independent: If you have two evidences to check their values, it doesn’t matter in which order they are calculated.</li> </ul> \[VPI(E_i, E_j \| e) = VPI(E_i \| e) + VPI(E_j \| e, E_i) = VPI(E_j \| e) + VPI(E_i \| e, E_j)\] <p><strong>Note</strong>: $VPI$ stands for value of perfect information.</p> <p>We can have some shortcuts in calculating VPO through some independence properties:</p> <ul> <li>If $Parents(U)$ ($U$ is utility node) is independent from a node <code class="language-plaintext highlighter-rouge">Z</code> given some evidence, then $VPI(Z | evidence) = 0$</li> </ul>]]></content><author><name></name></author><category term="tutorial"/><category term="ai"/><category term="tutorial"/><summary type="html"><![CDATA[A simple explanation of the basics of Bayesian networks]]></summary></entry></feed>