<?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 Mrinal Tyagi on Medium]]></title>
        <description><![CDATA[Stories by Mrinal Tyagi on Medium]]></description>
        <link>https://medium.com/@mrinaltyagi24?source=rss-5c246cf83b93------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LLHJ4VcVgXW9e6YdXkikIQ.png</url>
            <title>Stories by Mrinal Tyagi on Medium</title>
            <link>https://medium.com/@mrinaltyagi24?source=rss-5c246cf83b93------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:57:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mrinaltyagi24/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[Deep Dive: Artificial Neural Network]]></title>
            <link>https://medium.com/data-science/deep-dive-artificial-neural-network-e77aa627dc1b?source=rss-5c246cf83b93------2</link>
            <guid isPermaLink="false">https://medium.com/p/e77aa627dc1b</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Mrinal Tyagi]]></dc:creator>
            <pubDate>Mon, 26 Jul 2021 15:50:25 GMT</pubDate>
            <atom:updated>2021-07-26T17:13:06.984Z</atom:updated>
            <content:encoded><![CDATA[<h4>Complete explanation and mathematics involved in Artificial Neural Networks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bhnfIM_g43t0RwAw" /><figcaption>Photo by <a href="https://unsplash.com/@universaleye?utm_source=medium&amp;utm_medium=referral">Munro Studio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is an ANN?</h3><p>ANN stands for Artificial Neural Network. Just like humans have BNN i.e. the Biological Neural Network, the researchers tried to replicate the working of the human brain and came up with the great invention of an Artificial Neural Network. It is a machine learning algorithm that is widely used in all sectors nowadays. Be it detecting diseases like COVID and cancer or detecting human pose in an image. ANN does it all. It is one of the most researched sections of machine learning to date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*gOVohxvQXI1AgC20iDY15Q.jpeg" /><figcaption>(Image by author)</figcaption></figure><p>An ANN at its smallest level is called the Perceptron. A perceptron is also known as a Threshold Logic Unit (TLU). It consists of a single unit also known as the neuron with multiple inputs and a single output. It is one of the simplest ANN architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*ZVGcY9ADaAyXzSOjGWlQ4Q.jpeg" /><figcaption>(Image by author) Structure of a TLU (Threshold Logic Unit)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*RKNGs9QPv2dOC4v0VXKR2g.jpeg" /><figcaption>(Image by author) Representation of a Multi Perceptron Network with bias.</figcaption></figure><p>To understand the following perceptron model, consider the inputs to the neuron/ unit as the features of the dataset that you would input in other machine learning algorithms. Looking at the diagram of a perceptron the inputs are connected with the neuron with lines known as weights. When the inputs are passed they are individually multiplied by their weight and the sum of all these multiplications is passed onto a step function to generate an output. A step function is used to provide the output of the following calculation. Sometimes a bias is also added to the inputs or TLU to offset the result of the weighted sum to right or left. This helps the model to more adaptation to the data as rather than only tweaking the weights of the network it can also tweak the biases of the network to make the network adapt to the required dataset. So the equation of calculation of output of a neural network is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/1*e_i7RiSQGWKUD_649BkDoQ.gif" /><figcaption>(Image by author) Computation of output from a simple layer.</figcaption></figure><p>Where phi is an activation function, X is the inputs matrix, W is the weight matrix and B is the Bias.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*K9DC7gjMuypGo7xhmn0KpQ.jpeg" /><figcaption>(Image by author) Heavyside step/ activation function used in Perceptrons.</figcaption></figure><p>When the model has an input layer, multiple hidden layers, and an output layer then this is known as MLP (Multi-Layer Perceptron). It works similarly to the perceptron but the inputs are connected to the first layer with some weights and these weights are connected to some other output neuron with some weights. Similar to the Perceptron, first, the inputs are multiplied by their weights and then added up to pass to a step function. Then the output from this step function of all the neurons is multiplied with the weights and added. This is then passed onto a step function to obtain the output of the network.</p><p>When you combine multiple neurons to form a deep neuron layer and stack up these layers into a deep stack model then this model is known as Artificial Neural Network. ANN falls under the deep learning section and is one of the most used algorithms nowadays.</p><h3><strong>How to train an ANN?</strong></h3><p>An ANN is trained using an algorithm called backpropagation. First, a single training instance is taken and a forward pass is performed to produce the output. Then the loss of the network is compared with the actual output of the instance taken. Then this loss is backpropagated through the whole neural network. During this step of backpropagation, first, the gradient of the loss is calculated as we have to minimize the loss. Then the gradient for each weight matrix of the network is calculated and the weight matrix is updated by subtracting the product of the eta i.e. the learning rate of the network and the gradient of the loss function. The following process continues till the last layer and this step is known as the backward pass of the backpropagation algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*QQihxh4A0gq83xqH1LPdWQ.jpeg" /><figcaption>(Image by author) Training of an Artificial Neural Network</figcaption></figure><p>An ANN can have a single output and even multiple outputs. A single forward and backward pass of all the training instances through the network is known as a single epoch. A Deep neural network required to learn complex patterns has to perform various epochs to get good prediction results.</p><h3><strong>What are step/activation functions?</strong></h3><p>A step/activation function is used to add non-linearity to the network. If there is no non-linearity in the output of the network then the network might fail in predicting complex patterns. Hence an activation function is used for the same. Some of the activation functions used are:</p><ol><li>ReLU(Rectified Linear Unit) Activation Function</li><li>Sigmoid Activation Function</li><li>Tanh Activation Function</li></ol><p>and many more……</p><blockquote>ReLU Activation Function</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*c9mvKz2R4wi6L_SCJw2CWw.png" /><figcaption>(Image by author) Representation of ReLU Activation Function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*KaoU62yqhihtWk7YJjdppg.png" /><figcaption>(Image by author) Mathematical Representation of ReLU Activation function</figcaption></figure><blockquote>Sigmoid Activation Function</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*Q0KgF9Q5WRI0SVVe8-lbFQ.png" /><figcaption>(Image by author) Representation of Sigmoid Activation Function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*DwGPsr9PrhGPjXBPPD8QAA.png" /><figcaption>(Image by author) Mathematical Representation of Sigmoid Activation Function</figcaption></figure><blockquote>Tanh Activation Function</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*J0kU8hqc2i-wUZlYUKEqpQ.png" /><figcaption>(Image by author) Representation of Tanh Activation Function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*Q2XeIb-JOaROw4s5S4LXdw.png" /><figcaption>(Image by author) Mathematical Representation of Tanh Activation Function</figcaption></figure><h3><strong>ANN in regression</strong></h3><p>ANN in regression helps in predicting values either it is house prices or the coordinates of the bounding box of an object. In a regression-based ANN, usually, no activation function is used to prevent values from being in a range of the activation function. The loss function used to train the neural network is the Mean Squared Error or the Root Mean Squared Error. Mean Squared Error and Root Mean Squared Error are used most of the time but in the case of outliers Mean Absolute Error is used as it helps in reducing the effect of outliers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*egrSv4rcP5f0TDZMXmhtWQ.jpeg" /><figcaption>(Image by author)</figcaption></figure><h3>ANN for classification</h3><p>ANN in classification helps in predicting the class from the input values provided. From classifying between dogs or cats to classifying complex human emotions, ANN finds its application in all sorts of problems. When there are 2 categories to predict we can even work with a neural network with single output and a logistic activation function as the last layer’s activation function. When we have multiple categories to predict we can use the softmax activation function if we want to get the output value of all the categories equal to 1. A cross-entropy loss function can be used to train the network. We have to assign 1 neuron per class in multi-class classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*BkVego7ftP-fYAqFb4HGPA.jpeg" /><figcaption>(Image by author)</figcaption></figure><h3>References</h3><ol><li>Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 2nd Edition by Aurélien Géron, 2019</li><li>MIT 6.S191: Introduction to Deep Learning, <a href="https://www.youtube.com/playlist?list=PLtBw6njQRU-rwp5__7C0oIVt26ZgjG9NI">https://www.youtube.com/playlist?list=PLtBw6njQRU-rwp5__7C0oIVt26ZgjG9NI</a></li></ol><p>I hope that you find this article and explanation useful. Stay tuned for other segmentation techniques in upcoming parts.</p><p>Feel free to connect and give ur suggestions: <a href="https://www.linkedin.com/in/mrinal-tyagi-02a1351b1/">https://www.linkedin.com/in/mrinal-tyagi-02a1351b1/</a></p><p><a href="https://github.com/MrinalTyagi">https://github.com/MrinalTyagi</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e77aa627dc1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/deep-dive-artificial-neural-network-e77aa627dc1b">Deep Dive: Artificial Neural Network</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Viola Jones Algorithm and Haar Cascade Classifier]]></title>
            <link>https://medium.com/data-science/viola-jones-algorithm-and-haar-cascade-classifier-ee3bfb19f7d8?source=rss-5c246cf83b93------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee3bfb19f7d8</guid>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Mrinal Tyagi]]></dc:creator>
            <pubDate>Tue, 13 Jul 2021 07:46:20 GMT</pubDate>
            <atom:updated>2021-07-16T16:19:43.350Z</atom:updated>
            <content:encoded><![CDATA[<h4>Complete explanation and mathematics for beginners</h4><p>Viola Jones is a novel approach to rapid detection of objects with running capabilities of 15 frames per second. It was the first to achieve real time object detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*f2ydXY4JcDhFUPjU5qGFrQ.png" /><figcaption>(Image by author)</figcaption></figure><p>In this article, I talk about “Viola Jones Algorithm” and it includes the following subtopics :</p><ol><li>Viola Jones Detector</li><li>What are Haar like features?</li><li>What is an integral image?</li><li>Calculation of Haar like features with Integral Image</li><li>Boosting and AdaBoost algorithm</li><li>Deep Dive into AdaBoost Algorithm mathematics</li><li>Cascade Filter</li><li>Implementation using OpenCV Library</li></ol><h3><strong>Viola Jones Detector</strong></h3><p>A Viola Jones detector consists of following steps :</p><ol><li>Calculating Integral Image</li><li>Calculating Haar like features</li><li>AdaBoost Learning Algorithm</li><li>Cascade Filter</li></ol><h3><strong>What are Haar like Features?</strong></h3><p>Haar features are the relevant features for face detection. It was proposed by Alfred Haar in 1909. They are like convolutional kernels. There are various types of haar like features but the most dominant features used are :</p><ol><li>2 Rectangular Haar features</li><li>3 Rectangular Haar features</li><li>4 Rectangular Haar features</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*UcbEDisHCn8UK_qToEenNQ.png" /><figcaption>(Image by author) Inspired (<a href="https://docs.opencv.org/3.4/d2/d99/tutorial_js_face_detection.html">https://docs.opencv.org/3.4/d2/d99/tutorial_js_face_detection.html</a>)</figcaption></figure><p>The values of a 2 rectangular feature is the difference between the sum of the pixels within 2 rectangular regions. The regions have same shape and size and are horizontally and vertically adjacent. A three rectangular feature computes the sum in a centre rectangle. Finally a four rectangular feature computes the difference between diagonal pairs of rectangles. Various variations of these regions of different sizes are convolved through the image in order to get multiple filters that will be inputs to the AdaBoost training algorithm. Calculation of these features using the standard technique would require a high computation time. In order to reduce this time, a new approach called the integral image was suggested by the authors of the paper.</p><h3><strong>What is an integral Image?</strong></h3><p>Because we have to use haar-like features in all possible sizes and locations which eventually result in around 200k features to calculate which is a really big number. The problem with novel calculation of haar features is that we have to calculate the average of a given region multiple times and the time complexity of these operations are O(n*n). We can use an integral image approach to achieve O(1) running time. A given pixel in the integral image is the sum of all the pixels on the left and all the pixels above it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o4Bqfss5VoACUFKOvexnLA.jpeg" /><figcaption>(Image by author) Inspired (<a href="https://www.mathworks.com/help/images/integral-image.html">https://www.mathworks.com/help/images/integral-image.html</a>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LITL6LaacbFfpHjagp9nyA.jpeg" /><figcaption>(Image by author) Inspired (<a href="https://m.blog.naver.com/natalliea/222198638897"><em>https://m.blog.naver.com/natalliea/222198638897</em></a><em>)</em></figcaption></figure><p>The sum of all purple boxes in the original image is equal to the sum of green boxes in the integral image subtracted by the purple boxes in the integral image.</p><h3><strong>Calculation of Haar like features with Integral Image</strong></h3><p>Using integral images we can achieve constant time evaluation of Haar features.</p><ol><li>Edge Features or 2 Rectangular Features requires only 6 memory lookups</li><li>Line Features or 3 Rectangular Features requires only 8 memory lookups.</li><li>Diagonal Features or 4 Rectangular Features requires only 9 memory lookups.</li></ol><blockquote><strong>2 Rectangle</strong> = A-2B+C-D+2E-F</blockquote><blockquote><strong>3 Rectangle</strong> = A-B-2C+2D+2E-2F-G+H</blockquote><blockquote><strong>4 Rectangle</strong> = A-2B+C-2D+4E-2F+H-2I+J</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QOLDt87T8DT-6bJpVV_raA.png" /><figcaption>Technique for calculation of sum of regions for calculation of haar like features in a constant amount of time. (Image by author)</figcaption></figure><h3><strong>Boosting and AdaBoost Algorithm</strong></h3><p>Boosting refers to any Ensemble method that can combine several weak learners into a strong learner. The general idea of most boosting methods is to train predictors sequentially, each trying to correct its predecessor. AdaBoost also known as Adaptive Boosting is one of the most popular Boosting techniques used.</p><p><strong>AdaBoost </strong>: One way for a new predictor to correct its predecessor is to pay a bit more attention to the training instances that the predecessor under-fitted. This results in new predictors focusing more and more on the hard cases. This is known as Adaptive Boosting. For example, to build an Adaptive Boosting classifier, a first base classifier (such a Decision Tree or SVM classifier) is trained and used to make predictions on the training set. The relative weights of the misclassified predictions are altered and increased in order to lay more emphasis on these predictions while making the next predictor. A second classifier is trained using the updated weights and again it makes predictions on the training set, weights are updated and so on. Once all the predictions are trained, the ensemble method makes predictions very much like boosting except the predictors have different weights depending on their overall accuracy on the weighted training set. The drawback of this type of algorithm is that it cannot be parallelized thereby increasing time required. Thus after successfully running AdaBoost on all the features we are left with the most relevant features required for detection. Therefore, this reduces computational time as we don’t have to go through all the features and is much more efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*DpB0bfZEapv9dfEDgWYXSw.png" /><figcaption>(Image by author) Inspired (Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems)</figcaption></figure><h3><strong>Deep Dive into AdaBoost Algorithm</strong></h3><p>Let’s take a closer look at the AdaBoost algorithm. Each instance weight w(i) is initially set to 1/m. A first predictor is trained and its weighted error rate r1 is computed on the training set</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*M-R0VK72lotwlwifROF4Mw.png" /><figcaption>Here we take only the misclassified instances and sum up the weights of those instances to get the weighted error rate (Image by author)</figcaption></figure><p>The predictor’s weight j is then computed using the formulae given below. The more accurate the predictor is, the higher its weight will be. If it is just guessing randomly, then its weight will be close to zero. However, most often, it is wrong and its weight will be negative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*Gfj2MIfrZZWZVJQehlWlSQ.png" /><figcaption>(Image by author)</figcaption></figure><p>Next the instance weights are updated using the formula provided below in order to boost the misclassified instances</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*BkrO9Q_QpvkYEZlA-czhLw.png" /><figcaption>(Image by author)</figcaption></figure><p>Then all the predictors are normalized using the formulae provided below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*2ClBuZz79_xQXLR80epiuA.png" /><figcaption>(Image by author)</figcaption></figure><p>Finally, a new predictor is trained using the updated weights, and the whole process is repeated until the desired number of predictors is reached which is specified by the user.</p><p>During inference, AdaBoost simply computed the predictions of all the predictors and weights then using the predictor weight αj. The predicted class is the one that receives the majority of weighted votes.</p><h3><strong>Cascade Filter</strong></h3><ul><li>Strong features are formed into a binary classifier. : Positive matches are sent along to the next feature. Negative matches are rejected and exit computation.</li><li>Reduces the amount of computation time spent on false windows.</li><li>Threshold values might be adjusted to tune accuracy. Lower threshold yield higher detection rated and more false positives.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*an9QzEqvqY9PVssknJOCrw.png" /><figcaption>(Image by author) Inspired (<a href="https://www.researchgate.net/figure/Cascade-classifier-illustration-2_fig2_323057610">https://www.researchgate.net/figure/Cascade-classifier-illustration-2_fig2_323057610</a>)</figcaption></figure><p>In simple terms, each feature acts as a binary classifier in a cascade filter. If an extracted feature from the image is passed through the classifier and it predicts that the image consists of that feature then it is passed on to the next classifier for next feature existence check otherwise it is discarded and next image is checked. This thereby decreases computation time as we have to check only some features in windows where the object is not present rather than checking all features. This is the main part of the algorithm that allows it to process videos at a rate of approximately 15 frames per second and enables real time implementation.</p><h3><strong>Implementation using OpenCV Library</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15719fec6503d40410ab109e9385704c/href">https://medium.com/media/15719fec6503d40410ab109e9385704c/href</a></iframe><h3><strong>References</strong></h3><ol><li>Rapid Object Detection using a Boosted Cascade of Simple Features : <a href="https://web.iitd.ac.in/~sumeet/viola-cvpr-01.pdf">https://web.iitd.ac.in/~sumeet/viola-cvpr-01.pdf</a></li><li><a href="https://www.youtube.com/watch?v=uEJ71VlUmMQ">Detecting Faces (Viola Jones Algorithm) — Computerphile</a> : <a href="https://www.youtube.com/watch?v=uEJ71VlUmMQ">https://www.youtube.com/watch?v=uEJ71VlUmMQ</a></li><li>Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems by Aurelien Geron</li></ol><p>Stay tuned for new research papers’ explanation like this!</p><p>Feel free to connect and give ur suggestions : <a href="https://www.linkedin.com/in/mrinal-tyagi-02a1351b1/">https://www.linkedin.com/in/mrinal-tyagi-02a1351b1/</a></p><p><a href="https://github.com/MrinalTyagi">https://github.com/MrinalTyagi</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee3bfb19f7d8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/viola-jones-algorithm-and-haar-cascade-classifier-ee3bfb19f7d8">Viola Jones Algorithm and Haar Cascade Classifier</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>