<?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 Om Rastogi on Medium]]></title>
        <description><![CDATA[Stories by Om Rastogi on Medium]]></description>
        <link>https://medium.com/@omrastogi?source=rss-313e0d4cf3e0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*so6rOSACJRUS20ov</url>
            <title>Stories by Om Rastogi on Medium</title>
            <link>https://medium.com/@omrastogi?source=rss-313e0d4cf3e0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 04:50:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omrastogi/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[Design Choices in Diffusion Transformers]]></title>
            <link>https://omrastogi.medium.com/design-choices-in-diffusion-transformers-f7d4c8233535?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7d4c8233535</guid>
            <category><![CDATA[diffusion-models]]></category>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Sat, 22 Mar 2025 18:30:13 GMT</pubDate>
            <atom:updated>2025-03-22T18:30:13.153Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Study of Vanilla DiT, PixArt and Next-DiT Architectures for Visual Generation</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4wanNn_-j_H28-2hrvhCoQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@thebrownspy?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Spencer Watson</a> on <a href="https://unsplash.com/photos/brown-wooden-boards-iOMSkywIHtI?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><h3>Vanilla DiT</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*4e9trmAL1U9ZYEsPPtw2Ig.png" /><figcaption>DiT Architecture</figcaption></figure><p><strong>The Vanilla DiT uses a standard ViT block as its basic </strong>fundamental component<strong>.</strong> The latents are first encoded by a VAE, then passed into an embedder which consists of a patchify block followed by a positional embedding layer, and finally transformed into the embedding x.</p><p>The timesteps and labels are converted into embeddings using their respective embedders. Then, the time embedding t and the label embedding y are combined elementwise to form the condition C.</p><p>Finally, X (the image embedding) and C (the control embedding) are fed into the DiT block. In the DiT-XL/2 version this block is repeated for 28 times.</p><p>The output of after the last transformer block is then fed into a final feedforward layer and then unpatchify to extract the original sized latent.</p><h4>Vanilla DiT Block</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*pqES3tulJd_Csh5DS8_dNA.png" /><figcaption>Inside the transformer block</figcaption></figure><p>As we know, this is a standard ViT block except for one difference — <strong>Adaptive LayerNorm (adaLN)</strong> — which is used to inject t and y without relying on heavy mechanisms like cross-attention.</p><p>The adaLN layer modulates the network by applying a learned scale and shift applied to activations derived from C. This layer is initialized to zero to maintain training stability.</p><p>The adaLN outputs six values, namely scale, shift, and gate, to correspond to the self-attention and map layers. The scales and shifts are applied to the layer&#39;s input, while the gates are applied to the output.</p><h3>PixArt’s: Multi-resolution Text to Image</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*k1fez13X9Sgy7_juzzLeLw.png" /><figcaption>Pixart’s Flow</figcaption></figure><p>PixArt efficiently addresses the text-to-image generation problem and supports multiple resolutions. While it retains most architectural elements from DiT, key modifications include integrating caption embeddings and updating the treatment of timestep embeddings.</p><p>PixArt adopts <strong>interpolated positional embeddings</strong>, enabling the model to process latents at varying spatial resolutions without architectural changes. This multi-resolution capability supports <strong>progressive, multi-stage training</strong>, allowing faster convergence and greater flexibility.</p><p>Caption features and attention masks are extracted using a frozen T5 text encoder and passed into the model. These caption features are processed by a y_embedder to produce caption embeddings Y, which are then filtered using the attention mask. The resulting filtered embeddings Y, their valid token lengths y_len, along with image embeddings X and timestep embeddings t, are passed into the PixArt Transformer blocks.</p><h4>Pixart-MS Block</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*LDizoEmAKT9IRcTR0wEmMw.png" /><figcaption>Pixart Transformer Block</figcaption></figure><p>The modulation block from DiT is replaced with a <strong>learnable parameter table</strong>, scale_shift_tablewhich is added to <strong>scale</strong>, <strong>shift</strong>, and <strong>gate</strong> parameters. While the self-attention and MLP components remain unchanged from DiT, an additional <strong>multi-head cross-attention</strong> layer is inserted before the MLP to inject textual context.</p><p>The cross-attention is performed with image features as queries and label embeddings as keys/values. This allows the model to condition each image token on relevant semantic cues from the labels, enabling context-aware image generation.</p><h3>Next DiT</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S8StXVymFCD-IV0zATtg_Q.png" /><figcaption>Lumina T2I Flow</figcaption></figure><p>Next DiT builds on the DiT backbone with refinements aimed at improving efficiency, scalability, and training stability. It has several changes in how the latent and caption are treated.</p><p>The caption features are subjected to <a href="https://github.com/Alpha-VLLM/Lumina-T2X/blob/1c606962f95899da711633ee3a333d21c753e2d9/lumina_next_t2i/models/model.py#L847C1-L850C1">masked average pooling</a>: aggregates variable-length text inputs into a fixed-size embedding by averaging <em>only valid tokens</em> (as specified by the attention mask), effectively discarding padded or irrelevant tokens. The pooled features are then processed by a <strong>caption embedder</strong>, whose output is fused with the timestep embedding. This combined signal is leveraged to derive adaptive control parameters for <strong>Adaptive Layer Normalization (adaLN) </strong>similar to Vanilla design.</p><p>On the other hand, the image latent is input into <a href="https://github.com/Alpha-VLLM/Lumina-T2X/blob/1c606962f95899da711633ee3a333d21c753e2d9/lumina_next_t2i/models/model.py#L770">patchify_and_embed</a> module. The patchify_and_embed module first divides each image into non-overlapping patches and projects them into token embeddings using x_embedder. It then prepares the corresponding positional encodings using freq_cis, which contains the precomputed sine and cosine components used for <strong>Rotary Positional Embedding (RoPE)</strong>. These frequency encodings are sliced according to the spatial dimensions of the input and later applied to rotate the query and key vectors within attention. If the input is a list of variable-sized images, the module processes each image individually and pads the resulting token embeddings to the maximum sequence length in the batch using a learnable pad token. The positional encodings (freq_cis) are padded accordingly, and a binary mask is generated to track valid tokens. This setup allows the model to apply attention over batched inputs with consistent shape, while maintaining spatial awareness through RoPE and computational correctness through masking.</p><p>Finally the image mask, latent embed x, freq_cis, caption mask, caption feature and adaln_input are input into the transformer block. The lumina t2i has 24 blocks.</p><h4>Next DiT Block</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jszjbFPMy9PRl10XtwWtug.png" /></figure><p>Building on the standard DiT structure, this variant modifies the sublayer flow in several ways to improve efficiency and stability. First, <strong>learned scaling factors</strong> replace the original adaptive normalization, so each sublayer (attention or MLP) is simply scaled before being applied, rather than recalibrated via AdaLN. Second, the block adopts <strong>sandwich normalization</strong>, meaning it normalizes inputs both before and after the attention and MLP sublayers, which helps maintain stable activations in deeper networks. Finally, the <strong>Attention Block </strong>shown in the diagram has a both <strong>self-attention and cross-attention</strong>. The attention mechanism is implemented with a <strong>Grouped Query Attention (GQA)</strong> by projecting more query heads than key-value heads and sharing each key/value head across multiple query groups. In the forward pass, tokens are normalized, scaled, and processed by grouped cross-attention, then normalized and gated, with a similar scale–norm–MLP–norm–gate flow afterward. These updates keep the transformer’s residual architecture intact while introducing more lightweight conditioning control, higher training stability, and faster inference.</p><h4>Next DiT Attention Block</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xkzKAf-WkAZbzocxFGsR0A.png" /></figure><blockquote><em>The latent embedding </em><em>x is first projected into query, key, and value tensors: </em><em>xq, </em><em>xk, and </em><em>xv, respectively. </em><em>xq and </em><em>xk are passed through rotary positional embedding using </em><em>freqs_cis, which injects spatial position information into the attention mechanism, which allows the model to maintain relative spatial awareness across image patches. The position-encoded </em><em>xq, </em><em>xk, and </em><em>xv are passed through self-attention using </em><em>flash_attn_varlen_func, with padding temporarily removed via </em><em>_unpad_input to enable efficient computation over variable-length sequences.</em></blockquote><blockquote><em>In parallel, the caption features are projected into </em><em>yk and </em><em>yv, representing the key and value components for cross-attention. The query projection from </em><em>xq is used in both self-attention and cross-attention, allowing the image tokens to attend to themselves as well as to the caption tokens.</em></blockquote><blockquote><em>The output of cross-attention is passed through a gating layer before being added to the self-attention output. This gate is initialized to zero, meaning the model initially ignores textual input. Over time, it can learn to incorporate text as needed, offering greater flexibility and controllability compared to PixArt, where cross-attention is always active.</em></blockquote><h3><strong>Note</strong></h3><p>For one of my projects, I needed to choose between these architectures, so I conducted a focused study of their design spaces. I’ve emphasized the components most relevant to my use case, while not going into detail on areas like attention optimizations or training methodology.</p><p>I hope this write-up proves useful to others in the community. If you spot any inaccuracies or gaps, feel free to let me know.</p><p>Additionally, all the diagrams can be found <a href="https://excalidraw.com/#json=QFC1xylGpeeuXCOtqZMP8,Hyx2BrkMJF8HdILhtM8pEA">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7d4c8233535" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Intuition for
