<?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 skillissue on Medium]]></title>
        <description><![CDATA[Stories by skillissue on Medium]]></description>
        <link>https://medium.com/@ashusoni1505?source=rss-578dd3d4ffef------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tVriNUoUfXc5Unh41ZY9ZA.png</url>
            <title>Stories by skillissue on Medium</title>
            <link>https://medium.com/@ashusoni1505?source=rss-578dd3d4ffef------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:31:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashusoni1505/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[What exactly is counter propagation ?]]></title>
            <link>https://medium.com/@ashusoni1505/what-exactly-is-counter-propagation-481155b6c7b3?source=rss-578dd3d4ffef------2</link>
            <guid isPermaLink="false">https://medium.com/p/481155b6c7b3</guid>
            <dc:creator><![CDATA[skillissue]]></dc:creator>
            <pubDate>Thu, 04 Sep 2025 21:15:36 GMT</pubDate>
            <atom:updated>2025-09-04T21:15:36.561Z</atom:updated>
            <content:encoded><![CDATA[<p>In the last blog, we learnt about making a perceptron to solve for the AND/OR problems but well, life would be so much more easier if there were not many problems other then AND or OR right?<br>So this means we’ll need more then 1 layer of a neural network to solve bigger problems.</p><p>Today, let’s take a look at a certain type of neural network, the Artificial Neural Networks .<br>What we know about neural networks today comes from the work done around perceptrons and more specifically in ANNs, work on this first started in 1970s and 80s.<br>Not much work was done in this domain mainly because of the back propagation algorithm being introduced followed by RNNs and CNNs, nevertheless, its always good to learn the in and outs of the technologies worked on before to learn and improve.</p><p>So today, we’ll learn and implement the Counter Propagation network from scratch.<br>So what exactly does this term mean literally?<br>Well this name comes from 2 different types of ML Algorithms which are complementary to each other.</p><p>The first one being Competitive Learning which is an Unsupervised learning algorithm. In this algorithm, the input is matched against weight vectors.<br>The second one is the Outstar Structure which is a Supervised learning algorithm. Here, once the winning neuron is found, the target output is propagated back through the column weights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/0*MLbC8Wlnq9ce8Aw8.jpg" /></figure><p>Yea, this diagram looks kinda overwhelming, lets break it down.<br>The first algorithm is the forward path where the input propagates to the Kohonen layer (refer Kohonen networks) followed by the output <br>The second algorithm is the one that acts as the corrective signal, it updates the winning neuron’s links.</p><p>I’m pretty sure this went over the head right?<br>Well, let’s imagine this in more layman terms. <br>Let’s take an example of a library, the first layer a.k.a the Kohonen Layer so here, the librarian arranges the books in 2 ways Novels and Not Novels, this is called unsupervised grouping.<br>Then comes the Grossberg layer ( Grossberg devised the Outstar structure).<br>In this layer, a teacher comes and mentions that so and so book is written by Franz Kafka, so the librarian immediately sorts the book again with in novels to Kafka or Not Kafka and so on based on the authors. This is supervised association.</p><p>So the next time a similar book comes, the librarian will be able to figure out whether the book is written by Kafka or not.<br>Noticed the flow here? when the book comes, the input defines where to keep the book<br>and when there’s a label given by the teacher, its the output that tells you who wrote the book. Both the informations meet somewhere in the middle.<br>This explains the name Counter Propagation.</p><p>Now that I’ve explained stuff, lets actually implement this in Python.</p><p>First we load the dataset. Unlike last time where we just defined a very simple data, this time we’ll take something more unusual so from the UC Irvine Machine Learning Repository, we’re going to take the Iris data set which has a bunch of data about flowers.</p><p>Our first part deals with loading and pre-processing of the dataset.<br>So what we do is, to extract features using iloc function of pandas<br><em>X = df.iloc[:, 1:5].values.astype(float)</em> and then we extract only 4 features and ignore the ID Column. Next we do min max scaling by normalizing the features between 0 and 1 to keep things light for our model.<br>Once we’re done with that, we convert those flower species to vectors using one-hot encoding so our vectors look like 1–0–0, 0–1–0 or 0–0–1.</p><p>Done? lets move to defining the actual model architecture<br>Our model basically consists of 2 Layers as we discussed, the Kohonen layer and the Grossberg layer.</p><p>So in the Kohonen layer, all the features are learned in an unsupervised manner which in code terms looks like this <br> <em>self.w_hidden = np.random.rand(hidden_dim, input_dim)</em><br>our parameters hidden dimension and input dimensions are basically the number of neurons in the hidden layer and the number of features in the inputs<br>all the parameter values in this layer are between 0 and 1 .</p><p>In the Grossberg layer, we make an array of zeros because the neurons have no clue of where they really belong so gradually these neurons update their values and link to the correct output class.<br>In code, its just<br><em>self.w_output = np.zeros((hidden_dim, output_dim))</em></p><p>Alright we’ve done the data related work, we’ve made the architecture of the neural network, now its time to assign the winner basically this is where the competitive learning part happens. <br>we compute the distance between input x and all of the hidden neurons, the one with least distance wins</p><p><em>def winner(self, x):<br> dists = np.linalg.norm(self.w_hidden — x, axis=1)<br> return np.argmin(dists)</em></p><p>Training the data is our next task now, so here its just traversing past the 2 layers, first our model moves the winning neuron’s weight closer to input.<br>Next we take the difference between the target and the winner from step 1, move the weights of neuron with respect to the target using lr_out and repeat at every example. <br>In more easier terms its as simple as stating the obvious<br>“Hey neuron, you just saw a Setosa flower. Remember: you belong to Setosa!”<br>Yea, No Sh*t Sherlock ! <br>This kind of feels like gas lighting but well, that’s what our aim really is right?</p><p>So we’re almost done , now we just predict the outputs and evaluate by calculating accuracy and then set the number of epochs (basically 1 epoch is the equivalent of 1 pass of the training dataset through our defined algorithm), do some magic (nah its just math, like they’re any different though) and done.<br>You have officially trained your very own counter propagation network in the backyard (nah its just your laptop).</p><p>Now lets run the code and see the best accuracy, and the worst accuracy.<br>I’ve run this for 100 epochs because python ( I tried running 10,000 times too but it took like 20 Minutes and for obvious reasons, I’m not doing it again)<br>The same thing can be trained in C/C++ for over 1,00,000 epochs and it’ll still be done in lesser time than this with far better accuracy.</p><p>Here’s the outputs</p><p>This is in python:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5HQaYb2DBWxEk4bblxqT1g.png" /></figure><p>This is in C:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7NJ3yX0MxngCqZkHPJGFIA.png" /></figure><p>Well lets keep aside the best accuracy but look at the worst and the average accuracy, its literally 62% for worst and average is barely around 70–75%.<br>Clearly, this is why Counterpropagation did not break through, because ofcourse, ain’t nobody paying those staggering electricity bills for a compute this heavy.</p><p>Eventually as time progressed and the AI-Winter of 1980s passed by, we got something better, Convolutional Neural Networks and the paper for it was authored by none other then Yann LeCun in 1998.</p><p>Well that’s a topic for another day, until then we keep learning more.</p><p>Here’s the code implementation in both Python and C <br>(had to use GPT to fix the code a lot of times because of course, skill issue)<br><a href="https://github.com/ASHUTOSH-06-SONI/cpn-iris">https://github.com/ASHUTOSH-06-SONI/cpn-iris</a></p><p>Sayonara</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=481155b6c7b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Training a Machine to Think: Day 0]]></title>
            <link>https://medium.com/@ashusoni1505/training-a-machine-to-think-day-0-4866171206f1?source=rss-578dd3d4ffef------2</link>
            <guid isPermaLink="false">https://medium.com/p/4866171206f1</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[skillissue]]></dc:creator>
            <pubDate>Sun, 20 Jul 2025 18:00:29 GMT</pubDate>
            <atom:updated>2025-09-04T21:11:28.870Z</atom:updated>
            <content:encoded><![CDATA[<p>One fine day a man asked a very thought provoking question.<br>The question was “Can machines think ?”<br>And with that, a bunch of scientists, mathematicians, physicists and engineers came together and created a whole new realm of computer science known as Machine Learning.</p><p>Well I won’t cover the history behind all this, this is just going to be my documentation of learning how I can make machines learn.<br>So the first thing that strikes our mind when we say the word “learn” is to acquire some information. <br>And what happens at the back of our mind? Well, we tend to remember what we know about the “topic” beforehand.<br>So lets say I say the word football, <br>what exactly would come to your mind? <br>well in my case it’s quite literally a football’s image and furthermore, my mind would think of my favourite football team Liverpool and then my current favourite football player and then more players followed by iconic matches, victories, titles and so on. <br>As you can see in this example, our mind associates each term to another different term and makes an entire rabbit hole out of it.<br>What exactly just happened here? <br>Well the answer is, electrochemical reactions and the medium of those is the neurons in our brain or as we informally call it the “brain cells”.</p><p>So after a whole long para of introspection of how we think, now let’s make the machines think.</p><p>Let’s speedrun this process from the top in order to make a machine think. First we have our inputs, next the weights, chip in some biases, pass it through a function, and while that happens, find the loss and, slap in that activation function and voila, you have successfully created a brain cell or as we call it “Neuron”.</p><p>Now that we’ve collected the required things (not quite literally), where do we get started with this jargon?<br>I’m going to do this in C because why not?<br>Now since we’re literally at the ground level, lets first define our “simple” data that the machine should predict.<br>Let’s take an equation- y=2x, we’ll take the range of x from 0 to 4<br>so y should return 0,2,4,6,8. We can take a higher range for x values but lets just keep it simple for now.<br>And while that’s defined in a 2D array, lets also define a variable called train_count which evaluates the number of training data points.</p><p>Now, what exactly happens in Machine learning is that you just provide input data in the background, do some probability, statistics and permutations/combinations with it until you get the output magically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/0*h50MXbrbfWjrqJoI.png" /><figcaption>Credits to xkcd.com</figcaption></figure><p>Yep, it’s just throwing darts in blindfolded until it literally hits the bulls eye.<br>In our case, the darts are the parameters which we tweak.<br>So now, we generate some random number between 0 and 1, why this range ? <br>Well later in this blog we’ll discuss something called an activation function, and there the picture will be more clear.</p><p>Moving on, lets just make an equation, y=w*x+b <br>so w is the parameter we’re tweaking here. <br>So after doing this, the outcomes are 🥁🥁🥁</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*CWxqMVm4iCFdJVgCJlzZBw.png" /></figure><p>Now that doesn’t look too good.<br>So what do we do now?</p><p>Well first let’s calculate how far are we from the actual output, and then we’ll catch up with the actual output too.</p><p>For that, we’re going to calculate the difference between the actual and the expected outputs and then we take its square.<br>Why square it? well squaring makes the negative values positive so there’s going to be no cancellation when we sum up the errors and besides y=x² is a differentiable function. <br>There are other ways too like taking the absolute value of the difference, y=|x| but |x| has a sharp point at x=0 and hence it isn’t differentiable.<br>Now I won’t make this more math heavy but the reason why we’re accounting for differentiability is because, while minimizing the error, we need to see in the vicinity of all x values to find the optimal spot where the difference is minimal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/0*QMjGtDUrwdYniOxf.gif" /></figure><p>Once we’ve calculated the mean squared difference, we just take its average that is just dividing it by the number of training data points.</p><p>And this is called “Cost Function”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/0*xrD16e5Dkh3L30-a.png" /><figcaption>Credits: Simplilearn.com</figcaption></figure><p>But does this minimize stuff? No, this just gives us the net distance from the actual value we need. <br>So to minimize, we differentiate stuff. Why differentiate? because hey, we see both the left and right hand sides and move accordingly. So if our cost function is say 2, we instruct our code to just move towards 0.<br>Now taking derivative for x² is pretty basic it’s just 2x, but even then our function isn’t always supposed to be x². We can’t just use 2x (coz we’re making a generalized solution) so, let’s use the first principle.</p><p>We could use the finite difference method too but well, lets keep it simple for now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/179/0*OCo3OpCw3ix3QYMm" /><figcaption>Source-wikipedia</figcaption></figure><p>Alright, so for our case, the code for this would look like:</p><p>float eps = 1e-3;<br>float d_cost= (cost_function(w+eps)+cost_function(w))/eps;<br>*PS- Here eps is just a constant we’ve taken <br>And after doing so, <br>After Differentiation 61.294552</p><p>Now this makes things worse, LOL!</p><p>So to cope with this, they (the folks who were working out all of the maths) introduced a new variable. <br>Introducing, learning rate.<br><strong>learning rate</strong> is a <a href="https://en.wikipedia.org/wiki/Hyperparameter_(machine_learning)">tuning parameter</a> in an <a href="https://en.wikipedia.org/wiki/Mathematical_optimization">optimization algorithm</a> that determines the step size at each iteration while moving toward a minimum of a <a href="https://en.wikipedia.org/wiki/Loss_function">loss function</a>.</p><p>Yea I know you didn’t quite understand it, so basically, even if you use derivatives, the values are just too much to direct the prediction values towards 0. This learning rate variable is hence multiplied by the differentiated function.</p><p>So this somehow gives a closer output.<br>This is where the line “Stir the pile until things start looking right” becomes real. <br>Eventually, we add something called the bias to our model for accuracy (xD)<br>well in this case we can omit this part because we’ve just coded something as basic as y=2x but machine doing more slavery.</p><p>And finally, just run this cost function code snippet as many times as possible and the final output looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EajBmaS_qq2W_HvUt-DtTg.png" /></figure><p>PS- When I mentioned iteratively, I literally meant it, the loop runs for around 10000 times before getting an output this close.</p><p>Adding to the detail we can also consider to wrap an activation function over the main function y=w*x+b <br>Activation function restricts the output between 0 and 1 ( yea more restrictions, smh)<br>We may consider using any one of these depending on the problem statement:<br>- ReLU- Rectified Linear Unit<br>- Sigmoid Function<br>- Softmax Function<br>- Hyperbolic Tangent function</p><p>I’ve not used activation function here because for a statement this basic, the activation function might only cause overfitting which is equally a problem.</p><p>Remember, the target here is not to get 0 loss, the target is to minimize the loss.</p><p>And with this finally, we have coded and trained our very own Brain Cell.</p><p>Thank you for reading this blog<br>Special credits to the youtube channel Tsoding Daily for explaining this so clearly.<br>Here’s the github repository for the code:<br><a href="https://github.com/ASHUTOSH-06-SONI/Neural_Nets">https://github.com/ASHUTOSH-06-SONI/Neural_Nets</a></p><p>Sayonara</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4866171206f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>