<?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 Mohammed Amarnah on Medium]]></title>
        <description><![CDATA[Stories by Mohammed Amarnah on Medium]]></description>
        <link>https://medium.com/@m-amarnah?source=rss-8c18102a4b80------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3OTd7kcZCIOUQS78b9thyQ.jpeg</url>
            <title>Stories by Mohammed Amarnah on Medium</title>
            <link>https://medium.com/@m-amarnah?source=rss-8c18102a4b80------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 19:02:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@m-amarnah/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[Functional Programming]]></title>
            <link>https://m-amarnah.medium.com/functional-programming-69631b53f529?source=rss-8c18102a4b80------2</link>
            <guid isPermaLink="false">https://medium.com/p/69631b53f529</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[functional]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[clojure]]></category>
            <dc:creator><![CDATA[Mohammed Amarnah]]></dc:creator>
            <pubDate>Sat, 02 Jan 2021 23:19:48 GMT</pubDate>
            <atom:updated>2021-01-02T23:49:05.187Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NR8BxdBcNMaEtdUcl_pz4g.png" /></figure><p>So you have decided to learn functional programming, great! You visit the first website, read a book, watch a video, and maybe listen to a podcast; when suddenly you realize that functional programming is a completely different kind of programming. That it is a fundamental change in the way you see and interact with computer programs. And maybe it’ll even require you to almost forget about everything related to computer programs!</p><p>But what do we know, as programmers, so that we forget? I’ll assume that you’re coming from an object-oriented background, and if so, we can summarize the basic components of almost any program -that is, on a higher level- in the following pyramid:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kiI0XB9cfsqs8DluuKdvWg.png" /></figure><p>So instead of forgetting about everything we know, how about we rebuild our idea on programming and what it means, and how it is constructed.</p><h3>Three Elementary Structures</h3><p>In 1966 a paper by <a href="https://en.wikipedia.org/wiki/Corrado_B%C3%B6hm">Corrado Böhm</a> and <a href="https://en.wikipedia.org/w/index.php?title=Giuseppe_Jacopini&amp;action=edit&amp;redlink=1">Giuseppe Jacopini</a>, 2 great computer scientists, introduced the <a href="https://dl.acm.org/doi/10.1145/355592.365646#CIT"><em>Böhm–Jacopini theorem</em></a><em> </em>[1] or the structured programming theorem. This theorem states that all programs can be constructed from just three structures: sequence, selection, and iteration.</p><p>So based on that, we definitely will have to have these three elementary structures in any functional program. Of course, we’ll also have data types; strings, integers, and booleans are all fundamental in the way we develop programs. Add to this the more advanced data structures like arrays, trees, hashes, and so on.</p><p>Turns out the only level of the programming pyramid that we need to rebuild, are the ideas that were brought by the Object-Oriented Programming paradigm. We need to find a more “functional” approach to doing programming.</p><h3>Mathematics and Abstractions</h3><p>One of the best places to go to when you want to look for a new paradigm of programming is Mathematicians! Mathematics and Computer Science share the same characteristics in problem-solving techniques, formulating and modeling problems, and a lot more. But most importantly: <strong><em>Abstractions</em></strong>.</p><p>You might remember that moment when you were trying to build this complex system, and you’re having this abstraction of the system as a model, and then this other abstraction and the other and so on, all that combined together make up this functional goal of the system. Mathematicians share the same problem as us! They’re also trying to keep in their mind an abstraction over the other to derive this “functional” goal of a mathematical model. So, what did mathematicians use that we might find useful? <strong>Functions</strong>.</p><h3>Mathematical Functions</h3><p>If you are a programmer you have probably heard of functions (maybe methods, routines, etc.), but mathematical functions are not the same.</p><p>In mathematics, a <a href="https://mathinsight.org/definition/function">function</a> is a relation from a set of inputs to a set of possible outputs <strong><em>where each input is related to exactly one output</em></strong> [2]<strong>.</strong> We can view a function as a machine that can take an object and turn it into <strong><em>(or map it to)</em></strong> a different object, this is called the <a href="https://mathinsight.org/function_machine">function machine metaphor</a> [3].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*1tSdLOQB7uFwpFliqBjKxg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*3tQ0_u3jBpoA2gbgeD86qA.png" /></figure><p>Mathematical functions are different than programming methods/routines because of a very important thing and that is the mechanism of how they work. A simple ruby method can do a lot of things including updating the database, creating new files, sending emails. A mathematical function on the other side does only one thing and one thing only. Every input is mapped into the exact same output each time that function is called. So it’s not like f(x) is gonna be 24 today, and then 3 days later it’s 77.</p><p>So what if we borrow these ideas from mathematics and apply it to programming, in hope that our functions (programs) are easier to read and write? There are a couple of rules and conditions that we have to follow in order for our functions to be “pure”.</p><h3>Rule #1: Functions as values</h3><p>A fundamental rule is that those mathematical functions are considered to be “values”. This is what we call a <a href="https://lispcast.com/what-are-first-class-functions/"><strong><em>1st class function</em></strong></a> [4], and they’re actually in many programming languages (that are not even purely functional). If you look for example on this ruby code:</p><pre>fn = lambda { |x| x + 2 }</pre><pre>puts fn.(2) # = 4</pre><p>As you can see, we defined a variable fn that holds a function that takes an input x and returns x + 2. Nowadays, if you look over the documentation of almost all programming languages, you&#39;ll find the idea of pure functions developed and utilized. A function is a value that can be defined and passed as an argument and manipulated just like other variables.</p><pre># A function `add` that takes a function `fn`<br># and a number `a` as parameters, applies <br># `fn` to `a` and adds the result of <br># `fn(a)` to `a` again.<br>def add(fn, a)<br>	fn.(a) + a<br>end</pre><pre>fn = lambda { |x| x + 2 }<br>result = add(fn, 2)</pre><pre>puts result # = 2 + 2 + 2 = 6</pre><h3>Rule #2: No Side Effects</h3><p>The second most important rule for our functions to behave purely is to behave exactly like mathematical functions do: Take an input, produce an output. That is, without any side effects.</p><p>But, what are side effects?</p><pre># A side effect<br>File.open(&quot;log.txt&quot;, &quot;w&quot;) { |f| f.write &quot;#{Time.now} - User logged in\\n&quot; }</pre><p>Side effects are basically the change of the “outer” state of the function. A change that is outside the scope of the function’s inputs and outputs. Anything that deals with IO, or any external resource is considered to be a side effect. But what are our programs other than side effects?</p><p>We need this bridge that connects our pure functions with the actual events and side effects that we want to do. The solution to this problem has been implemented differently in different programming languages, and we’ll take a Clojure look at that.</p><p>There’s also a huge discussion nowadays on reactive functional programming (bonus: <a href="https://elm-lang.org/">Elm</a> [5] is a compellingly beautiful example of that), where they deal with a lot of state change and UI elements in a functional way.</p><h3>A Bridge to Side Effects</h3><h3>Atoms</h3><p>An example on this bridge that the programming language <a href="https://clojure.org/">Clojure</a> has taken is what they call an Atom. An atom is the closest thing that someone can find to a mutable state. It is Clojure&#39;s way of bridging the clean organized functional approach with the messy world of side effects.</p><p>Here’s how we define an atom in Clojure:</p><pre>(def x (atom 0))</pre><p>And then to change the value of this atom, you just throw it into a function that applies the function to that atom and returns the value of the function as the new value of the atom. For example, here’s how you can increment an atom:</p><pre>(swap! x inc)</pre><p>What this does is that it takes x and applies inc(x) and swaps the current value of x with the returned value of the applied function.</p><p>Now the beautiful thing happens when two threads are trying to update x at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*Qh3dOPvOaYeOghveG028cQ.png" /></figure><p>Here, inc(x) and dec(x) both come at the same time, and they see the current value of the atom X. What happens is that this atom runs the function and <strong>notices</strong> that the value of X has changed and what happens? It runs the function that came last <strong>again.</strong></p><h3>Agents and Actors</h3><p>Okay, what if I want to update a file or a database or something that is completely outside the scope of the program I’m dealing with? Here come Clojure’s agents.</p><p>In that, you basically send these side-effects into a queue specified for doing these tasks, and all of them run synchronously. The topic of agents is huge and shall be discussed in a separate article.</p><h3>Rule #3: Immutability</h3><p>Based on the previously mentioned rule #2, our functions should behave purely and with no side-effects. But what if our variables are mutable? That is, its state can change. You find yourself back at the problem of side-effects! So to ensure that side-effects are completely demolished we need one more important rule: Variable Immutability.</p><pre>x = [1, 2, 3]<br>y = f(x)<br># what is that value of x at this point? x!</pre><p>Notice that even if you make y = f(g(h(...(x))) , the value of x is still going to be the same. Nothing is changed! f(x) takes a copy of x and returns a result based on this copy. You don&#39;t have to figure out why x&#39;s value is being weird when it is clearly defined in front of your eyes.</p><p>But a problem arises here. y = f(x) + g(x) - h(x) / .... + a(x), if I define y to be the result of this huge chain of functions over functions over functions, the compiler will make this copy over copy over a copy. What if x was a 1-million element list instead of 3? And with every function, we make a new copy? That doesn&#39;t sound very memory friendly.</p><p>Turns out functional languages deal with this problem in a very beautiful way: <strong><em>Lazy data structures</em></strong>.</p><h3>Lazy Data Structures</h3><p>Let’s have a look at this Clojure code:</p><pre>;; (0, 1, 2, 3, 4, ...)<br>(def integers (range))</pre><p>This defines an <strong>infinite</strong> list of all integer numbers in a list called integers. Of course not the infinite list of integers will be saved in your memory, but instead only what you want to evaluate, gets evaluated.</p><pre>;; gets first 10 integers and maps an <br>;; increment function on all of them.<br>(def first-ten-integers (take 10 integers))<br>(def incremented (map inc first-ten-integers))</pre><p>The way lazy (or persistent) data structures are defined in memory is a very complex and interesting topic that shall be discussed in the next article.</p><h3>Conclusion</h3><p>Taking the ideas of mathematicians into programming wasn’t very bad after all. We’ll still use the same fundamental concepts of programming, but we’ll only change the higher-level way of modeling our programs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2DissncwV87Chg6IVsBPvw.png" /></figure><p>We added some rules in hope that our programs become cleaner and more concise. But functional programming isn’t this magical box that will make all your dreams come true. You’ll still find yourself making errors, you’ll spend a couple of minutes looking for a missing bracket or fixing a simple bug. It is just a cleaner, more organized way of thinking about computer programs.</p><h3>References:</h3><p>[1] — Flow diagrams, turing machines and languages with only two formation rules: <a href="https://dl.acm.org/doi/10.1145/355592.365646#CIT">https://dl.acm.org/doi/10.1145/355592.365646#CIT</a></p><p>[2] — Function: <a href="https://mathinsight.org/definition/function">https://mathinsight.org/definition/function</a></p><p>[3] — Function Machine: <a href="https://mathinsight.org/function_machine">https://mathinsight.org/function_machine</a></p><p>[4] — What are first-class functions? <a href="https://lispcast.com/what-are-first-class-functions/">https://lispcast.com/what-are-first-class-functions/</a></p><p>[5] — Elm Programming Language: <a href="https://elm-lang.org/">https://elm-lang.org/</a></p><p>This article was heavily based on the work of Bob Martin and his book Clean Architecture: <a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html">https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html</a> and Russ Olsen’s talk Functional Programming in 40 minutes: <a href="https://www.youtube.com/watch?v=0if71HOyVjY">https://www.youtube.com/watch?v=0if71HOyVjY</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69631b53f529" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Computational Numerical Analysis]]></title>
            <link>https://m-amarnah.medium.com/computational-numerical-analysis-517eda19cef8?source=rss-8c18102a4b80------2</link>
            <guid isPermaLink="false">https://medium.com/p/517eda19cef8</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[polynomial-interpolation]]></category>
            <category><![CDATA[numerical-analysis]]></category>
            <category><![CDATA[approximation-theory]]></category>
            <dc:creator><![CDATA[Mohammed Amarnah]]></dc:creator>
            <pubDate>Sat, 23 Jun 2018 13:53:48 GMT</pubDate>
            <atom:updated>2018-06-23T14:33:17.767Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part (1) — Introduction and Overview</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*n1jp89dZWTgA6_6qlCYizQ.jpeg" /></figure><p>In the past couple of semesters at my university, I decided that the mathematics course “Numerical Analysis” was my favorite math course ever. I found that course so close to real world problems, and it tried to solve those problems in the most efficient, yet realistic ways. What I liked the most about it is that it is the perfect combination of theory and applied science, and so I decided to explore what is beyond the presented in my undergraduate course.</p><p>But what is Numerical Analysis, exactly? What does it study? Honestly, when it comes to definitions, I like to go directly to wikipedia. It says that “Numerical Analysis is the study of algorithms that use numerical approximation (as opposed to general symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics)”.</p><p>So, this series of blog posts will be devoted to try to explain some of the topics that Numerical Analysis studies, and hopefully present them in an introductory way to Machine Learning (as this series of topics are in the core of theoretical Machine Learning research).</p><p>In this first article, I will present some of the topics that is studied by numerical analysis, and provide an overview on what to expect in the coming articles. I will also provide you with a list of all the references that I will be using in developing the material. I want to point out, that I am still a beginner, and that I decided to write these posts, in order to learn more about the topics in this field. If you found anything wrong, or you think of any suggestion that will make this a better learning experience please do not hesitate to contact me on any social network you find me on.</p><h3>Introduction to Numerical Analysis</h3><h4>Why do we study that?</h4><p>Generally, Numerical Analysis is a very broad topic, and it studies a lot of different sub-fields that are very important in solving numerical real life problems. Some of the topics that are studied includes:</p><p><strong>Convergence and Series Acceleration:<br></strong>This includes studying the rate of convergence in a sequence (that is the speed at which a convergent sequence approaches its limit), local and super convergence, etc.</p><p><strong>Discretization:</strong><br>Which is an extremely interesting topic that studies the process of converting continuous functions and mathematical models into discrete components. This is widely used in signal processing, system theory, and in control systems.</p><p><strong>Solving Systems of Linear Equations:</strong><br>This might be one of the most famous topics in Numerical Analysis. It basically studies methods that can solve systems of linear equations. These methods include the Gaussian Elimination, LU Decomposition, and many other methods and techniques.</p><p><strong>Polynomial Interpolation and Extrapolation:<br></strong>Interpolation is a method of getting new points within the range of a discrete set of known points. Extrapolation is the process of estimating, beyond the original observation range, the value of a variable on the basis of its relationship with another variable. Both topics are one of the most important topics not just in Numerical Analysis, but also in Machine Learning and Neural Networks.</p><p><strong>Optimization:<br></strong>Mathematical Optimization is the study of optimizing a specific function relative to a set of variables and constraints. Optimization can be easily looked at in your Calculus course, where you were asked to find the maximum or the minimum of a function. This topic is one of the most studied and used ideas in applied research and in solving real world problems. Every company, investment firm, factory, and many others wants to minimize or maximize either their yield, profit, productivity. Optimization problems are everywhere!</p><p>That’s not it! There are tons of other numerical analysis topics that are being studied in research centers and by companies and industry. Here is a list of Numerical Analysis topics from wikipedia: <a href="https://en.wikipedia.org/wiki/List_of_numerical_analysis_topics#Optimization">https://en.wikipedia.org/wiki/List_of_numerical_analysis_topics#Optimization</a></p><p>As you saw, Numerical Analysis, and the topics studied by it, is needed literally everywhere. Whether it is in industry or academia or anywhere! One of the biggest issues in our educational system (I’m talking about the Arabic world, and specifically in Jordan, but this might be everywhere) is that we take a lot of our courses in university or high school, without knowing “WHY” we take them. In my years in the university, one the most thing that I heard from other students was “Oh I hope they remove Calculus 2 from our curriculum” or “There is no need for Linear Algebra, Physics, or Applied Probability in our curriculum! Why do we even have that!”. And this is bad. Very bad. In this series, I will present a humble try of mine, to correct these ideas, and show that mathematics is one of the most important sciences in the 21st century. I will try to present a theoretical introduction followed by an applied perspective of the same concept, to show that theory and application are very much alike, and that they complete each other.</p><h3>Overview</h3><h4>What is the curriculum gonna look like?</h4><p>As I already mentioned, Numerical Analysis is a very broad topic, so in the upcoming series of posts, I will only cover some of the topics that I mentioned above. The following selection of topics is not final, and it is subject to change, but I hope it’ll be as close as possible to this.</p><p>First of all, I will start with Approximation Theory. Where we try to study how we can approximate complex functions with functions that are much simpler. We will talk about the Fourier Transformation, and we will talk about the Universal Approximation Theory. These topic will be the first part of a theoretical introduction to Machine Learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MjSx99hqRl-9uRzUqfyI_w.png" /></figure><p>From there, I am going to move to Polynomial Interpolation and Extrapolation, I will talk in depth about the methods of them, the recursive (very interesting 😍) and the iterative methods, and how can we computationally implement that. We will follow some examples on that and try to solve different problems with interpolation and extrapolation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*K3U5gBYBwkqM9fUAEVDsxg.jpeg" /></figure><p>After that, we will go to Optimization, and we will check out very cool algorithms and techniques. We will checkout Dynamic programming, Linear programming, Gradient Descent, Stochastic Gradient Descent and finally try to understand -together- the most powerful optimization algorithm, Adam.</p><p>Most probably, the topics mentioned above are ones that I am sure I will study and write on and anything other than that, will be something extra, where while reading some book or paper I found an interesting topic or concept that I would like to share with you, I will do that immediately!</p><p>I would like to note that all of the programs that we will write will be either in C++ or in Python. The reason for that is that I am most comfortable with those two languages, but you can always implement all the concepts in your favorite programming language.</p><h3>Prerequisites</h3><p>Although I will try to assume that on mathematical background is present, but being exposed to a previous one or two Calculus courses will definitely help. Of course, if you don’t know calculus, then do not worry about it.</p><p>The only thing that might be required is an advanced knowledge in programming. Since this series will be devoted -hopefully- to the computational applications of the topics presented. Programming language is not a constraint here, so any language is fine. Just make sure to at least have the mindset of a programmer or a computer scientist.</p><p>And of course, you will need the spirit of a learner. You want to learn, and that is why you are reading this series!</p><h3>List of References</h3><p>Currently, I am working on collecting and curating a list of structured Computational Numerical Analysis self studying curriculum, but it is still not complete. However, I will share with you the list of books and other references that I am following in creating this series. Any other reference that is used and not listed here will be listed in the original article of usage.</p><ul><li>Numerical Recipes: The Art of Scientific Computing, William H. Press et. al, Cambridge.</li><li>Introduction to Numerical Analysis [2nd Edition], J. Stoer et. al, Springer-Verlag.</li><li>Numerical Optimization [2nd Edition], Jorge Nocedal et. al, Springer.</li><li><a href="https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw">3Blue1Brown</a>: A youtube channel that presents several mathematical ideas in a very beautiful and visual way.</li></ul><p>Finally, I hope you will like this journey. As I mentioned, I am still a beginner in all of this, and I wish we could learn more, together, and make an impact in our world and fields.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=517eda19cef8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Wonders of Artificial Neural Networks]]></title>
            <link>https://m-amarnah.medium.com/the-wonders-of-artificial-neural-networks-71dfaab64209?source=rss-8c18102a4b80------2</link>
            <guid isPermaLink="false">https://medium.com/p/71dfaab64209</guid>
            <category><![CDATA[interpolation]]></category>
            <category><![CDATA[extrapolation]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Mohammed Amarnah]]></dc:creator>
            <pubDate>Sat, 10 Jun 2017 17:30:35 GMT</pubDate>
            <atom:updated>2018-06-23T13:16:47.051Z</atom:updated>
            <content:encoded><![CDATA[<h4>How an ANN can beat humans in GO but fails in predicting f(x)=x²</h4><p>A while ago, our AI professor gave us an assignment to apply what we learned about Artificial Neural Networks. It was simple, and pretty easy to be honest. <strong>It said:</strong></p><p><strong>Write a Neural Network that predicts <em>f(x)=x²</em></strong>.</p><p>For any of you who have taken any AI or Machine Learning course, or even wrote any ANN code before, you’ll know that predicting the square function is easy. And it is. In fact ANNs can predict any polynomial function and of any degree. <strong>But, only under one condition: <em>A finite range of values on the testing set.</em></strong></p><p><em>What does that mean? </em>If you trained the network on the range [-100, +100] and then tested it on [-50, +50], you’ll get pretty good results. However, if you tested it on a range of [-500, +500] the network will fail miserably.</p><p>Okay, before we dig into details, let us be on the same page. In 2014, 4 research scientists published a paper that cited a 1993 paper by a scientist named Barron that proved the same results but less general. They proved that <em>“a two-layer neural network can represent any bounded degree polynomial, under certain (seemingly non-restrictive) conditions.”</em></p><p>Here’s a preview from the abstract of their paper:</p><blockquote><strong>“First we show that for a randomly initialized neural network with sufficiently many hidden units, the generic gradient descent algorithm learns any low degree polynomial, assuming we initialize the weights randomly. Secondly, we show that if we use complex-valued weights (the target function can still be real), then under suitable conditions, there are no “robust local minima”: the neural network can always escape a local minimum by performing a random perturbation. This property does not hold for real-valued weights. Thirdly, we discuss whether sparse polynomials can be learned with small neural networks, with the size dependent on the sparsity of the target function.”</strong></blockquote><ul><li><strong>Learning Polynomials with neural networks: </strong><a href="http://proceedings.mlr.press/v32/andoni14.pdf"><strong>http://proceedings.mlr.press/v32/andoni14.pdf</strong></a></li></ul><p>So given all of the above, all the proofs and scientists talking, why does it still fail sometimes?<br>It’s because Neural Networks can approximate any continuous function only within a <strong>compact set</strong>.<br>So given a <strong><em>continuous function f(x)</em></strong>, and a <strong><em>finite range of values [a, b]</em></strong>, then there surely exists a neural network that can approximate the function with <strong><em>an error ε &gt; 0. For example, if we wanted to approximate f(x)=x³+3, on the range [-50, +50], then there exist a neural network that can do that pretty easily. </em></strong>But ask the network to predict the value of the function on a point outside that range, you’ll find that the accuracy of your prediction will decrease linearly as you go farther outside the range.</p><p>Here is what that means in images. Here you’ll see a network trained on the range [-7, +7] to predict the square function f(x)=x²</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*0W1J7BS_jhG-W9BCKvsxwA.png" /><figcaption>A Neural Network to predict f(x)=x² trained on the interval [-7, 7] and tested on [-30, 30]</figcaption></figure><p>As you see, the network was tested on the interval [-30, +30], and it produced decent results. <strong>Now what happens if we increase the testing interval? </strong>Here you go:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*j1G8vaxqKzRWQQKGRPnIZA.png" /><figcaption>A Neural Network to predict f(x)=x² trained on the interval [-7, 7] and tested on [-100, 100]</figcaption></figure><p>You can see now that the error increased drastically when we increased the testing interval. So why is that? Why is it that ANNs can do wonders but fails in finding the pattern of a basic square function? It’s because of <strong>extrapolation</strong>.</p><h3>Interpolation vs Extrapolation</h3><p>Interpolation is an estimation of a value <strong>within two known values in a sequence of values <em>(i.e [a,b] where a,b are finite numbers)</em></strong>. <a href="https://en.wikipedia.org/wiki/Polynomial_interpolation">Polynomial interpolation </a>is a method of estimating values between known data points. When graphical data contains a gap, but data is available on either side of the gap or at a few specific points within the gap, interpolation allows us to estimate the values within the gap.</p><p>Extrapolation is an estimation of a value based on extending a known sequence of values or facts <strong>beyond the area that is certainly known</strong>. In a general sense, to extrapolate is to infer something that is not explicitly stated from existing information.</p><p>Approximating a polynomial function <strong>for</strong> <strong>an infinite range of values</strong> falls under Extrapolation, however, ANNs are suited for Interpolation. But why?</p><blockquote>Let’s assume that we have a training set <strong>y</strong> with<strong> y∈ R</strong>. Can a neural network regression model extrapolate and return<strong> y_pred</strong> values outside the <strong>y</strong> range in a training set? Does it depend on the activation function or not?</blockquote><p>The output neuron of the model is just <strong>∑Θ[i]a[i]</strong>, where <strong>Θ[i]</strong> — <strong>is the</strong> <strong>weight of i-th neuron</strong> on the previous hidden layer, and <strong>a[i] — is the value of the activation function</strong> of that neuron. If we use the <a href="https://en.wikipedia.org/wiki/Logistic_function">logistic function</a> then <strong>a ∈ [-1, +1]</strong>. Thus maximum possible <strong>y_pred=∑Θ[i]</strong>, assuming that all <strong>“a”s</strong> reach their maximum value around <strong>1</strong>. But if we use the linear activation function, which doesn’t have restrictions on the output values of <strong>a (a ∈ R)</strong> the model will return <strong>y_pred ∈ R</strong>, which can be outside the range of the training set. Does that mean the output is correct? No. Prediction will be less good in regions of the data that were not present in the training data. That’s why extrapolation is hard for Neural Networks.</p><p>So what now? Is that it? No, there are so many solutions to that problem. It won’t give you the accuracy of interpolating a neural network, but still, it’ll give you good results. One of the solutions is using a rectifier unit <strong><em>g(x)=max(0,x) </em></strong>as an activation function. It’s an unbounded but non-linear link function. It also keeps the nice “universal approximation” property of the neural network, but with unbounded outputs.</p><p>That was my first article on Medium. I really enjoyed writing this, and learned so much from it and I really hope you like it too. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71dfaab64209" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>