Distribution Matching Distillation]]></title>
            <link>https://omrastogi.medium.com/unpacking-distribution-matching-distillation-dcb3af1ab863?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcb3af1ab863</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[diffusion-models]]></category>
            <category><![CDATA[distillation]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Thu, 26 Dec 2024 21:54:00 GMT</pubDate>
            <atom:updated>2025-04-25T03:30:19.385Z</atom:updated>
            <content:encoded><![CDATA[<p>Diffusion models excel at generating realistic images but suffer from high computational costs due to their iterative denoising process. Distribution Matching Distillation (DMD) tackle this challenge by condensing multi-step diffusion processes into efficient one-step generators. This method utilize distribution matching loss formulations and GAN loss in order to regress from fake images to realistic images, paving the way for faster generative imaging applications.</p><h3>Distribution Matching</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cG75Q68BrwQM2sO8U8LPUA.png" /></figure><p>As with other diffusion models, the one-step generator doesn’t explicitly learn the entire data distribution. Instead, it is forced to align with the target distribution. Hence instead of conducting step-by-step approximation, a one-step generator directly maps noisy samples to the target distribution.</p><p>That is where the distillation component comes in. Pre-trained teachers provide a high-quality intermediate representation of target distribution.</p><h3>Step-by-Step Process of DMD</h3><p><strong>Step 0: Initialization</strong></p><ol><li><strong><em>One-step generator</em></strong> is initialised from pretrained diffusion unet, keeping timestep as <em>T-1</em>.</li><li><strong><em>real_unet</em></strong> is frozen teacher, that poses the real distribution</li><li><strong><em>fake_unet </em></strong>is there to model the generator’s data distribution</li></ol><p><strong>Step 1: Generate Image from Noise</strong></p><ol><li>A random noise map is passed to the generator.</li><li>The generator denoises this noise in one step, producing an image <em>x</em>.</li><li>At this stage, <em>x</em> belongs to the generator’s probability density, <em>p_fake</em>.</li></ol><p><strong>Step 2: Add Gaussian Noise</strong></p><ol><li>The image <em>x</em> is perturbed with Gaussian noise to obtain a noisy version <em>xt</em>.</li><li>The timestep <em>t</em> is sampled uniformly between <em>0.2T</em> and <em>0.98T</em> (excluding extreme no-noise or all-noise cases).</li><li>This noise injection helps overlap <em>p_fake</em> with <em>p_real</em> so their distributions can be compared.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CmPG-es4DICqVtPFswWF2g.png" /></figure><p><strong>Step 3: Pass-Through real_unet and fake_unet</strong></p><ol><li><strong>real_unet</strong> produces <em>pred_real_image</em>, representing the generator’s approximation toward the clean image</li><li><strong>fake_unet</strong> produces <em>pred_fake_image</em>, modeling how the generator’s distribution looks at this timestep.</li><li>Comparing <em>pred_real_image</em> and <em>pred_fake_image</em> highlights any discrepancy between real and fake distributions.</li></ol><p><strong>Step 4: Compute Loss</strong></p><ol><li>Next Mse between x and x — grad is calculated, to extract loss. Here, The term x — grad suggests a <strong>corrected output</strong> that moves x closer to the real data distribution by reducing the discrepancy measured by grad.</li></ol><p><strong>Step 5: Update the fake_distribution (mention update pattern as well)</strong></p><p>The fake_unet is updated with diffusion loss between x and pred_fake_image. This is the step where fake unet learns the generator’s evolving fake distribution. The loss is calculated between xt-1_pred and x, unlike other unets which calculate between xt-1_pred and xt-1_gt, such that the fake UNet learns to denoise noisy versions of the generator’s outputs (xt) back to the generator’s current outputs x.</p><h3>Some Questions</h3><p><strong>Question 1:</strong> Why is the fake_unet updated with the loss calculated as the divergence between xt-1_pred and x0, instead of comparing xt-1_pred with xt-1_gt?</p><p><strong>Answer 1:</strong> We calculate the divergence between xt-1_pred and x because the fake_unet’s goal is to denoise noisy versions of the generator’s outputs (xt) back to the generator’s current outputs (x). This ensures the fake_unet accurately tracks the generator’s evolving “fake” distribution, providing meaningful gradients to improve the generator’s output.</p><p><strong>Question 2:</strong> Why do we even need a <em>fake_unet</em>? Couldn’t the KL divergence be computed directly from the pretrained <em>real_unet</em>’s output and the generator’s output?</p><p><strong>Answer 2:</strong> The generator is intended to produce a fully denoised image in a single step, whereas the pretrained <em>real_unet</em> can only provide partial denoising in that same time frame. This mismatch prevents the <em>real_unet</em>’s output from offering a meaningful KL divergence for training the generator. Instead, the <em>fake_unet</em> is continually trained on the generator’s evolving distribution, enabling it to approximate how the generator’s outputs currently look. As a result, comparing <em>real_unet</em> and <em>fake_unet</em> outputs yields a direction (via an approximate KL divergence) to fine-tune the generator’s probability distribution and improve single-step image synthesis</p><h3>Distribution Matching Loss</h3><p>During training the KL divergence measure how much the generator’s distribution deviates from real distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*TLt5DoRUmGNZOR5fneLwMg.png" /><figcaption>Where Preal is PDF of real data distribution, while Pfake is PDF of fake distribution i.e. the generator (Gθ)</figcaption></figure><p>Computing probability densities for high-dimensional datasets is often intractable. For example, a 32×32 pixel grayscale image has 256¹⁰²⁴ dimensions, making direct density computation computationally prohibitive.</p><p>Hence, we calculate scores for real and fake distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*RQioI7J7S1psTmCHOaPEyg.png" /></figure><p>This allows us to calculate the KL divergence as Sreal moves x toward the modes of Preal, and −Sfake spreads farther from real distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*mTmvVwC9PGQk8u5CHfWOGw.png" /><figcaption>Sreal(x) is the score function of the real data distribution, Sfake(x) is the score function of the fake data distribution. ∇θ Gθ(z) is gradient of the generator’s output (x)</figcaption></figure><p>Sreal(x)−Sfake(x) corresponds to the <strong>difference between the real and fake scores</strong>. Now, Sreal for x being a fake sample will be nearly zero, hence, perturbation is added for the diffusion model to denoised from xt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkucyxApTu9qmwtN1Wex8Q.png" /><figcaption>Definition for Sfake and Sreal are taken from paper “Song et al. — Score-based generative modeling through stochastic differential equations”</figcaption></figure><p>Final Loss</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*31FWwZcGNgj-dxmTdkZK9Q.png" /></figure><h3>Intuitive Understanding</h3><p>The outputs of <strong>real_unet</strong> and <strong>fake_unet</strong> at timestep t−1 are used to form a gradient that nudges the generator’s current output, x, closer to <strong>real_unet</strong>’s output at t=0. After this gradient-based shift, a mean squared error (MSE) is computed between the generator’s original output (x) and the shifted version. Essentially, this correction step drives x to align with the real data distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*G85S46G_i2L2DtlZhm-Tdg.png" /><figcaption>Calculation of loss, as in the code</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vug6KaSUxju0_P5N4K-4pg.png" /><figcaption>This Visualizes the loss function at various timesteps, precisely showing how a multi-step generator is used to train one-step generator. <strong>Note:</strong> This diagram omits details about <strong>weighting_factor</strong> and makes a few assumptions about the underlying distributions.</figcaption></figure><p>The key idea is that the gradient derived from the difference between xfake​ and xreal​ is used to push the generator’s output toward <strong>real_unet</strong>’s final output at t=0. As the generator learns, its output gradually moves toward the real distribution, pulling <strong>fake_unet</strong>’s output closer as well. Consequently, the shifted image ∥x−grad∥ also converges toward the real distribution.</p><h3>Epilogue</h3><p>I have poured much time and effort into translating my intuition into this article. My goal has been to make the concept as clear and accessible as possible. While I’ve done my best to be thorough, I welcome any feedback or suggestions for improvement — I truly believe there’s always room to learn and grow.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcb3af1ab863" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Free Information to Ever]]></title>
            <link>https://omrastogi.medium.com/free-information-to-ever-d3f3400e149c?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3f3400e149c</guid>
            <category><![CDATA[information]]></category>
            <category><![CDATA[malpractice]]></category>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Fri, 22 Jul 2022 04:48:45 GMT</pubDate>
            <atom:updated>2022-08-02T08:08:12.582Z</atom:updated>
            <content:encoded><![CDATA[<h3>Free Information to Everyone</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*pRtP__O04RnwJv8Z" /></figure><p>There is the preconceived notion that, everyone should have the right to information. “How much information?” is a debatable topic. While the availability of information provides more transparency and helps fight corruption, deception, and malpractices. However, wrong people using the same information can bring the whole system down. Hence the idea of free information is a slippery slope.</p><p>Firstly, it is essential to release important information, by organizations to increase the transparency of their processes. By providing transparency, people can participate proactively and give their best work inside or related to the organization. Also, this transparency helps to keep a check at various steps of the process. Discrepancies and malpractices are easily identifiable in transparent systems. Democracy over Monarchy is a great example of providing transparency to each individual.</p><p>However, the same democracy comes with its drawback. There are too many stakeholders in the process that interrupt at every step, making the process very slow. Providing too much transparency can be proven harmful. Such especially is the case for Government, Military, and Research Organisations. Critical information can be easily exploited by groups like terrorists and hackers to bring down the whole organization or even worse the nation.</p><p>OpenAI after creating its state-of-the-art GPT3 did not open source the main version, while Tesla open-sourced its design and patents of electric cars for the use of other companies. Ironically, both companies are owned by Elon Musk, yet the choices differ. This is a prime example of the selectivity of disclosure of information. While Musk wanted to open source electric car technology to promote it, however, he didn’t want the wrong groups to get hold of GPT3 which can prove dangerous to generate real-sounding text.</p><p>We need to be very careful with the information we share. Neither restricting too much nor releasing too much information is the best balance that we should yearn toward. This principle is useful not just in nations or organizations, but in our personal lives as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3f3400e149c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guide to Run an application in EC2 instance]]></title>
            <link>https://omrastogi.medium.com/guide-to-run-an-application-in-ec2-instance-97dda8b3b0df?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/97dda8b3b0df</guid>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Thu, 12 May 2022 14:19:27 GMT</pubDate>
            <atom:updated>2022-05-12T14:20:14.172Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gVh1m6w1Qcd6nQlv.png" /></figure><h4>— Upload file into Ec2</h4><pre>0. Convert pem file into ppk file with putty</pre><pre>1. Open WinSCP</pre><pre>2. Provide<br>a. Enter host nameas public DNS of the ec2 instance<br>b. Username of instance i.e. ec2-user</pre><pre>3. With WinSCP, upload the folders in EC2 volume</pre><h4>— Run the python API</h4><pre>1. Install requirements &gt;&gt; pip3 install -r requirements.txt</pre><pre>2. python3 app.py</pre><h4>— Run python API in a parallel thread</h4><pre>&gt;&gt; sudo yum install python3 python3-pip tmux htop</pre><pre>&gt;&gt; tmux new -s runapp</pre><pre>&gt;&gt; pip3 install -r requirements.txt</pre><pre>&gt;&gt; python3 app.py</pre><pre>&gt;&gt; Detach(ctrl+B+D)</pre><h4>— tmux guide</h4><pre>1. Install tmux — sudo yum install tmux</pre><pre>- sudo yum install python3 python3-pip tmux htop</pre><pre>2. Within one terminal window you can open multiple windows and split-views called “panes”</pre><pre>3. Check tmux shells — tmux ls</pre><pre>4. To connect to that session you start tmux again but this time tell it which session to attach to:</pre><pre>- tmux attach -t 0</pre><pre>Note that the -t 0 is the parameter that tells tmux which session to attach to.</pre><pre>“0” is the first part of your tmux ls output.</pre><pre>5. New Tmux shell &gt;&gt; tmux new -s &lt;name&gt;</pre><pre>6. Detach from Tmux shell &gt;&gt; Ctrl-B and press D</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97dda8b3b0df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guide to Office Open XML]]></title>
            <link>https://omrastogi.medium.com/a-guide-to-office-open-xml-6ba14198ef63?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ba14198ef63</guid>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Sat, 07 Aug 2021 09:52:32 GMT</pubDate>
            <atom:updated>2021-08-07T09:52:32.275Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*Nb6fPARmIRUWSaWt" /></figure><p>Have you ever wondered, how presentations and documentations are rendered. The GUI is written in xml format defined by ISO/IEC 29500–1:2008. Here is a basic guide about the format and basic vocabulary.</p><h3>&lt;cSld&gt; (Common Slide Data)</h3><p>This element specifies a container for the type of slide information that is relevant to all of the slide types. All slides share a common set of properties that is independent of the slide type; the description of these properties for any particular slide is stored within the slide’s &lt;cSld&gt; container. Slide data specific to the slide type indicated by the parent element is stored elsewhere</p><h3>&lt;spTree&gt; (Shape Tree)</h3><p>This element specifies all shapes within a slide. Contained within here are all the shapes, either grouped or not, that can be referenced on a given slide. As most objects within a slide are shapes, this represents the majority of content within a slide. Text and effects are attached to shapes that are contained within the &lt;spTree&gt; element.</p><h3>&lt;grpSp&gt; (Group Shape)</h3><p>This element specifies a group shape that represents many shapes grouped together. This shape is to be treated just as if it were a regular shape but instead of being described by a single geometry it is made up of all the shape geometries encompassed within it. Within a group shape each of the shapes that make up the group are specified just as they normally would. The idea behind grouping elements however is that a single transform can apply to many shapes at the same time.</p><h3>&lt;grpSpPr&gt; (Group Shape Properties)</h3><p>This element specifies the properties that are to be common across all of the shapes within the corresponding group. If there are any conflicting properties within the group shape properties and the individual shape properties then the individual shape properties should take precedence.</p><h3>&lt;sp&gt; (Shape)</h3><p>This element specifies the existence of a single shape. A shape can either be a preset or a custom geometry, defined using the &lt;DrawingML&gt; framework. In addition to a geometry each shape can have both visual and non-visual properties attached. Text and corresponding styling information can also be attached to a shape. This shape is specified along with all other shapes within either the shape tree or group shape elements.</p><p>[Note: Shapes are the preferred mechanism for specifying text on a slide.]</p><h3>&lt;pic&gt; (Picture)</h3><p>This element specifies the existence of a picture object within the document.</p><h3>&lt;cxnSp&gt; (Connection Shape)</h3><p>This element specifies a connection shape that is used to connect two &lt;sp&gt; elements. Once a connection is specified using a &lt;cxnSp&gt;, it is left to the generating application to determine the exact path the connector will take. That is the connector routing algorithm is left up to the generating application as the desired path might be different depending on the specific needs of the application.</p><h3>&lt;graphicFrame&gt; (Graphic Frame)</h3><p>This element specifies the existence of a graphics frame. This frame contains a graphic that was generated by an external source and needs a container in which to be displayed on the slide surface.</p><h3>&lt;graphic&gt; (Graphic Object)</h3><p>This element specifies the existence of a single graphic object. Document authors should refer to this element when they wish to persist a graphical object of some kind. The specification for this graphical object will be provided entirely by the document author and referenced within the &lt;graphicData&gt; child element.</p><h3>&lt;graphicData&gt; (Graphic Object Data)</h3><p>This element specifies the reference to a graphic object within the document. This graphic object is provided entirely by the document authors who choose to persist this data within the document.</p><p>Attributes: <strong>&lt;uri&gt; </strong>Specifies the URI, or uniform resource identifier that represents the data stored under this tag. The URI is used to identify the correct ‘server’ that can process the contents of this tag. The possible values for this attribute are defined by the XML Schema token datatype.</p><h3>&lt;extLst&gt; (Extension List with Modification Flag)</h3><p>This element specifies the extension list with modification ability within which all future extensions of type &lt;ext&gt; will be defined. The extension list along with corresponding future extensions is used to extend the storage capabilities of the &lt;PresentationML&gt; framework. This allows for various new types of data to be stored natively within the framework.</p><h3>&lt;xfrm&gt; (2D Transform for Individual Objects)</h3><p>This element represents 2-D transforms for ordinary shapes.</p><p><strong>Child Elements:</strong></p><p>&lt;ext&gt; (Extents)</p><p>&lt;off&gt; (Offset)</p><p><strong>Attributes:</strong></p><p>&lt;flipH&gt; (Horizontal Flip)</p><p>Horizontal flip. When true, this attribute defines that the group will be flipped horizontally about the center of its bounding box.</p><p>&lt;flipV&gt; (Vertical Flip)</p><p>Vertical flip. When true, this attribute defines that the group will be flipped vertically about the center of its bounding box.example: — The following illustrates the effect of a vertical flip.</p><p>&lt;rot&gt; (Rotation)</p><p>Rotation. Specifies the clockwise rotation of a group in 1/64000 of a degree. The possible values for this attribute are defined by the ST_Angle simple type</p><p>&lt;ST_Angle&gt; (Angle): This simple type represents an angle in 60,000ths of a degree. Positive angles are clockwise (i.e., towards the positive y axis); negative angles are counter-clockwise (i.e., towards the negative y axis).<br>This simple type’s contents are a restriction of the XML Schema int datatype. The following XML Schema fragment defines the contents of this simple type:</p><h3>&lt;xfrm&gt; (2D Transform for Grouped Objects)</h3><p>This element is nearly identical to the representation of 2-D transforms for ordinary shapes. The only addition is a member to represent the Child offset and the Child extents.</p><p>&lt;chExt&gt; (Child Extents)</p><p>This element specifies the size dimensions of the child extents rectangle and is used for calculations of grouping, scaling, and rotation behavior of shapes placed within a group.</p><p>&lt;chOff&gt; (Child Offset)</p><p>This element specifies the location of the child extents rectangle and is used for calculations of grouping, scaling, and rotation behavior of shapes placed within a group.</p><p>&lt;ext&gt; (Extents)</p><p>This element specifies the size of the bounding box enclosing the referenced object.</p><p>&lt;off&gt; (Offset)</p><p>This element specifies the location of the bounding box of an object. Effects on an object are not included in this bounding box.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ba14198ef63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Airflow Installation on Windows]]></title>
            <link>https://omrastogi.medium.com/airflow-installation-on-windows-10aa38107350?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/10aa38107350</guid>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[windows-subsystem-linux]]></category>
            <category><![CDATA[airflow-installation]]></category>
            <category><![CDATA[installation]]></category>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Sat, 12 Jun 2021 17:23:28 GMT</pubDate>
            <atom:updated>2021-06-12T17:25:03.362Z</atom:updated>
            <content:encoded><![CDATA[<h4>An approach for Apache Airflow Setup</h4><p>Well, airflow can’t work on windows directly. I was not able to run airflow with docker as well. Now what? I am sharing a possible way to get airflow working on windows, that worked for me.</p><h4>Setup Windows Subsystem for Linux</h4><ol><li>Turn Window Subsystem For Linux<br>a. Setting &gt;&gt; Apps &gt;&gt; “Related settings”<br>b. Click the <strong>Programs and Features</strong> option<br>c. Click the <strong>Turn Windows features on or off</strong> option<br>d. Check the <strong>Windows Subsystem for Linux</strong> option</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/0*OhuIu4-JR9vvRb7y.jpg" /><figcaption>Turn on WSL feature</figcaption></figure><p>2. Install Ubuntu Linux<br>a. Go to Microsoft Store <br>b. Install Ubuntu ( I downloaded from Canonical Group Limited)<br>c. Click on ‘Get’, ‘install’ after it is downloaded and finally ‘Launch’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qS_95E8Eh2ua-bfPj_MSag.png" /></figure><h4>Airflow Installation</h4><ol><li>Setup of Ubuntu <br>a. Setup user and password<br>b. Upgrade and Update</li><li>Install Airflow<br>a. Activate sudo access and enter password<br>b. Check for pip and install pip if not present<br>c. install Install Airflow</li></ol><pre>&gt;&gt; apt-get update<br>............<br>............<br>&gt;&gt; apt-get upgrade<br>............<br>............<br>&gt;&gt; sudo su <br>password: <br>&gt;&gt; pip -V<br>Either pip version or Error if not installed<br>&gt;&gt; apt install python3-pip<br>&gt;&gt; pip install apache-airflow</pre><h4>Airflow Setup</h4><p>Won’t still be able to access airflow localhost webpage. By default, Airflow requires users to specify a password prior to login. To setup logins type the following after changing the specifics</p><pre>airflow users create \<br>    --username omrastogi\<br>    --firstname Om\<br>    --lastname Rastogi\<br>    --role Admin \<br>    --email omrastogi@gmail.com</pre><h4>Some Important cli commands</h4><ol><li>airflow webserver<br>To run the airflow webserver</li><li>airflow scheduler<br>To run the airflow scheduler, a new dag won’t be added until scheduler is not run</li><li>airflow dag list<br>To check the list of all dags and their repository</li><li>airflow dags unpause &lt;dag name&gt; <br>To start/resume the dag</li><li>airflow dags test &lt;dag name&gt;&lt;date&gt;<br>To test a dag on a given date</li></ol><p>It took me a lot of time to figure out each step, aforementioned are the things that worked well for me, hope they will work for you as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10aa38107350" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Haar Cascade Classifiers]]></title>
            <link>https://medium.datadriveninvestor.com/haar-cascade-classifiers-237c9193746b?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/237c9193746b</guid>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[haar-cascades]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Wed, 21 Oct 2020 19:30:56 GMT</pubDate>
            <atom:updated>2020-10-29T01:29:22.610Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn and implement Haar cascade classifier in projects…</p><h3>Viola Jones Algorithm</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/0*6hYXTHvQOtsxhhzO" /><figcaption>Working of Classifiers</figcaption></figure><p>The Viola-Jones object detection framework is a machine learning approach for object detection, proposed by Paul Viola and Micheal Jones in 2001. This framework can be trained to detect almost any object, but this primarily solves the problem of face detection in real-time. This algorithm has four steps.</p><h4>1. Haar Feature Selection</h4><p>Objects are classified on very simple features as a feature to encode ad-hoc domain knowledge and operate much faster than pixel system. The feature is similar to haar filters, hence the name ‘Haar’. An example of these features is a 2-rectangle feature, defined as the difference of the sum of pixels of area inside the rectangle, which can be any position and scale within the original image. 3-rectangle and 4-rectangle features are also used here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/0*HVkcuKqFds7lHOui" /><figcaption>Haar Features</figcaption></figure><h4>2. Integral Image Representation</h4><p>The Value of any point in an Integral Image, is the sum of all the pixels above and left of that point. An Integral Image can be calculated efficiently in one pass over the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/0*Uh1HbU3pIqCyE6bR" /></figure><h4>3. Adaboost Training</h4><p>For a window of 24x24 pixels, there can be about 162,336 possible features that would be very expensive to evaluate. Hence AdaBoost algorithm is used to train the classifier with only the best features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LW_z5gO10WZlQSph" /><figcaption>Image by Packt</figcaption></figure><h4>4. Cascade Classifier Architecture</h4><p>A cascade classifier refers to the concatenation of several classifiers arranged in successive order. It makes large numbers of small decisions as to whether its the object or not. The structure of the cascade classifier is of a degenerate decision tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*O4k602EVv7smbTFG" /><figcaption>Architecture</figcaption></figure><h3>Implementation</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d786542848520bae470ac485fd9a4db/href">https://medium.com/media/0d786542848520bae470ac485fd9a4db/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*hkyKiqv_eUd96G41LZAahQ.jpeg" /></figure><h3>Application</h3><p>Despite the arrival of deep learning(RCNN, YOLO, etc), this method is still used in many applications for face and object detection, as this is very simple yet powerful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=237c9193746b" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/haar-cascade-classifiers-237c9193746b">Haar Cascade Classifiers</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intuition to Pooling Layers in CNN]]></title>
            <link>https://medium.datadriveninvestor.com/intuition-to-pooling-layers-in-cnn-a45be956a3a9?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a45be956a3a9</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[cnn]]></category>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Thu, 27 Aug 2020 07:22:45 GMT</pubDate>
            <atom:updated>2020-10-29T01:29:17.813Z</atom:updated>
            <content:encoded><![CDATA[<p><em>An approach to understanding pooling layers and effect on backpropagation</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*mVf8A-ZGG_R1MxYL" /><figcaption>Credits <a href="https://unsplash.com/@sickhews">@sickhews</a></figcaption></figure><p>CNNs work on a weight sharing strategy, neurons are able to perform convolutions on the data with the convolution filter being formed by the weights. Pooling operation then follows which reduces the spacial size of the representation thus reducing the amount of computation and parameters in the network. Pooling layer also helps to control overfitting.</p><blockquote>No learning takes place on the pooling layers</blockquote><p>Pooling units are obtained using functions like max-pooling, average pooling and even L2-norm pooling. At the pooling layer, forward propagation results in an <em>N</em>×<em>N</em> pooling block being reduced to a single value — value of the “winning unit”.</p><p>There are only two commonly seen variations of the max pooling layer found in practice: A pooling layer with <em>F</em>=3,<em>S</em>=2 (also called overlapping pooling), and more commonly <em>F</em>=2,<em>S</em>=2. Pooling sizes with larger receptive fields are too destructive.</p><h4>Backpropagation Over MaxPooling</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/0*U0QXNgAuBo842m12.png" /><figcaption>Forward Propagation of CNN</figcaption></figure><p>To understand backpropagation over maxpooling we’ll have to understand derivative of max(x,y).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*WZBqD5AkXXBfyTQ5CD1Ogw.png" /><figcaption>Derivative of max(x,y)</figcaption></figure><p>That is, the (sub)gradient is 1 on the input that was larger and 0 on the other input. Intuitively, if the inputs are <em>x</em>=4,<em>y</em>=2, then the max is 4, and the function is not sensitive to the setting of <em>y</em>. That is, if we were to increase it by a tiny amount <em>h</em>, the function would keep outputting 4, and therefore the gradient is zero: there is no effect.</p><p>Hence the backward pass for a max(x,y) operation has a simple interpretation as only routing the gradient to the input that had the highest value in the forward pass. Hence, during the forward pass of a pooling layer it is common to keep track of the index of the max activation (sometimes also called <em>the switches</em>) so that gradient routing is efficient during backpropagation.</p><h4>What’s wrong with Pooling Layers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/0*ZUbFZr8Mvc1Nlipw.png" /><figcaption><strong>To a CNN, both pictures are similar, since they both contain similar elements.</strong></figcaption></figure><p>Pooling layers loses a lot of valuable information and it ignores the relation between the part and the whole if we are talking about a face detector so we have to combine some features (mouth, 2 eyes, face oval and a nose) to say that is a face.</p><h4>CNN without Pooling Layers</h4><p>To reduce the size of the representation they suggest using larger stride in CONV layer once in a while. Discarding pooling layers has also been found to be important in training good generative models, such as variational auto encoders (VAEs) or generative adversarial networks (GANs). It seems likely that future architectures will feature very few to no pooling layers.</p><h3>References</h3><p>[1] <a href="http://Backpropagation In Convolutional Neural Networks">Backpropagation In Convolutional Neural Networks, jefkine</a><br>[2] <a href="https://medium.com/the-bioinformatics-press/only-numpy-understanding-back-propagation-for-max-pooling-layer-in-multi-layer-cnn-with-example-f7be891ee4b4">Jae Duk Seo</a><br>[3] <a href="https://medium.com/@pechyonkin?source=post_page-----b4b559d1159b----------------------">Max Pechyonkin</a><br>[4] <a href="https://cs231n.github.io/">CS231n Convolutional Neural Networks for Visual Recognition</a><br>[5] <a href="https://towardsdatascience.com/part-2-gradient-descent-and-backpropagation-bf90932c066a">Gradient descent and backpropagation</a></p><h4>EndNote</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/123/0*lSm8m450Myvx1qUF.png" /></figure><blockquote>If you have stayed till the end — Do Clap. (50 times specifically)<br>It’ll keep me motivated to write more. Thank You.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a45be956a3a9" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/intuition-to-pooling-layers-in-cnn-a45be956a3a9">Intuition to Pooling Layers in CNN</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[numpy.random —  Generating Random Numbers In Python]]></title>
            <link>https://medium.com/analytics-vidhya/numpy-random-generating-random-numbers-in-python-fc5fff3a1594?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc5fff3a1594</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[random]]></category>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Mon, 08 Jun 2020 10:13:03 GMT</pubDate>
            <atom:updated>2020-06-11T16:07:14.607Z</atom:updated>
            <content:encoded><![CDATA[<h3>numpy.random — Generating Random Numbers In Python</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*XYQFh1NT_CtcOiGI" /></figure><p>Random number have lots of application like, cryptography, game and Neural Network. Here we’ll discuss and identify different methods for generating random numbers in NumPy module in python.</p><pre><strong><br>import numpy as np<br></strong></pre><p><strong><em>numpy.random.random (size)</em></strong>— Return random floats in the half-open interval [0.0, 1.0), ie <strong>1.0&gt;x≥0.0</strong></p><pre>&gt;&gt;&gt;np.random.random((2,2))</pre><pre>array([[ 0.66032591,  0.91397527],<br>       [ 0.63366556,  0.36594058]])</pre><p><strong><em>numpy.random.randint(low, high, size, dtype=int)</em> </strong>— Return random integers from <em>low </em>to <em>high </em>from the “<strong>discrete uniform</strong>” distribution.</p><pre>&gt;&gt;&gt; np.random.randint([1, 3, 5, 7], [[10], [20]], dtype=np.uint8)</pre><pre>array([[ 8,  6,  9,  7], <br>       [ 1, 16,  9, 12]], dtype=uint8)</pre><p><strong><em>numpy.random.randn(d1,d2,..dn)</em></strong> — Return a sample/s from the “<strong>standard normal</strong>” distribution, for given dimension.</p><pre>&gt;&gt;&gt; np.random.randn(2,2)</pre><pre>array([[ 0.6762164 , -1.37066901],<br>       [ 0.23856319,  0.61407709]])</pre><p><strong><em>numpy.random.rand(s1,s2,..sn)</em></strong> — Random values in a given given dimension and ranges between (0,1).</p><pre>&gt;&gt;&gt; np.random.rand(3,2)<br>array([[ 0.14022471,  0.96360618],  <br>       [ 0.37601032,  0.25528411],  <br>       [ 0.49313049,  0.94909878]]) </pre><p><em>random.rand and random.randn</em> are similar function, both in functionality and syntax and can be confused easily. <br><strong><em>random.rand </em></strong>— Returns sample according to standard normal distribution.<strong><em><br>random.randn</em></strong> — Returns numbers ranging between (0,1)</p><p><strong><em>numpy.random.normal(loc=0.0, scale=1.0, size=None) </em></strong><em>— </em>Draw random samples from a normal (Gaussian) distribution.</p><pre>loc : Mean (“centre”) of the distribution<br>scale : spread or “width” of the distribution</pre><pre>&gt;&gt;&gt; np.random.normal(3, 2.5, size=(2, 4))<br>array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],   <br>       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]])  </pre><p>These are the most methods used for creating random number. More details can be searched in <a href="https://numpy.org/doc/stable/reference/random/generated/numpy.random.multivariate_normal.html"><em>documentation</em></a>. To get broader knowledge on numpy check my <a href="https://medium.com/@omrastogi/master-numpy-in-45-minutes-74b2460ecb00"><em>article</em></a>.</p><blockquote>If this article was helpful, check my other articles on similar topics.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc5fff3a1594" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/numpy-random-generating-random-numbers-in-python-fc5fff3a1594">numpy.random —  Generating Random Numbers In Python</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Feature Scaling is required for Training ML Models]]></title>
            <link>https://medium.com/analytics-vidhya/why-feature-scaling-is-required-for-training-ml-models-d004212f2cd6?source=rss-313e0d4cf3e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d004212f2cd6</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[normalization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[gradient-descent]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Om Rastogi]]></dc:creator>
            <pubDate>Sun, 07 Jun 2020 08:21:05 GMT</pubDate>
            <atom:updated>2020-07-30T07:28:58.065Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ec6ZR9YocEk2f_YXDv8roQ.jpeg" /></figure><p>A question that all the Data Science learners have is, why is there a need to normalize data. Here we will discuss the answer and get the intuition of the mechanics.</p><h4>What is Normalization?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MAnACOoi0DrOsKQS.jpeg" /></figure><p><strong>Feature scaling</strong> is a method used to <strong>normalize</strong> the range of independent variables or features of data. While, data normalization refers to shifting and scaling of values. There are many ways, Features can be scaled-</p><ol><li><strong>Min Max Scaling</strong></li><li><strong>Standard Scaling</strong></li><li><strong>Max abs Scaling</strong></li><li><strong>Z-Score Scaling</strong></li></ol><p>The details of whose, most of the readers are aware and can be kept for later.</p><p>Here we are looking at the Z-score formula. Mean is subtracted by the value, then divided by the standard deviation of the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/0*zKk2Z37M4ehQVh8h.png" /><figcaption>Z-score Normalization</figcaption></figure><h4>Why Scale the data ?</h4><p>We understand that models are capable to train, no matter what type of values are provided. However the answer to this question, lies deep in the working of <strong>optimization functions of learning models.</strong></p><p>A normalized data with comparable ranges, leads to better and efficient optimization of the learning algorithms.</p><h4><strong>Intuition</strong></h4><p>We can get some intuition from the most famous optimization algorithm:<br><strong>The Gradient Descent Algorithm.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/0*fV--bekoCxRrCP_q.jpeg" /><figcaption>A complex visualization for gradient descent plane</figcaption></figure><p>To know more about gradient descent click <a href="https://medium.com/@omrastogi/fundamentals-of-logistic-regression-bde451712652"><em>here</em></a>.</p><h4>Let us look at a simplified version.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/0*-wNWzFaAhyst6gg_.png" /></figure><p>Now the <strong>size and complexity </strong>of this curve would depend on the<strong> range of data being trained</strong>.</p><p>For two feature learning model and data with similar range data, the gradient descent can look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*6HUBFz8u1sqwYU1ObYlQxw.png" /></figure><p>For a optimized learning rate, the algorithm smoothly reaches the global minima hence optimization is fast and effective.</p><p>Now let us consider unscaled data:<br>X1: Range -(1,100)<br>X2: Range -(0,1)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QyH2VFYwJdB77MkxRdjiQg.jpeg" /></figure><p>BUT IT LOOKS FINE AND HAS NO PROBLEM!!</p><p>Let us see how it reached minima for a given learning rate.(X1 perspective)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1eX6AgCDeVdC5rv9fg9Iw.png" /></figure><p>WHAT !! BUT WHY!! Why Zig zag?</p><p>This looks like unreal but, lets look at this from another perspective(of X2), for the same learning rate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*yGkIG_yHjjmdqYMmJa4btw.png" /></figure><p>Sure we can decrease the learning rate, but then the leaning in X1 will decrease too. Hence it is best to normalize and make the ranges comparable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d004212f2cd6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/why-feature-scaling-is-required-for-training-ml-models-d004212f2cd6">Why Feature Scaling is required for Training ML Models</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>