<?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 Jean Salvi on Medium]]></title>
        <description><![CDATA[Stories by Jean Salvi on Medium]]></description>
        <link>https://medium.com/@salviosage?source=rss-f3228db40710------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DQK-d4FPRMhzqA1yQgXXBA.jpeg</url>
            <title>Stories by Jean Salvi on Medium</title>
            <link>https://medium.com/@salviosage?source=rss-f3228db40710------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:24:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@salviosage/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[Build mini TensorFlow-like library from scratch.]]></title>
            <link>https://salviosage.medium.com/build-mini-tensorflow-like-library-from-scratch-fc28c9660037?source=rss-f3228db40710------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc28c9660037</guid>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[breast-cancer-detection]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Jean Salvi]]></dc:creator>
            <pubDate>Wed, 27 Oct 2021 11:37:33 GMT</pubDate>
            <atom:updated>2021-10-31T21:06:44.331Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are really curious about the state of the art of machine learning, then you know the guts of crashing down a computationally hard problem from scratch. and, You might have noticed what libraries like Tensorflow, Pytorch, or Keras are capable of.</p><p>In this blog post, I will try to break down some fundamentals of <a href="https://g.co/kgs/fjxjs">differentiable graphs</a> which is a building block of the Tensorflow library. we will build a small library to train and test an artificial deep neural network from scratch.</p><p>Since we are generally dealing with Artificial neural networks here, I assume it’s not your first time hearing about it. If I am wrong then, worry not. I wrote something for you back then <a href="https://medium.com/@salviosage/when-i-use-a-word-artificial-intelligence-a245bbc6ff05">when-i-use-a-word-artificial-intelligence</a>. But basically, ANNs mimic the process of how our (human ) brains operate, and it&#39;s a biologically inspired computational network. sounds pretty scary right?</p><p>Computational wise you might have to think of it as a graph of mathematical functions such as linear combination and activation functions. The graph consists of <strong>nodes</strong>, and <strong>edges</strong>. Just like this image down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GsisaGGtOSSEftAc.png" /></figure><p><strong>Nodes</strong> in each layer perform mathematical functions using inputs from nodes in the previous layers or <strong>input predictors</strong> (for nodes in the input layer). For example, a node could represent simple linear function <strong><em>f(x,y)=x+y+b</em></strong>, where <strong><em>x</em></strong> and <strong><em>y</em></strong> are input values from nodes in the previous layer or simply inputs(for nodes in the input layer), and<strong> b</strong> is a bias unit.</p><p>Each node creates an output value that may be passed to nodes in the next layer or if the node is in the output layer then it produces a <strong>target variable</strong>. The Layers between the input layer and the output layer are called <strong>hidden layers</strong>.</p><p>The <strong>edges </strong>in the graph connect the nodes where the values flow from one layer to the other. These edges can also apply operations to the values that flow with them, such as multiplying by weights and adding biases.</p><p>Considering how we can implement graph structure in our mini Tensorflow_like library, We’ll use a Python class to represent a generic node. each node might receive input from multiple other nodes (inbound_nodes). each node also creates a single output, which will likely be passed to other nodes (outbound_nodes).</p><p>by adding two lists (one to store references to the inbound nodes, and the other to store references to the outbound nodes), each node will eventually calculate a value that represents its output. the code snippet below shows the implementation in python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6e4be6a357c598be1da4847b7d3478e/href">https://medium.com/media/e6e4be6a357c598be1da4847b7d3478e/href</a></iframe><p>Unlike other hidden layers nodes, the Input nodes subclass doesn’t have inbound nodes as they are the frontier of our neural network .they do not actually calculate anything. They hold a <strong>value</strong>, such as a <strong>data feature </strong>or a model parameter (<strong>weight/bias</strong>). value can be set either explicitly or with the <strong>forward()</strong> method, and This value is then fed through the rest of the neural network during <strong>Forward propagation</strong>.</p><p>below is the implementation of the input node.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c130b78ab39dbee7561393c1a6ce03c/href">https://medium.com/media/1c130b78ab39dbee7561393c1a6ce03c/href</a></iframe><h4>Forward Propagation</h4><p>By propagating values from the first layer (the input layer) through all the mathematical functions represented by each node(the nodes of the hidden layer), the network outputs a value. This process is called a <strong>forward pass</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/0*UNjW2bm6ZG0h0k9C" /><figcaption>Image Adapted from<a href="https://ujjwalkarn.me/2016/08/09/quick-intro-neural-networks/"> ujjwalkarn.me</a></figcaption></figure><p>The picture above shows just a simple perceptron with two inputs and a bias unit to produce the output after performing a mathematical function, with no hidden layers.</p><p>Let’s implement a forward pass with two methods to help us define and then run values through our graphs, we will Implement the <strong>topological_sort</strong> method and f<strong>orward_pass</strong>. Given the fact that the input to some nodes depends on the outputs of others, we need to flatten the graph in a way where all the input dependencies for each node are resolved before running its calculation. we will use <a href="https://en.wikipedia.org/wiki/Topological_sorting">topological sort</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*51CeXmirz9kqXqbl.jpeg" /><figcaption>Topological sort Image adapted from <a href="https://classroom.udacity.com/nanodegrees/nd101/">Udacity</a></figcaption></figure><p>it is just a <a href="https://en.wikipedia.org/wiki/Depth-first_search"><strong>Depth-first search</strong></a> algorithm where we take one node and expand to its end roots before continuing to the next one. It only works with <a href="https://en.wikipedia.org/wiki/Directed_acyclic_graph"><strong>Directed_acyclic_graphs</strong></a>. the animation below explains a depth-first search algorithm in details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*23Y1RGRA6Sa6JabE.gif" /><figcaption>Image adapted from <a href="https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm">Wikipedia.org</a></figcaption></figure><p>The topological sort function will return a sorted list of nodes in which all of the calculations can run in series. takes in a <strong>feed_dict</strong>, which is a dictionary data structure where we initially set a value for an <strong>input_node</strong>. Here&#39;s the code implementation</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c6a4879bf42875b513ff4c2c82ddf46/href">https://medium.com/media/3c6a4879bf42875b513ff4c2c82ddf46/href</a></iframe><p>We have to have a way to run the network and output the value, The method <em>forward_pass()</em> down here will perform that for us.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae2ed1e63a58f65896660557f4f34a8b/href">https://medium.com/media/ae2ed1e63a58f65896660557f4f34a8b/href</a></iframe><h3><strong>Time for big hows!</strong></h3><p>How do we turn our neural network into a learning machine(human-like) then?</p><p><strong>The first step lets make our neurons (nodes ) linear</strong></p><blockquote><em>As I stated back on top, you should think of ANN as</em> <em>“a graph of mathematical functions such as linear combination and activation functions. The graph consists of nodes, and edges”</em>.<strong> <em>now think of node as a neuron or linear function with an activation function wich is addition operator in the image down here. and think of edge as simply three main components of linear fumction (weights </em></strong>wi<strong><em>, inputs </em></strong>xi, <strong>and bias</strong> b) . so our neuron is just the weighted sum of the inputs plus the bias for now.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*6Qe4W6TmTi94bpvb.png" /><figcaption>Linear Function Image adapted from <a href="https://udacity.com/">udacity.com</a></figcaption></figure><p>Under this linear node(neuron ) our network is finally becoming a clear thinker(smart is overrated). here is an implementation of a simple linear node.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1198638806e0dac2d93b09b36a124caa/href">https://medium.com/media/1198638806e0dac2d93b09b36a124caa/href</a></iframe><p>Our network for sure has to be capable of receiving multiple inputs and having multiple layers. so we have to do the <a href="https://www.khanacademy.org/math/linear-algebra/matrix-transformations/linear-transformations/v/vector-transformations">transformation</a> for us to implement what layers should do( transforming values between layers in a graph). using <a href="https://www.khanacademy.org/math/linear-algebra">Linear algebra</a> matrix transformation we can convert inputs to outputs in many dimensions.</p><p>Let’s go back to our equation for the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/0*ZicC9vswL7L35uvr.png" /><figcaption>Image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>The equation above shows the summation of <strong><em>X</em></strong> (a <strong>1</strong> by <strong>n</strong> matrix of inputs ) and <strong><em>W</em></strong> (an <strong>n</strong> by <strong>k</strong> matrix of weights) and <strong>B</strong> (a <strong>1</strong> by <strong>k</strong> matrix of bias units).</p><p>So here we are simply mapping <strong>n</strong> inputs to <strong>k</strong> outputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/0*9rDVqFFHBEnzHQLl.png" /><figcaption>Inputs vector image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/0*WIpkZoSZRHmwwTMt.gif" /><figcaption>Weights Matrix image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/0*Th9e93UNOQOqFXjJ.png" /><figcaption>Bias units vector image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>Basically consider a 28px by 28px greyscale image, as is in the case of images in the <a href="http://yann.lecun.com/exdb/mnist/">MNIST dataset</a>. We can reshape the image such that it’s a 1 by 784 matrix, n = 784. Each pixel is an input/feature.</p><h4><strong>Batch size </strong>(not a batch of Meth from breaking bad )</h4><p>It’s commonly good practice to feed in multiple data inputs in each forward pass rather than just 1, just to process in parallel, resulting in big performance gains. The number of data inputs is called the <strong><em>batch size</em></strong>. Common numbers for the batch size are 32, 64, 128, 256, 512. Generally, it’s the most memory can comfortably manage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*MyqJFEGTbXj3G_AE.png" /><figcaption>Inputs vector image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p><em>So it basically means </em><strong><em>X </em></strong>becomes an <strong>m</strong> by <strong>n</strong> matrix and <strong><em>W</em></strong> and <strong><em>B</em></strong> remain the same. The result of the matrix multiplication should be <strong>m</strong> by <strong>k </strong>then.</p><p>In the context of our MNIST, each row of <em>X</em> is an image reshaped from 28 by 28 to 1 by 784. so <strong>X </strong>becomes <strong>bach_size</strong> by <strong>784</strong> matrix.</p><p>Too many scary math symbols right? Here is a rescue 😊</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77e69b0d47594d4a121afbc0caecf744/href">https://medium.com/media/77e69b0d47594d4a121afbc0caecf744/href</a></iframe><p>We just used NumPy np.dot to handle the matrix multiplication, not really scary.</p><p>Now we have implemented linear transforms, <strong>let’s face forward</strong>.</p><h3><strong>Activation function</strong></h3><p>Normally neural networks require a more nuanced transform than the one we have now. For instance, Let&#39;s take a binary classification problem example. let&#39;s say we want to build a face recognition system, whether the output will be true or false let’s assume. Perceptrons(neurons or nodes ) compare a weighted input to a threshold. When the weighted input exceeds the threshold, the perceptron is <strong>activated</strong> and outputs 1, otherwise, it outputs 0, and it is a binary step function.</p><p>The binary step function is great for binary output. But, we want our neural network to be able to learn from its error. This can not be possible given the fact that activation functions should be continuous and differentiable to be able to do gradient descent, and the step function is not. down here are other most popular alternative activation functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e0tYZLaSc5KXv53g.png" /><figcaption>Activation functions Example Image adapted from <a href="https://medium.com/@shrutijadon10104776/survey-on-activation-functions-for-deep-learning-9689331ba092">medium.com</a></figcaption></figure><blockquote>Keep in mind that in older to apply <a href="https://en.wikipedia.org/wiki/Gradient_descent#:~:text=Gradient%20descent%20is%20a%20first,the%20direction%20of%20steepest%20descent.">gradient descent </a>(reducing network error ), error function should be differentiable and continous.</blockquote><h3>Sigmoid Function</h3><p>The sigmoid function is among the most common activation functions. as you see in the image above it is between 0 and 1, which makes sense for probabilistic models given the fact that probability exists between 0 and 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*lerK_Hr-yjs2OEq1.png" /><figcaption>sigmoid function image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>It simply mimics the activation behavior of a step function while being differentiable. It also has a very simple derivative that that can be calculated from the sigmoid function itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*Q_f0LEJ_r3fFrVv3.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/0*KliwfV_N7empGiT-.png" /><figcaption>derivative of sigmoid function image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>Conceptually, the sigmoid function makes decisions. When given weighted features from some data, it indicates whether or not the features contribute to classification. In that way, a sigmoid activation works well following a linear transformation. As it stands right now with random weights and bias, the sigmoid node’s output is also random. The process of learning through backpropagation and gradient descent modifies the weights and bias such that activation of the sigmoid node begins to match expected outputs.</p><p>too many scary math symbols right? here is your rescue</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/792f080881dc5108b6887b3d8e183235/href">https://medium.com/media/792f080881dc5108b6887b3d8e183235/href</a></iframe><p>Yeah like that our network now is continuous and differentiable.</p><p>Eventually, We will have to figure out how to measure our network accuracy. Let&#39;s say for example in the picture below that our neural network is trying to separate red dots from blue ones. given the fact that there are misclassified points there, thus we can measure how far we are to better classify every point right by calculating the summation Errors we made against each and every point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*Z5PLQoTMgEd_6IGUb7sjlQ.png" /><figcaption>Log Loss error image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>You might have noticed that the bigger the point the bigger the error(misclassification) in the image above. this perfectly mimics the perceptron trick whereby each and every point will have to communicate what is best for it to be classified well. Let’s break down some ways our points communicate to an entire network what they want, and it&#39;s a matter of the network to take actions that maximize the profit of each and every point on average.</p><h4><strong>Error Functions</strong></h4><p>There are a couple of techniques for defining the accuracy of a neural network. Some call then <strong>loss</strong> or <strong>cost</strong>.</p><p>There are many Types of <a href="https://en.wikipedia.org/wiki/Loss_function">Error Functions</a> but in our case, we will use <a href="https://en.wikipedia.org/wiki/Mean_squared_error"><strong>mean square error</strong></a><strong>.</strong> The image below shows some maths of our error function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HPZFMtEb06Jepn7B9ScNcQ.png" /><figcaption>Sum of squared error image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>As you might have noticed, the above error function is the mean of the squares of the differences between the predictions and the labels. which will help us to measure our model accuracy.</p><blockquote>we square the error becouse it helps penalize outliers more than small errors, and it also makes the maths simple later since we don’t want negative values if we happen to have positive errors.</blockquote><p>It is obvious the error is the function of the weights, and we will be using them to tune our network to make good predictions.</p><p>here is the code implementation!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a535e3f679fb967a6957526c1dd27f38/href">https://medium.com/media/a535e3f679fb967a6957526c1dd27f38/href</a></iframe><p>Note the order of y and a doesn&#39;t actually matter, we could switch them around (a - y) and get the same value after being squared.</p><p>after getting errors of course we will have to find a way to decrease our errors for the network to better predict values.</p><h3><strong>Gradient Descent</strong></h3><p>Our goal is to make our network output as close as possible to the target values by minimizing the cost or its error. You can envision the cost or error as a mountain and we want descent to the bottom.</p><p>Since we know how wrong the predictions are, Now it’s time to descent from the error mountain. We need to update our weight to make predictions as close as possible to the real values. and the process is called <strong>Gradient Descent</strong>.</p><p>Our goal is to calculate the gradient of Error(E), at a point x = (x1,…, xn), given by the partial derivatives. We will simply calculate the derivative of the error that each point produces. We have seen the formula of the sum of the Error function in the above sections in case you need to revise.</p><p>In order to calculate the derivative of this error with respect to the weights, we’ll first calculate The predictions derivative with respect to weighs. below is the formula.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*P4hndWmhWazJXOG8.gif" /><figcaption>image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>And now we can calculate the derivative of the error E at a point x.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Ny6Jit4LDXG6jzWXfOVAg.png" /><figcaption>image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>to summarize this, the formula actually tells us that the Gradient of E with respect to point X is <strong>∇<em>E</em>=−(<em>y</em>−<em>y</em>^​)(<em>x</em>1,…,<em>xn</em>,1).</strong></p><p>The gradient is the difference between the label and the prediction, times the coordinates of the point!</p><blockquote>This means the closer the label to the prediction the smaller the gradiemt, Vise versa.</blockquote><p>Since the gradient is a vector of numbers. Each number represents the amount by which we should adjust a corresponding weight or bias in the neural network. Adjusting all of the weights and biases by the gradient values reduces the cost (or error) of the network.</p><p><strong>Now let’s take a walk to the bottom of the Error mountain.</strong></p><p>Here the confusing part is how do we know which way is downhill. Well, the good news is, our gradient descent provides this exact information. it gives us the direction of the <strong>steepest descent</strong>, which is what we want.</p><p><strong>Gradient Descent Step</strong></p><p>Now we know the direction. The next thing to consider is how fast. or how long is our one step to the given direction? This is known as the <strong><em>learning rate,</em></strong> which is a value that determines how quickly or slowly the neural network learns.</p><p>You&#39;re probably thinking of big learning late, to make networks learn fast. But, Be careful! If the value is too large we could overshoot the target and eventually diverge from it. Yikes!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*r6SVgyV5ivZ0y_IJ.gif" /><figcaption><strong>Convergence </strong>image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p><strong>Convergence</strong>. This is the ideal behavior.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*QBxtvZkrttNUjcvJ.gif" /><figcaption><strong>Divergence </strong>image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p><strong>Divergence</strong>. This can happen when the learning rate is too large.</p><p><strong>So what is a good learning rate, then?</strong></p><blockquote>This is more of a guessing game than anything else but empirically values in the range 0.1 to 0.0001 work well. The range 0.001 to 0.0001 is popular, as 0.1 and 0.01 are sometimes too large.</blockquote><p>so basically gradient descent formula is <strong>x = x - learning_rate * gradient_of_x</strong></p><p>Here’s the formula :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*zoBopc_gLynDN7UYjsRv-Q.png" /><figcaption>image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p><strong>x</strong> is a parameter used by the neural network (i.e. a single weight or bias) and <strong>n</strong> is a learning rate.</p><p>awesome let&#39;s apply this in codes :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a22344ed3fc3835aeb53bf321c44fd94/href">https://medium.com/media/a22344ed3fc3835aeb53bf321c44fd94/href</a></iframe><blockquote>“you can’t connect the dots looking forward, you can only connect them looking <strong>backward</strong>”</blockquote><blockquote><strong><em>Steve Job</em></strong>.</blockquote><h4><strong>Backward Propagation</strong></h4><p>Wonder how will our network learn then. well by varying the weights, our NN can vary the amount of influence any given input has on the output now. It can also modify the weights and biases to improve the network’s output accuracy. and that’s <strong>backpropagation</strong>.</p><p>for us to do backpropagation we need a proper way to measure our network accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/0*TzrppffX3weufNbX.gif" /><figcaption>Image adapted from <a href="https://disavanta.blogspot.com/2020/12/linear-regression-gif.html">disavanta.blogspot.com</a></figcaption></figure><p>As you can see in this animation above after backpropagation our network adjusts in a way that produces accurate output than before.</p><p><strong>Working through an example</strong></p><p>Let’s walk through the steps of calculating the weight updates for a simple two-layer network. Suppose there are two input values, one hidden unit, and one output unit, with sigmoid activations on the hidden and output units. The following image depicts this network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/197/0*QDIej9KSR_W1S8le.png" /><figcaption>image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>Assume our target value y=1. We’ll start with the forward pass, first calculating the input to the hidden unit which is</p><p><strong>h=∑i wi xi = 0.1×0.4−0.2×0.3=−0.02.</strong></p><p>and the output of the hidden unit by simply applying the sigmoid function.</p><p>a<strong>=f(h)=sigmoid(−0.02)=0.495.</strong></p><p>Using this as the input to the output unit, the output of the network is</p><p><strong><em>y</em>^​=<em>f</em>(<em>W</em>⋅<em>a</em>)=sigmoid(0.1×0.495)=0.512.</strong></p><p>With the network output, we can start the backward pass to calculate the weight updates for both layers. remember our sigmoid nice derivative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/0*KliwfV_N7empGiT-.png" /><figcaption>derivative of sigmoid function image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>the error term for the output unit is</p><p><strong><em>δo</em>=(<em>y</em>−<em>y</em>^​)<em>f</em>′(<em>W</em>⋅<em>a</em>)=(1−0.512)×0.512×(1−0.512)=0.122</strong></p><p>and error term for our hidden is</p><p><strong><em>δh</em>=<em>Wδof</em>′(<em>h</em>)=0.1×0.122×0.495×(1−0.495)=0.003</strong></p><p>Now that we can calculate errors with respect to a given point, we can calculate the gradient descent steps. The hidden to output weight step is the learning rate, times the output unit error, times the hidden unit activation value. remember this formula we used on top</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*zoBopc_gLynDN7UYjsRv-Q.png" /><figcaption>image adapted from <a href="https://www.udacity.com/">udacity.com</a></figcaption></figure><p>so the gradient descent step calculation is as simple as this.</p><p><strong>Δ<em>W</em>=<em>ηδoa</em>=0.5×0.122×0.495=0.0302</strong></p><p>and the gradient descent step for the input node</p><p><strong>Δ<em>wi</em>​=<em>ηδhxi</em>​=(0.5×0.003×0.1,0.5×0.003×0.3)=(0.00015,0.00045)</strong></p><p>so like this we backpropagate through the network and update the weight :</p><p>here is the complete code implementation so far</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed2827aecc3b4704b2538caaf933b958/href">https://medium.com/media/ed2827aecc3b4704b2538caaf933b958/href</a></iframe><p>Now Our network has the capability to learn and make smart decisions for itself. It’s that time to investigate ourselves haha. Let&#39;s try to diagnose breast cancer from online datasets.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/095a0e745dde6f8c83129b1269394a96/href">https://medium.com/media/095a0e745dde6f8c83129b1269394a96/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*mAUIzNFCdg8aTXlkzH2VEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*qUpoYSGRhQECe4mawPJDtQ.png" /></figure><p>as you can see our learning loss has diminished from 4.567 up to 0.069 on the 100th epoch.</p><p>Yay! our network is able to learn and become wise. Let’s test it in the image dataset.</p><figure><img alt="Image adapted from becomminghuman.ai by Venkatesh tata" src="https://cdn-images-1.medium.com/max/1024/0*vcmoLEVoMjCgFAMG.gif" /><figcaption>Image adapted from becominghuman.ai</figcaption></figure><p>Lets&#39;s use our algorithm to visually diagnose <a href="http://www.skincancer.org/skin-cancer-information/melanoma">melanoma</a>, the deadliest form of skin cancer.</p><p>To be continued….</p><h3><strong>Recommended Improvements</strong></h3><p><a href="https://arxiv.org/abs/1811.08150">Local minima, Breakpoint</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc28c9660037" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When I use a word ….. Artificial intelligence]]></title>
            <link>https://salviosage.medium.com/when-i-use-a-word-artificial-intelligence-a245bbc6ff05?source=rss-f3228db40710------2</link>
            <guid isPermaLink="false">https://medium.com/p/a245bbc6ff05</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-intelligence]]></category>
            <dc:creator><![CDATA[Jean Salvi]]></dc:creator>
            <pubDate>Fri, 11 Sep 2020 18:21:20 GMT</pubDate>
            <atom:updated>2020-09-14T18:48:15.898Z</atom:updated>
            <content:encoded><![CDATA[<h3>When I use a word Artificial intelligence</h3><p>if you happen to read about new technologies , you are most likely to hear words <strong>Artifical intelligence</strong> more often than any other words. AI itself is probably the most oustanding creation of human kind which is largely unexplored and growing exponentially if i can say.</p><p>AI is about unleashing one of the most amazing thing in the universe , I<strong>ntelligence</strong>. the technology that can learn much faster than us, solve computationaly hard problem human like me or you can’t solve with same speed and accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VHPdPAKmajebjLhI" /><figcaption>Photo by <a href="https://unsplash.com/@photoshobby?utm_source=medium&amp;utm_medium=referral">Photos Hobby</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>What is AI anyway ?</strong></p><p>If you think about AI, in a context of machine or technology you think about intelligent machine or intelligent softwares. let’s focus on the word <strong>intelligence.</strong></p><p>We often tend to use word intelligence to describe things we don’t know how to explain or how it literaly works, if we can explain them we just say they are algorithm or formulas designed for a specific task . It’s only intelligence if we can’t explain then. This definition implies that anything we design is not intelligent because we would know how it works.</p><p>Like us human being we consider ourselves as intelligent because we don’t realy understand well how our brains works. Once we understand that we will not consider ourselves as intelligent anymore . or imagine yourself studying mathematics for the first time, you might wonder how your teacher can solve those simple mathematics problems , but when you grow up you realise that it was simple and you might not consider your primary math teacher as intelligent person if you are asked.</p><p>But that’s not how we should define intelligence, for AI to be productive the concept of intelligence should be defined in a concept of task , for example if my goal is to plan flights with a lowest possible cost and my system is able to do it with a decent of success, i consider my system as intelligence at flight planning . it just turns out that human are intelligent in doing a lot of different things .Intelligent systems tends apply concept and techniques like search, probabilistic planning and logic to achieve a certain goal.</p><p>to design an intelligence system one must understand the task or <strong>problem domain</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*fiQT0h55hHSJJuWXx5GJPA.png" /><figcaption>intelligent agent and its environment</figcaption></figure><p>We refer to a system or AI program as the Agent, and the surroundings or anything that can influence or have an impact on our system’s behaviour the environment. You may only consider the software as the agent and the other hardware components would be external to the agent and that’s part of the environment. or you might consider whole system as the agent, it realy depend on context.</p><p>lets take an example of the agent and its environment. for example like a self driving car , we might consider a car as an agent and the surroundings as environment ,whether its something near our agent, agent position in the road, road width, distance from traffic light or may be our vehicle current speed. those are some properties that define our agent environment states.</p><blockquote>An agent interact with the environment by sensing its properties and its known as <strong>perception.</strong></blockquote><p>we need state of the environment on every stage to be able to examine our agent, define the next move towards our goal state.</p><blockquote>The process of which the agent decide what action to take based on perceived input is known as <strong>cognition.</strong></blockquote><p>as you can guess much of discussion about AI focus on cognition (reasoning and decision making ) just human like behaviours. like on self driving car example the agent can perceive the traffic light state and decide whether to stop or keep going.</p><p>Some agent directly associate their action with what is perceived or have very simple pre programed behaviours like an automated light that sense something and turn on the light automatically these are referred to as <strong>reactive or behaviour based agents.</strong></p><p>On the other side some agent delibarate in the forms of non trivial processes such as game playing agent or flight planner . we can classify this agent depending on process they do like planning agents …, just keep in mind that it’s simple to accomplish complicated behaviour by layering simple reactive control.</p><h3><strong>Types of Learning in Artificial Intelligence</strong></h3><p>When someone asks you to describe different types of artificial intelligence systems, you might classify them based on their functionality or its evolvement .</p><p>Lets start from evolvement, there are three steps AI can deevelop or be evolved .</p><ul><li>Artificial Narrow Intelligence</li><li>Artificial General Intelligence</li><li>Artificial super intelligence</li></ul><p><strong>Artificial Narrow Intelligence</strong>: is a stage of AI which involves machine that can only perform predefined tasks, simple machine has no thinking capability at this stage. most of the current AI systems far into this stage i guess.</p><p><strong>Artificial General Intelligence: </strong>At this stage<strong> </strong>machines have the ability to think and make decisions just like humans do, and we are not far off this stage currently.</p><p><strong>Artificial super intelligence:</strong> at this stage the machine have the ability to outperform humans. we are kind of far off this stage but people described it in some movies,where machine have taken over the world. and we are better off this i think.</p><h4><strong>Based on the functionality of AI systems</strong>, AI can be classified into the following types:</h4><ul><li>Reactive machines AI</li><li>Limited memory AI</li><li>Theory of Mind AI</li><li>Self-aware AI</li></ul><p><strong>Reactive machines AI: </strong>The most basic types of AI systems have the ability neither to form memories nor to use past experiences to inform current decisions, its purely reactive . for example like a chess playing agent which observe oponent moves and its position to decide next best move.</p><p><strong>Limited memory AI : </strong>AI can make informed and better decisions by looking into the past data from its memory. for example self driving cars can look into past decisions and their effect to decide which action to take in a certain scenario.</p><p><strong>Theory of Mind AI: </strong>This kind of AI mainly focuses on emotional intelligence, this tipe of AI is not only the form representations about the world, but also about other agents or entities in the world.</p><p><strong>Self-aware AI: </strong>This kind of AI is a bit far in view of current systems . However, in the future, it is possible to to build the systems that can form representations about themselves. yes, a machine that have consciousness.</p><p>To classify AI problems is using properties of the environments and components of the state that needs to be captured.</p><blockquote>An environment can be <strong>fully observable</strong> when your agent can see the entire environment or <strong>partially observable</strong> like in serf driving car where you cant see the entire environment</blockquote><p>like palying chess game task where the agent can see the entire board, its fully observable.</p><blockquote>It can be <strong>deterministic</strong> where an agent know for sure the result of each action it take or <strong>stochastic</strong> where an agent is not sure of the result of ist actions .</blockquote><p>for example<strong> </strong>Recognizing Handwritten Text task , the environment is stochastic becouse there are uncertainity about the result becouse there are number of possible solutions.</p><blockquote>An environment can be <strong>discret </strong>where there is a finite number of actions you can take or <strong>continuous </strong>where the number of possible state is infinite .</blockquote><p>like Playing Poker task , it is discret becouse there<strong> </strong>are finite number of actions an agent can take.</p><blockquote>It can be <strong>benign</strong> where the agent t is the only one taking actions that intentionally affect its goal . or it could be <strong>adversarial</strong> where there are one or more agents that takes actions to defaeat its goal.</blockquote><p>for example like playing chess task , it is adverserial becouse the agent is playing against another oponent who is taking actions to defeat the agent.</p><p><strong><em>In all this, what’s AI?</em></strong></p><p><strong>An intelligence system </strong>is the one that takes action to maximize its chance to achieve the desired goal , that means it requires agent to behave optimally however it is hard to find optimal solution given the constraight the agent might face like for example a partialy observable environment , limited computational resources such as memories and processing speed .</p><p>intelligent Agent should not be expected to behave optimally but for the sake of quantifying our agent intelligence, we can come up with a level of performance or bound that we desire our agent to meet or exceed. for example we might want our flight planning agent to minimize the cost 30% or so . This known as bounded optimality .</p><p><strong>to me AI is a branch of computer science concerned with building intelligent machine that perform intelligent tasks.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a245bbc6ff05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep learning]]></title>
            <link>https://medium.com/series/deep-learning-4ee001859d5d?source=rss-f3228db40710------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ee001859d5d</guid>
            <dc:creator><![CDATA[Jean Salvi]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 06:30:21 GMT</pubDate>
            <atom:updated>2020-07-05T06:30:21.675Z</atom:updated>
            <content:encoded><![CDATA[<p>Data structure and algorithm</p><p>Artificial intelligence</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ee001859d5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>