<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by SUNITI SRIVASTAVA on Medium]]></title>
        <description><![CDATA[Stories by SUNITI SRIVASTAVA on Medium]]></description>
        <link>https://medium.com/@sunitisrivastava5?source=rss-208e9021f4fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FirJqz6zNhfuWLhdAy-UCA.jpeg</url>
            <title>Stories by SUNITI SRIVASTAVA on Medium</title>
            <link>https://medium.com/@sunitisrivastava5?source=rss-208e9021f4fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:57:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sunitisrivastava5/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Generalizing power of Neural Networks — Universal Approximation Vs Weirstrass Approximation Theorem]]></title>
            <link>https://sunitisrivastava5.medium.com/generalizing-power-of-neural-networks-universal-approximation-vs-weirstrass-approximation-theorem-b3bfce3810d1?source=rss-208e9021f4fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3bfce3810d1</guid>
            <category><![CDATA[generalization]]></category>
            <category><![CDATA[universal-approximation]]></category>
            <category><![CDATA[neural-network-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[mathematics-in-ml]]></category>
            <dc:creator><![CDATA[SUNITI SRIVASTAVA]]></dc:creator>
            <pubDate>Wed, 01 Jan 2025 14:12:30 GMT</pubDate>
            <atom:updated>2025-01-01T14:21:12.587Z</atom:updated>
            <content:encoded><![CDATA[<h3>Generalizing power of Neural Networks — Universal Approximation Vs Weirstrass Approximation Theorem</h3><p>I have been meaning to write this for quite some time but had been delaying it in search for further answers. Now I feel the need to write this and may be revisit it sometime later. If you are a mathematician, do drop in your thoughts on the below research.</p><p>It started with me thinking about testing the Universal Approximation Theorem(link <a href="https://en.wikipedia.org/wiki/Universal_approximation_theorem">here</a>) for neural networks by testing their predictive power on Polynomial functions. I started with a simple function below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*WFl9z2nQ9v9bJ5F1LthUXg.png" /></figure><p>Below is the simple graph of this function when plotted on x in [0,100]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*txP3CFc33VN1r-jcSljl8Q.png" /><figcaption>Plot of f(x)</figcaption></figure><p>If you read through the details of Universal Approximation theorem (UAT from here onwards….coders beware !), neural networks can approximate any kind of function with the help of sufficient neurons and multiple layers of such neurons. Thus given sufficient number of model parameters, the network can learn to approximate any function.</p><blockquote>It can approximate , but can it predict ??</blockquote><p>The questions is - if it purely learns to mimic the pattern or it does learn the underlying functional form to even predict for values of X outside of the training range [0,100]. Here is the <a href="https://github.com/SUNITImaster/Test/blob/main/Approximator_level2_reg_with_noise.py">link</a> to the code that tries to test just that.</p><p>When you see the output of this experiment below , you can see that the approximations work very well on the training range [0,100] but simply very poor on the unseen data range X&gt;100.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*nTXAERTQgOIEG2tviJRbVg.png" /><figcaption>Neural Net predictions fail beyond training data range of (0 ,100 )</figcaption></figure><p>This made my mind go back to a very old mathematics theorem “Weirstrass Approximation Theorem”. Its is a centuries old theorem (18th Century) and states that the space of polynomial functions in dense in C[a,b], where C[a,b] is the space of all continuous functions defined on the interval [a,b]. So any function (as f(x) in our case) can be approximated by the polynomial function below, as closely as possible by increasing the value of n.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*JNF_GIx4XCIERZ6jdw0LhA.png" /><figcaption>image source : <a href="https://www.instagram.com/mrtranmathematics/p/C77N5SnxKcM/?img_index=2">https://www.instagram.com/mrtranmathematics/p/C77N5SnxKcM/?img_index=2</a></figcaption></figure><p>This sequence of polynomials is called Bernstein Polynomials. The code link <a href="https://github.com/SUNITImaster/Test/blob/main/Weirstrass_approximation_test.py">here</a> shows that Bernstein polynomials can equally well approximate functions similar toNeural Nets. It can even approximate a hand drawn continuous curve very well This is proven for generalized space like Rⁿ as well via the Stone-Weirstrass theorem. Graph approximation of a simple continuous hand drawn curve by Bernstein polynomials for various values of N , as generated by the code is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*78QDK5682rVsbsoatuDjVQ.png" /><figcaption>Weirstrass Polynomial fit for different values of N (200 to 1000)</figcaption></figure><p><em>Note that both in UAT and Weirstrass Theorem, the emphasis is on approximating a given continuous curve or surface via linear combination of simpler functions and both are limited by the fact that </em><strong><em>they are defined on the domain on which f(x) values are known.</em></strong></p><p>Both Neural Networks and Bernstein Polynomials would fare poorly if asked to extrapolate the value of f(x) on domain outside of training dataset.</p><blockquote>So Neural Networks &amp; Bernstein polynomials are both rote learners which lead to excellent approximation but not necessarily good prediction.</blockquote><p>So what can essentially learn the actual repeating pattern behind the curves/surfaces and master extrapolation/prediction also perfectly ? That part of our brain that sees a pattern, identifies the underlying laws and hence how to extend it further, is what is intelligence. It is this intelligence which is still missing in neural networks.</p><p>While I am still thinking about it, clearly mathematicians have toyed with this problem long long time ago and came up with ways like Fourier Transform which tries to do something fundamental i.e. breaking a complex function into a linear sum of its simpler periodic subfunctions, thus making prediction easier.</p><p>More on it later ….Till then happy researching !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3bfce3810d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Importance Sampling in Monte Carlo simulation and applications to Reinforcement Learning]]></title>
            <link>https://sunitisrivastava5.medium.com/importance-sampling-in-monte-carlo-simulation-and-applications-to-reinforcement-learning-ac8563967871?source=rss-208e9021f4fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac8563967871</guid>
            <category><![CDATA[monte-carlo-method]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[importance-sampling]]></category>
            <dc:creator><![CDATA[SUNITI SRIVASTAVA]]></dc:creator>
            <pubDate>Thu, 11 May 2023 06:46:20 GMT</pubDate>
            <atom:updated>2023-05-11T06:46:20.387Z</atom:updated>
            <content:encoded><![CDATA[<p>Its great to be able to write again. Some break from regular 9 to 5 job gives incredible amount of space to read as you please. Posting some notes here for myself for later browse and also for anyone interested in the field of probability and Machine Learning .</p><p><em>Weighted Importance Sampling</em> is one of the concepts utilized in first visit Monte Carlo method for optimal policy evaluation via off policy control. But more on that later in this post. So what is importance sampling and why is it used and how does it help ? Consider a below example of Monte Carlo simulation :</p><p><strong>MC simulation example </strong>: Consider that we are estimating the expected value of function f(x) for some distribution p(x). If p(x) is not known exactly we can do a Monte Carlo simulation over a large no. of samples and get the sample average of f(x) as a reasonably good estimate. However problem arises when there are extreme values which have low probability of occurrence but do affect the average or expected value strongly.</p><p>Consider the hypothetical distribution <em>p(x) : P(x=1)=0.99 , P(x=10) = 0.01</em></p><p>If we pull out 50 random samples to compute the average of f(x) , there are chances that x=10 is never observed. Hence the sample mean would be 1 and not 1.09 (0.99x1+10x0.01) as it should be. This is a significant amount of prediction error arising only because of extreme but rare events. To get more accurate MC estimates in such cases, we do importance sampling which is as follows :</p><p><strong>Importance Sampling method :</strong></p><ol><li>Step 1 : Generate a hypothetical distribution q(x) that gives higher probability of occurrence to extreme values and then sample from X assuming it follows this fake distribution. e.g. q(x = 10) =0.5, q(x=1)=0.5</li><li>Step 2 : The prior step will ensure that we get enough extreme values in the sample. Now simply down weight their importance in the sample average by using the importance ratio p(x)/q(x) i.e.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*sa8m08vwC48KzhMCUSGLoQ.png" /></figure><p>Assume now that you sampled 50 observations under q(x). The X observed will be 1 for approximately 25 times and 10 for remaining 25 times in the MC sample. Now the IS estimate of f(x) is :</p><p>[25x(0.01/0.5) x 10 + 25 x (0.99/0.5)x1 ]/50 = 1.09 which is the correct estimate with no standard error.</p><p><strong>Monte Carlo Off policy Prediction via importance sampling :</strong></p><p>Motivation : Often we might want to learn and compare the values of different target policies and we might not want to do the data collection for each policy separately via on policy agent. What might be a lot easier is to collect data under a general “behavior policy µ” of an agent and then use this data to predict target policy π’s value function.</p><p>The additional advantage of this is that an exploratory policy µ might provide better coverage of more rare state -action situations i.e. µ(a/s)&gt;0 , given it is purely stochastic and not near-deterministic as the on-policy methods.</p><p>The following excerpt from Sutton and Barto explains the off-policy importance sampling prediction method clearly :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*QkUKqxt34LKI0BeFrLsuFA.png" /><figcaption>Monte Carlo Off Policy Prediction (Image Credits : Sutton and Barto )</figcaption></figure><p>Consider a first Visit Monte Carlo estimation method where all first visits to state s are denoted by the set <strong>τ(s)</strong>. For each tετ(s), let T(t) denote the time of terminal state visit. Let G(t) denote the episode return for tετ(s). Ordinary Importance Sampled Value function in this case is given by :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/0*gVlpuWxeWtHNwHjn" /><figcaption>Equation 1 : Ordinary Estimate</figcaption></figure><p>Since importance sampling ratios can have infinite variance, this can lead to eventual estimates also having very high variance. In order to solve the high variance problem, Weighted Importance Sampling version is used as given by :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/0*TREF8OofFF_OHUPv" /><figcaption>Equation 2 : Weighted Estimate</figcaption></figure><p>The weighted estimate is however biased unlike the unweighted one. This however is not a problem as this bias converges to zero in case of large sample sizes.</p><p>Hoping to provide Github link to actual python code in coming articles, which show comparison of weighted vs unweighted methods.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac8563967871" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spectral Theorem and SVD — Data Science and Other Applications]]></title>
            <link>https://sunitisrivastava5.medium.com/spectral-theorem-and-svd-data-science-and-other-applications-3518e4283335?source=rss-208e9021f4fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/3518e4283335</guid>
            <category><![CDATA[spectral-analysis]]></category>
            <category><![CDATA[singular-values]]></category>
            <category><![CDATA[eigenvectors]]></category>
            <category><![CDATA[svd]]></category>
            <category><![CDATA[principal-component]]></category>
            <dc:creator><![CDATA[SUNITI SRIVASTAVA]]></dc:creator>
            <pubDate>Wed, 20 Jan 2021 08:37:32 GMT</pubDate>
            <atom:updated>2021-01-20T08:37:32.830Z</atom:updated>
            <content:encoded><![CDATA[<h3>Spectral Theorem and SVD — Data Science and Other Applications</h3><p>I was going through old linear algebra books and went over Spectral Theorem and Singular Value Decomposition(SVD) again . This theorem is one of the most widely applied concepts in data science but finds little mention . So here is a recap from the very scratch of the whole concept , so that next time you are stuck with a problem involving high dimensional data that is leading to compute challenges, you can apply SVD to try out data reduction with minimal information loss.</p><p>Starting with the mathematical concept , lets first revisit what the Spectral Theorem says :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*mVDZcEp5TTfvBDI3qNsy3A.png" /><figcaption>Source credits : Slideshare.net</figcaption></figure><p>Here D is a diagonal matrix containing eigenvalues of A . Let us go through a brief intuition on why this should hold true. Assume b₁,b₂, .., bₙ are n distinct eigenvalues of a symmetric matrix A and x₁, x₂,…xₙ are the corresponding eigenvectors. It is easy to prove that these eigenvectors form a linearly independent and orthonormal basis for Rⁿ. You may ask how? Here is a brief proof:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*X7GYApfP8iQM71aBrcX0Rg.png" /><figcaption>Image Source: Author</figcaption></figure><p>Even if eigenvalues repeat , it can be shown that the same holds true. Also, for matrix P of eigenvectors =[x₁,x₂,…xₙ] , A*P=[Ax₁,Ax₂,…Axₙ]=[b₁x₁,b₂x₂,…bₙxₙ] = PB where B=diag matrix(b₁,b₂,..bₙ) . This is equivalent to A=PBPᵗ as PPᵗ=I.</p><p>This concept can in fact be extended to any real rectangular n x d matrix B by applying the spectral decomposition to symmetric matrices BᵗB and BBᵗ.</p><p>Spectral Decomposition :</p><p>BᵗB=VDVᵗ</p><p>BBᵗ=UDUᵗ</p><p>It can be shown that B can be ultimately written as :</p><p>B = USVᵗ = ∑(√bᵢ)Uᵢ Vᵢᵗ , where bᵢ is the ith eigenvalue for BᵗB — (eq. i)</p><p>Here S is nxd diagonal matrix with (√bᵢ) as its ith diagonal entry(which are also called singular values).</p><blockquote><em>The above decomposition of matrix B into a sum of component matrices Uᵢ Vᵢᵗ , indicates that most of the information of matrix B is stored in its first few largest singular values . Now we can select only first k largest singular values and the corresponding k columns of U and V , to create a compressed matrix B* as under :</em></blockquote><blockquote><em>B* = Uₖ*Sₖ*Vₖᵗ</em></blockquote><blockquote><em>This matrix B* is a compressed representation of B, that has minimal information loss.</em></blockquote><p>This underlying concept is used in dimensionality reduction techniques in case of high dimensional correlated data(i.e. PCA, variable clustering algorithms), image compression in case of high resolution bulky images , simplifying recommendation algorithm (e.g. by creating user-genre and movie-genre matrices instead of user-movie matrix which is much more bulky)etc . For the purpose of illustration, lets deep dive into the first 2 use cases :</p><ol><li><strong>Principal Component Analysis (PCA) and Variable Clustering</strong> : Let’s start with titanic data set available on <a href="https://www.kaggle.com/c/titanic">kaggle</a>. This dataset has 1 target variable and 11 input variables. Below code snippet describes computation of Principal components from scratch using SVD and also demonstrates a comparison with built-in sklearn method for PCA, for judging accuracy of our method. Complete code for can be found at the github link provided at the end of the article.</li></ol><p><strong>Steps</strong> :</p><p><strong>Step1</strong>: The data matrix X is first scaled using Standard Scalar (X=(X-mean)/Std. dev) ) to ensure that all variables are on the same scale. This is necessary as in case of variables with different units e.g. variable1= length in cm and variable2 = width in km, variable 1 will dominate the SVD due to larger values.</p><p><strong>Step 2</strong> : Next we compute the covariance matrix , which is essentially of the form XᵗX , X being the scaled data matrix.</p><p><strong>Step 3</strong>: Spectral decomposition is found for this symmetric matrix in the form : XᵗX= VDVᵗ where V denotes the rotation matrix which holds the variable-factor loadings and D is the diagonal matrix of eigenvalues. This matrix V along with the U matrix (XXᵗ=UDUᵗ) gives the SVD of scaled matrix X i.e. <strong>X=USVᵗ</strong> .</p><p><strong>Interpretation :</strong> Looking at the form XV=US, it is clear that each row of X(representing one customer’s features) is rotated along the direction of mutually orthogonal columns of V to give the resultant orthogonal principal components. You can run the below code to see that the computed principal components exactly match with Sci-kit learn’s built in function for PCA (except for the sign as U,V and -U,-V are both permissible solutions for the SVD decomposition as signs cancel out) .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*9mi_KnG83Hek3QDJJX22rQ.png" /><figcaption>Source : Github</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*A2LU8gYjSz9RSmToLT1gCw.png" /></figure><p>If you have used variable clustering algorithms before( e.g. VARCLUS in SAS), it leverages the same principal, followed by rotation of principal components to allow for better interpretability.</p><p>2. <strong>Image Compression</strong> : I start with a high resolution grayscale image of 1080x1920 pixels that I had clicked on a trip earlier. If each pixel takes 1 bit to store, this image takes around 259,200 bytes (253KB). Lets attempt to compress this image by SVD. Let A denote the image converted to 1080x1920 array of numbers (each number between 0 to 255). We first scale the image and then attempt to find the spectral decomposition of AᵗA = VDVᵗ and of AAᵗ=UDUᵗ in order to reconstruct A as USVᵗ. By choosing only the first k columns of U and V, we can get an approximation B = UₖSₖVₖᵗ of A, which loses minimum information while achieving desired compression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*38WjelxE5X-Jjxc3DqRmCw.jpeg" /><figcaption>Original Image (Photo Credits : Me)</figcaption></figure><p>Below are compressed images achieved using different no. of singular values k. While the image is grainy for k=50 , it starts to get very clear for k≥150.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*PLJ0vQ09h3QRjOtc1b8V_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*VGjG-x6M9XVmrWwxDf2nKw.png" /><figcaption>Compression and Peak Signal to Noise Ratios at different k values</figcaption></figure><p>The complete code for both PCA and image compression can be found at my github account <a href="https://github.com/SUNITImaster/SVD/tree/master/SVD">here</a>.</p><p>Hope this article helped build an understanding how a simple mathematical tool for reduced representation can help in a variety of ways in data science and computing. Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3518e4283335" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>