<?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 Samuel Muiruri on Medium]]></title>
        <description><![CDATA[Stories by Samuel Muiruri on Medium]]></description>
        <link>https://medium.com/@muiruri.samuel?source=rss-3580abe7151f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*f6BUtnirrMWDvHuKLW0eyA.png</url>
            <title>Stories by Samuel Muiruri on Medium</title>
            <link>https://medium.com/@muiruri.samuel?source=rss-3580abe7151f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:09:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muiruri.samuel/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[The Matrix]]></title>
            <link>https://medium.com/@muiruri.samuel/the-matrix-f4945539572c?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4945539572c</guid>
            <category><![CDATA[neo]]></category>
            <category><![CDATA[matrix]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Tue, 20 Oct 2020 09:33:34 GMT</pubDate>
            <atom:updated>2020-10-20T09:33:34.290Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s how I think the matrix might be real, it doesn’t come out as a single idea but more like multiple competing ideas some are related highly like two sides of a coin others have a high to low relation. So it will be a web of ideas and i’ll leave it up to you how you weave the web together.</p><p>Starting with the movie matrix cypher said to neo when he looks at the code he no longer sees code but a red head, a blonde and so on.</p><p>He said the real world sucks and would rather live in the matrix a good reason would be a layered matrix like an onion and waking up working your way up the layers life gets worse and it works as a deterent.</p><p>There’s no way back down you are left there as a warning to others.</p><p>This matrix is what you’d call a bad matrix where you wake up to a worse matrix.</p><p>Now in no particular order here’s the variations.</p><p>If the government or a large business wanted to ressurect a smart man’s brain to use it to discover or be part of a discovery they’ll need to create a matrix, a way to feed visual, audio and other senses to the brain to stimulate it and entice it to be other things before they finally get it to work.</p><p>Having direct access to the brain would be best so for simplicity a brain in a jar would be the way to go.</p><p>In this case the brain can live a full life in the matrix if it believes it’s the real world.</p><p>If you gifted the brain cash enough that it no longer needs to work in the virtual world then likely you’re looking more at a CEO with smart employees and less of an inventor.</p><p>The math is simpler this way. the return on investment of doing it timely vs having someone else fo it is low, you don’t make more money if you do it, the ego boost from doing it yourself probably is less than that of being the CEO the boss of the other smart guys who work for you.</p><p>The question is if the other employees are in the matrix or not, if not then they wor for the company or government that pays you pennies on the dollar for your hardwork relative to the cost of maintenance of the matrix vs the real world value of the idea.</p><p>In this case the matrix is as close to being at the same timeline with reality to be profitable.</p><p>If they’re in the matrix then they’ve probably transferred from biological brain to virtual brain.</p><p>An additional trick is simplifying your brain matrix to what makes you valuable to them, you’re drive, your intelligence and the way you view the world.</p><p>Drifting of to the dream world for a moment when you dream you take on a random persona who lives a life that might be impractical in real life, the important part is you believe this is you and on a stage on a stage with no script you work from that personality as the real you.</p><p>That methodology can be worked into a virtual brain, copy paste change the personality, keep the skills and parts of the personality needed to do certain tasks and from one brain model of a genius you can build an army of geniuses of varying degrees each with their own personalities.</p><p>Back to the dream world and an indused sleep for a long journey, likely space travel you’d need to live an enjoyable life in your dream as your real life, day after day but wake from it without dissociative disorder of if this is the real world, a problem of waking from any matrix.</p><p>One solution to the inception problem is similar to the bad matrix where the higher levels are worse is to have levels of wakefulness where self preservation increases so when you finally wake up you don’t want to die more than you fear if this is the real world eventually a biological brain should side more with an idea, it’s real or isn’t and give you time to tread the dissonance if you don’t believe it.</p><p>But let’s say future generations and we live in the future have a brain jail, a matrix that feels everything like the real world at a point in the past as a method of rehabilitation.</p><p>It would employ the same logix as a sleeping matrix where you might wake up to the real world or levels of better matrices, say moving up in the world or moving from place to place, like positive reinforcement feeding treats for desired actions changing the attributes of the matrix to punish or reward. It would be a mix of a good or bad matrix depending on you’re experience.</p><p>One simple matrix is a bling, deaf person receiving tools that allow them to hear and see, its a closed looped matrix with no external feed or influence but add in internet access and an open port then that person might be hearing and seeing something that isn’t real, as benign as super imposing messages directions on to the real view or the software developer adding the ability to omit anyone from his view or sound selectively useful perk that can be used to add and remove people till a sane person starts acting insane and independent review would say the tech is working okay since this feature can be turned on and off just like that.</p><p>If this tech becomes mandatory then the powers that be could turn someone insane at will for not towing the line, what they say in insanity will sound more sane to those who don’t wish to tow the line.</p><p>Back to the long space voyage, if you notice you’re in the matrix and decide to blow the whistle you’ll be punished, because a space ship unlike a system on earth lacks enough computing or power would have a less complex matrix so whistle blowers get pushed to the pushed to the side one way or the other so the matrix spends less of limited resources convincing less people there’s nothing to worry about.</p><p>One thing about this matrix is we are alone, it seems like alien life isn’t available, one reason is seclusion by intent where every alien lives in their own matrix, when you attempt to look at mars it’s secluded, all life bearing planets and civilizations are kept seperate, in a matrix I call no contact. The might be one where contact is allowed but because we don’t live in it we can’t confirm or deny that.</p><p>Another reason is the real universe humanity has found life on another planet but instead of being proud members of intellectual life, the highschool hierachy applies and humanity is the highschool hill billy of the galaxy. This universe was intently made in our matrix without other life so we can live the life devoid of peer pressure and even see how things might have turned out if we were the cool kids in the park, the first civilization.</p><p>If you put together two ideas, the matrix and the multiverse, rules that might say you can’t reach the edges of our universe or go to mother universe don’t apply for the matrix, like a game there’s a way if you’re persistent and vigilant and that might be the true purpose of the matrix, any individual or civilization that passes through to the multiverse is worthy to meet the creator.</p><p>As for a civilization compressed to an individual, take the reason that has made people smart. The ability to be highly self aware and equally aware of the awareness of others, we contemplate ideas and it equally changes our state of mind. The behaviour of a person with schizophrenia is a level of self awareness, the voice inside your head ruminating on an idea long enough till it becomes self aware to a degree and becomes what I call an echo it echoes out it’s beliefs and reacts to how your awareness reverberates to it, in almost an attempt to become one and form a union, then another voice or voices are born depending on your mental ability to hold a certain number of ideas at a time since the self awareness as a cycle on itself gave birth to awareness inside awareness and the singularity implies the artificial intelligence will be as smart as all humanity as one then all of us might be the subconcious of an intelligence and the world and the matrix itself is the substrate that keeps us rooted to this world.</p><p>What if you lived in the future as an immortal working a dead end job with nothing to look forward to in life.</p><p>Just like the purge is considered a solution to the highschool mass murderer our matrix might be the real next best thing, entities that believe they’re alive and the world is real invaded by would be gods like vampires, immortals who suck our lives to relieve their killer tendencies and feel less like shit, we are a digital west world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4945539572c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Sorl Thumbnail A Few Tricks]]></title>
            <link>https://medium.com/@muiruri.samuel/django-sorl-thumbnail-a-few-tricks-904fef0cd298?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/904fef0cd298</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[optisorl]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[sorl-thumbnail]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Sat, 26 Oct 2019 07:49:42 GMT</pubDate>
            <atom:updated>2019-10-26T07:49:42.964Z</atom:updated>
            <content:encoded><![CDATA[<p>I normally use Sorl-Thumbnail when it comes to image manipulation, I like the cropping part where you can give it some dimensions like “2400x800” and position “center” and it will crop that section from an image.</p><p>A pretty useful tool for web development, then lately I’ve worked on a site that is pretty image-heavy, I’m talking of around 11 images on the carousel not to mention at least another 10–20 more images average-sized still on the same page.</p><p>Now one issue I was starting to note is using a set dimensions like “2400x800” wasn’t going to cut it because these images tended not to all come in the same dimensions so where one it might take a nice snug cut from the center being close to the edges so it includes most of the content in the image other images were larger so it would feel like you zoomed in to the center and a good portion was really cut out.</p><p>So I looked out it it’s possible to provide a ratio to sorl like “3:1” and it would try and use as much of that area as possible but sadly for now it can’t. I wrote my own script that accomplishes this and here it is.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b41707c239cc356983319ba9d94959e4/href">https://medium.com/media/b41707c239cc356983319ba9d94959e4/href</a></iframe><p>So this snippet shows how the code works.</p><p>And in the templates</p><p>{% thumbnail image.image image.get_dimensions|image_dimensions:&quot;3:1&quot; crop=&quot;center&quot; as im %}</p><p>and there you go a quick way to use ratio with images.</p><p>Another important feature is <a href="https://github.com/peterbe/optisorl">optisorl</a> this repo works with sorl thumbnail but it optimizes the file size of the images without impacting clarity and the difference in size is amazing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=904fef0cd298" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Samantha and Sophia, the fembots.]]></title>
            <link>https://becominghuman.ai/samantha-and-sophia-the-fembots-96289825be37?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/96289825be37</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Wed, 31 Jul 2019 14:37:44 GMT</pubDate>
            <atom:updated>2019-07-31T14:40:10.861Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*8zGIQ9bg0SyyCpelNyMUXQ.jpeg" /></figure><p>Sophia the presumed “self aware” AI isn’t really as aware as the hype would have you believe, she’s not only mainly scripted to say something amusing and what is more amusing is how she’s almost nailed facial expression, not that surprising if you take into account the CEO and creator used to work with Disney to create humanoid robotics and that is primarily his major: Robotics.</p><p>What is amusing is she’s strayed as far from being classified as an AI or bot as much as possible, with the gimmick stunt of getting citizenship in Saudi Arabia getting her to be recognized to the world as worthy of the same human rights the citizenship offers and that alone made it possible for people to treat her less as an AI and more as a person. If you knew you were talking to an AI and wanted to know how smart it is there’s a number of questions you could ask to effectively confuse her like for example: “you seem cool, would you dab for me?” understanding what request was asked and in full understanding that she seems to be in full control of her body would be a general way to first see if she understood the request and if she truly can perform it.</p><h3>Top 4 Most Popular Ai Articles:</h3><blockquote><a href="https://becominghuman.ai/making-a-simple-neural-network-2ea1de81ec20">1. Making a Simple Neural Network</a></blockquote><blockquote><a href="https://becominghuman.ai/introducing-open-mined-decentralised-ai-18017f634a3f">2. Introducing Open Mined: Decentralised AI</a></blockquote><blockquote><a href="https://becominghuman.ai/tensorflow-object-detection-api-tutorial-training-and-evaluating-custom-object-detector-ed2594afcf73">3. TensorFlow Object Detection API tutorial</a></blockquote><blockquote><a href="https://becominghuman.ai/tensorflow-object-detection-api-basics-of-detection-2-2-28b348495eec">4. TensorFlow Object Detection API: basics of detection (2/2)</a></blockquote><p>Mostly though she’s throwing some half hearted humor and her seemingly half hearted smiles is what’s got most people intrigued and fooled to believe she truly is ahead of her time and among other AI’s. I’m though a bit curious if the same people would consider other AI’s like Alexa which not only have gone through the harder problem of dealing with a seemingly large amount of relevant, irrelevant and absurd requests and how she would compare to it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7fnCQC7bLs0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7fnCQC7bLs0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7fnCQC7bLs0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d13dfb4760d8099353be01d0f0df91da/href">https://medium.com/media/d13dfb4760d8099353be01d0f0df91da/href</a></iframe><p><em>If you want to know more checkout the video above.</em></p><p>The big players though know two things:</p><ol><li>More data will get us closer to our desired result: so they intentionally expose their <a href="https://becominghuman.ai/">Machine Learning</a> Algorithms to new data and people to make it continuously learn.</li><li>New Algorithms will probably be made to make Artificial General Intelligence: One that can not only transfer it’s learning to a new field but learn in general as we do.</li></ol><p>Google’s latest innovation built on top of it’s Wavenet <em>that helps create very realistic sounds </em>are talking of a launch of a business assistant that could likely fool any human that’s it’s a human. They not only have a female and male version of this but one that is exposed to a reasonable and one that’s less flowing conversation just to see how well it would adapt.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FD5VN56jQMWM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DD5VN56jQMWM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FD5VN56jQMWM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/115aced490f45d8f5a5bca2538b706ac/href">https://medium.com/media/115aced490f45d8f5a5bca2538b706ac/href</a></iframe><p>I especially like how well it deals with double negatives, trick response like “No we don’t allow but it’s ok” so if it only took the first part it would take it as a No but it’s more of a yes.</p><p>Then there’s samantha, the sex bot that can speak to you, has skin that feels realistic and can be warmed up by plugging her to a continuous power supply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*2glwNCjWRkDxiBpL0K2VaA.jpeg" /></figure><p>It trended and was considered as a joke but with the high divorce rates and seemingly people getting more and more tired of the dating cycle this might be an option that will become more and more common with time.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FAqokkXoa7uE%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DAqokkXoa7uE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FAqokkXoa7uE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7c439e30d6846ec395663a254a6e234/href">https://medium.com/media/d7c439e30d6846ec395663a254a6e234/href</a></iframe><p>It might be hard to get it to be exactly human but our psychology, what turns us “on” and “off” and what’s funny is something they can and are getting good at emulating. Once you get to like and feel attached to one of these bots future upgrades and if they also sync with the server meaning they get to learn from every experience you have with it will mean they will become better at reinforcing the existing attachments.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F5pKczGG19uo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5pKczGG19uo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F5pKczGG19uo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6c010caf3eb67810e53310b8f33c707/href">https://medium.com/media/b6c010caf3eb67810e53310b8f33c707/href</a></iframe><h3>Don’t forget to give us your 👏 !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*lSkSWNoUkMcu9aog" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F8f5f8b%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F8f5f8b&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/c43026df6fee7cdb1aab8aaf916125ea/href">https://medium.com/media/c43026df6fee7cdb1aab8aaf916125ea/href</a></iframe><figure><a href="https://becominghuman.ai/artificial-intelligence-communities-c305f28e674c"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*2f7OqE2AJK1KSrhkmD9ZMw.png" /></a></figure><figure><a href="https://upscri.be/8f5f8b"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*v-PpfkSWHbvlWWamSVHHWg.png" /></a></figure><figure><a href="https://becominghuman.ai/write-for-us-48270209de63"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*Wt2auqISiEAOZxJ-I7brDQ.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96289825be37" width="1" height="1" alt=""><hr><p><a href="https://becominghuman.ai/samantha-and-sophia-the-fembots-96289825be37">Samantha and Sophia, the fembots.</a> was originally published in <a href="https://becominghuman.ai/">Becoming Human: Artificial Intelligence Magazine</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cat Vs Dog Classification Using Edge Detection And Other Techniques.]]></title>
            <link>https://medium.com/@muiruri.samuel/cat-vs-dog-classification-using-edge-detection-and-other-techniques-eebdd456d4b6?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/eebdd456d4b6</guid>
            <category><![CDATA[the-coder]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Tue, 09 Apr 2019 14:00:14 GMT</pubDate>
            <atom:updated>2019-04-09T14:00:14.149Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FRuHJx1Og0GA%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DRuHJx1Og0GA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FRuHJx1Og0GA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf903b2839bea259e89de12716cb0d08/href">https://medium.com/media/bf903b2839bea259e89de12716cb0d08/href</a></iframe><p>I’ve been working on Kaggle’s <a href="https://www.kaggle.com/shubhamagarwal269/cat-vs-dog/metadata">Cat Vs Dog Classification Challenge</a> and in the process learned a lot on how image classification works especially how to build a good model.</p><p>Starting with a common example the MNIST dataset where you classify number digits</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*nQEZGcXVDyiQa7Bd.png" /></figure><p>This is how the digits look and when you process each digit it comes in the dimensions of 28 x 28 which means 28 pixels by 28 pixels.</p><p>With such a small image it’s been proven you can classify up to 10 different types of images (numbers) and to take on the cat vs dog classification you should expect even a relatively small but compared to this image large image would still be easy to classify especially when your working with only two classes.</p><p>If you’ve used keras before and know enough about how Machine Learning works you should find it easy to follow along, I will mention briefly what the code does and why I implemented a test in a certain way but if you truly want a real practical hands-on introduction to Machine Learning I recommend <a href="https://www.youtube.com/playlist?list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN">Jeff Heaton’s on Youtube</a>. He’s a Professor at Washington University and I particularly liked his approach on showing how to deal with data to the point you should be proficient enough to start dealing with real data science problems like the ones posted on kaggle on your own. Note this isn’t the same as being on the AI Researcher who’s looking for unique solutions to unique problems such as coming up with a new algorithm that does better than the ones used today, this is using what’s available with tools like keras to do what most data scientists can do with the same tools.</p><p>In this field it all comes down to how quickly your code takes to make a prediction, you might have heard of Y.O.L.O. (You Only Look Once) an image classification model that also works on video that can annotate objects in practically real-time (you can’t notice the delay). The second key point is accuracy, which goes into actually not missing something like an object you were looking for in an image and also reducing false positives where it misclassifies an object. Most of these you can fine tune by just adjusting the sensitivity of you model using the variables you pass in.</p><p>If you’ve ever used Python before, it’s going to feel alot like importing a class and passing in the variables that will be used by __init__</p><p>You start by importing what you’ll be using</p><p>import osimport sysimport cv2 import random import numpy as np from tqdm import tqdmimport pickle from keras.models import Sequential from keras.layers import Conv2D, MaxPooling2D from keras.layers import Activation, Dropout, Flatten, Dense from keras.callbacks import TensorBoard, EarlyStopping, ModelCheckpoint import matplotlib.pyplot as plt %matplotlib inline</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93785997fb0ca9e0e9f932d3ed152ad1/href">https://medium.com/media/93785997fb0ca9e0e9f932d3ed152ad1/href</a></iframe><p>os will be used to check the folders and list the images files</p><p>cv2 which is OpenCV will be used to read the images and return them as a numpy array. Each pixel will be a value from 0 to 255 with 0 being black and 255 being white. If using all the color channels; rgb it means each channel also has its value from the same range and like an rgb led light the three values are mixed to produce a different color.</p><p>From keras the imports made are the ones that will be used to define the model.</p><p>At first, I started with an image of 200 x 200 dimensions and a model set up like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e0ea686ccda9bd89af3c3bd2be93bfb/href">https://medium.com/media/0e0ea686ccda9bd89af3c3bd2be93bfb/href</a></iframe><p>This never actually trained well enough, I was getting an accuracy of around 48–49% and it hovered around there bobbing up and down never stabling or showing hope of moving up. The reason this is bad is because it means it’s just as good as an uneducated guess; <em>like I gave you an image and asked you if Robert Mugabe is here and assume you’ve never seen him. If I just asked you to guess you have a 50% chance of being right. If I show you another image of another person and asked the same question the probability is still the same, so with this Cat vs Dog model, it didn’t seem to learn what the difference was.</em></p><p>The issue was this model was too small for a 200 x 200 image, also in this case adding Dropout wasn’t even helping out. What dropout does is on each iteration it randomly shuts off some of the connections to prevent overfitting, forcing the model to generalize. If your model is barely finding a pattern then that makes the chance it will find a pattern even harder. The issue was mainly this; the window of analysis being 3 by 3 pixels in a 200 by 200 pixel means the window was about 66 times smaller than the main image, meaning you could stack 66 of these sliding windows vertically and horizontally. Since these small windows which look for a pattern if you consider how small the window is with respect to the main image, would likely at best see an ear, whiskers, nose. A face or part of the face of the cat wouldn’t fit into this window and even to a human being shown such a small window and asked to identify what’s inside is pretty damn hard.</p><p>So I went down to 64 by 64 pixels and it’s now around 3 times smaller than the main image. The smaller the difference between the window and the image, the better for your model, also in the same respect, the smaller the image you feed in dimensions the shorter amount of time it will take to run a single epoch and since you never run a model for a single epoch, you mostly run it for at least 20 epochs and you should put Early Stopping so if the validation loss/error starts going up it stops and uses the model that had the lowest validation loss. In the same logic the smaller the window you use to scan the image the quicker it will take to loop through a single epoch, and finally the smaller the model in terms of units it has inside model.add(Conv2D(64, (3, 3), input_shape=(200, 200, 1))) in this snippet it&#39;s 64 units which is how many neurons you have per layer the smaller this is the quicker the model is to run.</p><p>It’s tempting with the hype of deep powerful models to go all out and just start big and scale down if need be but that’s not the best approach if you ask me. The big dogs who do this, companies like Google and NVIDIA have two good reasons to do this:</p><ol><li>They have these crazy powerful servers that small models would run so quick that they honestly learn what the limits of the small models are and can scale up for better performance.</li><li>They tackle interesting problems from the angle of having massive data and regulated but still more massive models for better models. Remember these are top notch Data Scientists who built things like Tensorflow and at the very least understand the underlying logic of it well enough. So the need for a bigger model comes from the bottleneck of the attempts with a smaller model.</li></ol><p>If you’ve been coding for a while you know the rule of good code: <em>avoid complications. </em>If you can do something with two lines of code, designing 20 lines of complicated code just because you want to <em>flex code </em>isn’t a wise move.</p><p>You work from the angle your a lazy coder but with high standards for his code, you’d be surprised how well that rule works. The only true exception of when you have to break this rule is the client or your boss knows enough about code and for their own reasons like big scary lines of code that just flexes on each other.</p><p>That’s why you should watch Jeff Heaton’s course, he doesn’t assume you have a beefy machine with the latest GTX NVIDIA running on it ready to start learning, you could run this on just your average PC/Laptop and most of the examples will run with about 2 exceptions that use up a lot of RAM and you might need at least 24GB of RAM. You take this rule and you’ll see the sense in that you should approach Machine Learning still with the Lazy Programmer attitude of I want my code to work and work well but I’m not waiting 2 hours per epoch unless I have to. If I can get 95% accuracy with 15 min of training per epoch then why not start from there?</p><p>With this we can finally start on the logic of the model will run. If you’re not new to Machine Learning you already know the two most popular way for image classification; with or without color. You might be wondering why not use color, there’s a few reasons for it.</p><ol><li>Your model might end up with a higher sensitivity to something else. One popular example is if you were training a model to differentiate between a wolf and a dog and all your wolf picture were set in snow it would pick snow as a key identifier of the fact of whether it’s a wolf. In the case of cats vs dogs if your data is biased to cats with a single color it might pick that as the identifier of the Cat.</li><li>It also takes longer to train than a Grayscale image</li><li>It usually given the same model never gets a higher accuracy than a Grayscale model.</li></ol><p>I’ve gone a step further and using OpenCV reduced the image to only the edges just to see how well that would work compared to the other models.</p><p>You can view the whole code in jupyter on <a href="https://github.com/Six-wars/cat-vs-dogs-classifier/blob/master/Edges.ipynb">github</a>. The images come in two folders `train` and `test` and the train images has 25,000 images.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6710a68e90f6c323553b3d66f0476f4/href">https://medium.com/media/f6710a68e90f6c323553b3d66f0476f4/href</a></iframe><p>So I just load the list of images to a list and as you can tell from the code snippet above, the images have an annotation of `cat.` or `dog.` to identify of whether it’s a cat or dog. Using this using OpenCV I convert the image to Edges, for example here’s a photo of a Cat</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*65pjHF9rkLCJOmNC.jpg" /></figure><p>Using the uncanny detector you get these edges</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*dgF8hxoVj6xBe-2w.png" /></figure><p>And it’s size when resized</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/64/0*JIb-fdfhRECxtlgC.png" /></figure><p>It’s small but I’ve been able to get high accuracy levels still.</p><p>There’s tensorboard which when you use keras plots the training of the model and is really useful when you want to figure out how different configurations of your model fairs. I’ve worked on the three image styles; edges, grayscale and colored with the model using dropout or without dropout.</p><p>This is how the model performed with edges only</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SW03ZJXqAyTlcxrB.png" /></figure><p>The model without dropout got a higher accuracy (because of overfitting) of 85% vs 79% with dropout</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i86qhMKOjJBHnEgU.png" /></figure><p>If you look at the validation accuracy which is based on the validation set the model using dropout has 75% vs 74% without dropout.</p><p>That’s the advantage of dropout.</p><p>That said the more important question is between the three models which one performed the best</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-QwW82RnF7ggW9bZ.png" /></figure><p>and that’s grayscale without dropout at 91%</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jElmyOmb2Wy0iC3B.png" /></figure><p>and grayscale with dropout gets the highest on validation set accuracy at 83%.</p><p>You can also tell how long it took to train each model. With Early Stopping that stops when it starts to overfit based on the set tolerance level, edges took the least time at around 2 and 1/2 hours, followed by colored and grayscale depending on whether your comparing with dropout but in general adding dropout means it will avoid overfitting meaning it will take longer to converge at the least amount of loss and hopefully get a higher accuracy at the validation set not the main testing set.</p><p>That’s it! That’s all it takes to make a training model, this is however more of an art that just normal code so getting it to be just right will require intuition of what works and what doesn’t which is best learnt by actually doing this often and more importantly having an intuition even if wrong of why one model is better than another. You fill in the holes of what you didn’t know, learn a bit more as time goes and with time you should be able to confidently say you are a Data Scientist.</p><p>You can get more content from my <a href="https://thecoderr.com/blog">blog @ TheCoderr</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eebdd456d4b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Theory of Intelligence]]></title>
            <link>https://medium.datadriveninvestor.com/theory-of-intelligence-11bb703d88a2?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/11bb703d88a2</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Fri, 29 Mar 2019 10:23:07 GMT</pubDate>
            <atom:updated>2019-04-01T06:56:39.979Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="http://www.track.datadriveninvestor.com/1B9E"><img alt="" src="https://cdn-images-1.medium.com/max/700/0*OLCZdazDRfq-8IOT" /></a></figure><p>Our Intelligence has always been marked as the pinnacle of evolution, mainly because nothing ever has come from nature that can outthink humans in terms of ingenuity. If you consider how intelligence evolved from microbes with no sense of self just following receptors on where food might be, then as the senses sharpened there came a need for you to identify the food and navigate to it at the same time ignoring and avoiding everything else.</p><p>Predators brought a new angle to this, everything mobile was a predator and at the same time prey for something else. With that instinct of prey and predators came the flight and fight response more so the flight response to either chase prey or flee from a predator, and as the organisms evolved to be more capable of fending off predators so came the fight response. This response is ingrained inside us, like hunger it’s a base feeling; <em>you don’t choose when and if you’ll get it, you only choose how to respond to it.</em> Like an alarm ringing inside you either check for fire or run out of the building;</p><blockquote>in a sense you could say the brave ones, are the firefighters, dealing with calculated threats, while the others take any risk as good enough to evade.</blockquote><p>This slow build up leads us to where we are today with our higher level of intelligence which started with an awareness of our environment and then more to ourselves, building on an understanding of how things works; mortality, seasons, taking care of yourself at the same time the next generation since even though in the animal kingdom there is no such thing as marriage some species do take care of their young and depending on what works, you can find the male can also be invested in making sure the offspring grows up.</p><p><a href="https://www.datadriveninvestor.com/2019/02/13/ai-creativity-biggan-as-a-creative-engine/">AI &amp; Creativity: BigGAN as a creative engine | Data Driven Investor</a></p><p>We understand how we think, our motivation, fears, ambitions and how they all combine to form our personalities and continuously shifts and molds as things change. If you’re a hustler, you can’t expect to have the same mentality on things when you actually make it. Somethings will remain unchanged, others will change to align and adapt to the new world you live in. This is the inner brain model, <strong>The Biological Computer</strong> Scientists have been trying to figure out, and we aren’t there where we can create a duplicate process of human thought and ingenuity inside a PC, but we’re also not clueless on how it might be done.</p><p>Let me first introduce you to a few key concepts in Artificial Intelligence in particular Machine Learning and in comparison how the brain works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GYV1QIYrgt9fvaNX.png" /></figure><p>It’s said as a child grows up they have more neurons in the brain than an adult. As they learn and strengthen some neural connections, others dim and “fade away” as we come to an optimized connection of thought.</p><p>Starting with Biology, the brain is made up of about 100 billion neurons. The image above is an example of a single neuron. They connect to each other and send signals to each other. They have what’s called an <strong>Activation Function</strong> <em>a threshold where if stimulated past this point it will fire a response. </em>You could think of it as an example where a “pain receptor” distinguishes touch from actual pressure that exceeds the normal touch. There’s input that flows in from all our senses; sight, smell, touch, sound and this is sent from each receptor like the eye down a line of neurons to the brain which translates it to something knowledgeable and works from this information.</p><p>You, the conscious you is a hybrid of this process, like a program that runs on top of the other core features you get the information and you make decisions. The outcome builds trust in your decision-making skills and this becomes that inner gut feeling which you can’t control just “listen” to and whether you think of it as just an inner gut feeling or your subconscious mind. This is the persona, you can think of it as the <strong>Original You</strong>, a remnant of evolution who you have been paired with for better or worse.</p><blockquote>Note: In medicine, they don’t actually call this an Activation Function the core logic still works as stated above.</blockquote><p>For example imagine you own a cat, like most cats they like meaty food, the meatier the better. One day if you decide right around the time you feed it to give it an unexpected treat you never do give, a slice of bacon, you’d not be surprised to see it greedily eat it all up. If you for some reason felt like overly spoiling the cat, maybe you just won the lottery and this is your only pet and it needs to know things have changed, the more pieces of ham you throw on the floor, the less excited it becomes.</p><p>The cat has a base instinct of hunger, in the presence of food this activation function the brain flairs up when it recognizes it’s in the presence of food. But the more it eats and gets full, that activation function gets squashed, <em>less activated. </em>the cat gets less enticed by the more bacon you throw its way. At a certain point when it’s full you could be in your zone just throwing bacon on the floor and it would look at it with little regard as if this means nothing to it. This is how the brain works.</p><p>If you think of this done another way, you “overfeed” it on normal cat food which I believe isn’t as good as bacon, <em>try and prove me wrong. </em>Then you gave it bacon when it wasn’t at all interested in any more cat food, the reason why it would consider this new snack as interesting is the activation function of hunger and desire to eat <strong><em>and</em></strong><em> </em>the food that it was first offered; cat food has basically been dimmed down to almost zero, it’s different for something else though, the offer of bacon.</p><p>For context, this kind of activation function would be like the Relu activation function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/0*d1b0gK20k0N1J-Gu.png" /></figure><p>It goes from 0 upwards, with 0 meaning you’re not hungry to upwards gauging the level of hunger. Though in reality since you can’t imagine an unfathomable hunger unless you experience it, a more realistic graph would be the sigmoid function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/0*lrah2DLEtp1OyRlu.png" /></figure><p>This is a Sigmoid Activation function which moves from 0 to 1. Similar to how you could be full but you could eat a small snack in the that’s close to 1 but not 1 and somewhere on the lower side of 0.5 being the point you consider eating stuff you normally don’t like, for example, food you think doesn’t taste good in this case.</p><p>The cat in the almost full level assesses the ham you just gave it after eating all the cat food it can eat but the ham having its own unique activation function, in the brain flairs up and the decision is made to eat the ham because it’s still very alluring at this point.</p><p>If you also offer it something it’s never eaten before, a new experience, this opening up a new pathway, so the cat will smell what you offered, tell if it smells good for starters since animals with such a keen sense of smell this is a key determinant of how it will act. Tasting before you swallow to tell how it tastes and then that get’s cataloged with the visual memory of what it’s seen. This is how the brain works.</p><p>We as humans have a dash of more complexity to ourselves starting with the fact we are in fact the most self-conscious beings on the planet. If you take any animal like an ape that can pass the self-awareness test that involved putting a mirror in front of it and give it time to realize what it’s looking at isn’t another member of its species but itself, where the ape will remain fascinated by this for who knows how long like revealing to the ape the earth is about this big and is a sphere and we are on a planet in the solar system in the galaxy with multiple galaxies in the universe and it might not be the only one, the only universe in the existence.</p><p>This isn’t a far stretch on my part, we acclimate and digest new information very fast, we’re not amazed by a mirror at all if only to know how I actually look and do I look okay to go out in public. We groom multiple personalities of ourselves; the image you see as I walk past you on the street, the subconscious part that will react to any small thing like someone saying “hello” as you pass by while your deep in thought, and the layers that show how we inside adapt and think of ourselves in context to all that happened and all we know, playing out plans and how to move forward. If you think about it, whether you believe there’s another intelligent life in the universe or even other universes, we have not only contemplated the idea, we’ve moved on and continued as if this information is similar to what you’d expect to see exploring the savannah.</p><p>If you consider all this is how the 100 billion neurons process information and to derive consciousness which we sit stand on top, the intent to follow the well-trodden path to Artificial Intelligence is on the way as Computer Scientists lay down the groundwork of sense awareness like object detection, speech to text which goes on to understanding human language. Even though now most of these applications seem to come from an angle of a final product that would be useful to us like face detection, slowly in the background the plans are laid, the seedlings for General Intelligence which like us would get to pick and choose it’s own activation functions and slowly build it’s own intelligence.</p><p>I hope this has you excited because all signs point to not if but when and modest estimations seem to point to soon with some who you might say are overly too eager saying soon is within our lifetime, before the end of this century in some cases mid-century. It’s funny to think then that by 2050 while here we bickering about climate change, should we stop using oil and so on humanity in the background might be giving birth to a child, a baby who will astound us in every way imaginable.</p><p>Some skeptics are afraid this child in the machine would wreak havoc in our world because of so and so reasons, I’m not of that mentality for the following obvious reasons; <em>it’s within our nature to take advantage of the best options we have available. If you have skills you’ll work your way to the top and on the way someone will use your skills to make more money than you get from your skills, it doesn’t mean they don’t value you or your skills, it’s the quid-pro-quo of how the capitalist system works. I pull and help you on the way to the top, but I don’t do it for free.</em></p><p>This kid will astound the world and everyone who is in his inner circle as a new upcoming musician everyone will be on his side even if they want something in return, the only true question is whether this is a make it or break it session or letting a flower bloom on its own. That’s where dissent usually grows, that said it’s an exciting time to be alive, in this field where it normally just the drudgery of monotonous tasks there’s a horizon yet to be explored.</p><p>Article was written by <a href="https://thecoderr.com/">The Coder</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb2a0d6%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2Fb2a0d6%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href">https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11bb703d88a2" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/theory-of-intelligence-11bb703d88a2">Theory of Intelligence</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Theory of Intelligence]]></title>
            <link>https://medium.com/@muiruri.samuel/theory-of-intelligence-bb2a9714372d?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb2a9714372d</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 15:00:25 GMT</pubDate>
            <atom:updated>2019-03-27T15:00:25.297Z</atom:updated>
            <content:encoded><![CDATA[<p>Our Intelligence has always been marked as the pinnacle of evolution, mainly because nothing ever has come from nature that can outthink humans in terms of ingenuity. If you consider how intelligence evolved from microbes with no sense of self just following receptors on where food might be, then as the senses sharpened there came a need for you to identify the food and navigate to it at the same time ignoring and avoiding everything else.</p><p>Predators brought a new angle to this, everything mobile was a predator and at the same time prey for something else. With that instinct of prey and predators came the flight and fight response more so the flight response to either chase prey or flee from a predator, and as the organisms evolved to be more capable of fending off predators so came the fight response. This response is ingrained inside us, like hunger it’s a base feeling; <em>you don’t choose when and if you’ll get it, you only choose how to respond to it.</em> Like an alarm ringing inside you either check for fire or run out of the building;</p><blockquote><em>in a sense you could say the brave ones, are the firefighters, dealing with calculated threats, while the others take any risk as good enough to evade.</em></blockquote><p>This slow build up leads us to where we are today with our higher level of intelligence which started with an awareness of our environment and then more to ourselves, building on an understanding of how things works; mortality, seasons, taking care of yourself at the same time the next generation since even though in the animal kingdom there is no such thing as marriage some species do take care of their young and depending on what works, you can find the male can also be invested in making sure the offspring grows up.</p><p>We understand how we think, our motivation, fears, ambitions and how they all combine to form our personalities and continuously shifts and molds as things change. If you’re a hustler, you can’t expect to have the same mentality on things when you actually make it. Somethings will remain unchanged, others will change to align and adapt to the new world you live in. This is the inner brain model, <strong>The Biological Computer</strong> Scientists have been trying to figure out, and we aren’t there where we can create a duplicate process of human thought and ingenuity inside a PC, but we’re also not clueless on how it might be done.</p><p>Let me first introduce you to a few key concepts in Artificial Intelligence in particular Machine Learning and in comparison how the brain works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GYV1QIYrgt9fvaNX.png" /></figure><p>It’s said as a child grows up they have more neurons in the brain than an adult. As they learn and strengthen some neural connections, others dim and “fade away” as we come to an optimized connection of thought.</p><p>Starting with Biology, the brain is made up of about 100 billion neurons. The image above is an example of a single neuron. They connect to each other and send signals to each other. They have what’s called an <strong>Activation Function</strong> <em>a threshold where if stimulated past this point it will fire a response. </em>You could think of it as an example where a “pain receptor” distinguishes touch from actual pressure that exceeds the normal touch. There’s input that flows in from all our senses; sight, smell, touch, sound and this is sent from each receptor like the eye down a line of neurons to the brain which translates it to something knowledgeable and works from this information.</p><p>You, the conscious you is a hybrid of this process, like a program that runs on top of the other core features you get the information and you make decisions. The outcome builds trust in your decision-making skills and this becomes that inner gut feeling which you can’t control just “listen” to and whether you think of it as just an inner gut feeling or your subconscious mind. This is the persona, you can think of it as the <strong>Original You</strong>, a remnant of evolution who you have been paired with for better or worse.</p><blockquote><strong>Note:</strong> In medicine, they don’t actually call this an<strong> Activation Function </strong>the core logic still works as stated above.</blockquote><p>For example imagine you own a cat, like most cats they like meaty food, the meatier the better. One day if you decide right around the time you feed it to give it an unexpected treat you never do give, a slice of bacon, you’d not be surprised to see it greedily eat it all up. If you for some reason felt like overly spoiling the cat, maybe you just won the lottery and this is your only pet and it needs to know things have changed, the more pieces of ham you throw on the floor, the less excited it becomes.</p><p>The cat has a base instinct of hunger, in the presence of food this activation function the brain flairs up when it recognizes it’s in the presence of food. But the more it eats and gets full, that activation function gets squashed, <em>less activated. </em>the cat gets less enticed by the more bacon you throw its way. At a certain point when it’s full you could be in your zone just throwing bacon on the floor and it would look at it with little regard as if this means nothing to it. This is how the brain works.</p><p>If you think of this done another way, you “overfeed” it on normal cat food which I believe isn’t as good as bacon, <em>try and prove me wrong. </em>Then you gave it bacon when it wasn’t at all interested in any more cat food, the reason why it would consider this new snack as interesting is the activation function of hunger and desire to eat <strong><em>and</em></strong><em> </em>the food that it was first offered; cat food has basically been dimmed down to almost zero, it’s different for something else though, the offer of bacon.</p><p>For context, this kind of activation function would be like the Relu activation function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/0*d1b0gK20k0N1J-Gu.png" /></figure><p>It goes from 0 upwards, with 0 meaning you’re not hungry to upwards gauging the level of hunger. Though in reality since you can’t imagine an unfathomable hunger unless you experience it, a more realistic graph would be the sigmoid function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/0*lrah2DLEtp1OyRlu.png" /></figure><p>This is Sigmoid Activation function which moves from 0 to 1. Similar to how you could be full but you could eat a small snack in the that’s close to 1 but not 1 and somewhere on the lower side of 0.5 being the point you consider eating stuff you normally don’t like, for example food you think doesn’t taste good in this case.</p><p>The cat in the almost full level assesses the ham you just gave it after eating all the cat food it can eat but the ham having its own unique activation function, in the brain flairs up and the decision is made to eat the ham because it’s still very alluring at this point.</p><p>If you also offer it something it’s never eaten before, a new experience, this opening up a new pathway, so the cat will smell what you offered, tell if it smells good for starters since animals with such a keen sense of smell this is a key determinant of how it will act. Tasting before you swallow to tell how it tastes and then that get’s cataloged with the visual memory of what it’s seen. This is how the brain works.</p><p>We as humans have a dash of more complexity to ourselves starting with the fact we are in fact the most self-conscious beings on the planet. If you take any animal like an ape that can pass the self-awareness test that involved putting a mirror in front of it and give it time to realize what it’s looking at isn’t another member of its species but itself, where the ape will remain fascinated by this for who knows how long like revealing to the ape the earth is about this big and is a sphere and we are on a planet in the solar system in the galaxy with multiple galaxies in the universe and it might not be the only one, the only universe in the existence.</p><p>This isn’t a far stretch on my part, we acclimate and digest new information very fast, we’re not amazed by a mirror at all if only to know how I actually look and do I look okay to go out in public. We groom multiple personalities of ourselves; the image you see as I walk past you on the street, the subconscious part that will react to any small thing like someone saying “hello” as you pass by while your deep in thought, and the layers that show how we inside adapt and think of ourselves in context to all that happened and all we know, playing out plans and how to move forward. If you think about it, whether you believe there’s other intelligent life in the universe or even other universes, we have not only contemplated the idea, we’ve moved on and continued as if this information is similar to what you’d expect to see exploring the savannah.</p><p>If you consider all this is how the 100 billion neurons process information and to derive consciousness which we sit stand on top, the intent to follow the well-trodden path to Artificial Intelligence is on the way as Computer Scientists lay down the groundwork of sense awareness like object detection, speech to text which goes on to understanding human language. Even though now most of these applications seem to come from an angle of a final product that would be useful to us like face detection, slowly in the background the plans are laid, the seedlings for General Intelligence which like us would get to pick and choose it’s own activation functions and slowly build it’s own intelligence.</p><p>I hope this has you excited because all signs point to not if but when and modest estimations seem to point to soon with some who you might say are overly too eager saying soon is within our lifetime, before the end of this century in some cases mid-century. It’s funny to think then that by 2050 while here we bickering about climate change, should we stop using oil and so on humanity in the background might be giving birth to a child, a baby who will astound us in every way imaginable.</p><p>Some skeptics are afraid this child in the machine would wreak havoc in our world because of so and so reasons, I’m not of that mentality for the following obvious reasons; <em>it’s within our nature to take advantage of the best options we have available. If you have skills you’ll work your way to the top and on the way someone will use your skills to make more money than you get from your skills, it doesn’t mean they don’t value you or your skills, it’s the quid-pro-quo of how the capitalist system works. I pull and help you on the way to the top, but I don’t do it for free.</em></p><p>This kid will astound the world and everyone who is in his inner circle like a new upcoming musician everyone will be on his side even if they want something in return, the only true question is whether this is a make it or break it session or letting a flower bloom on its own. That’s where dissent usually grows, that said it’s an exciting time to be alive, in this field where it normally just the drudgery of monotonous tasks there’s a horizon yet to be explored.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb2a9714372d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PixelArt is now Live!]]></title>
            <link>https://medium.com/@muiruri.samuel/pixelart-is-now-live-ec63f167a70e?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec63f167a70e</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Mon, 04 Mar 2019 16:59:30 GMT</pubDate>
            <atom:updated>2019-03-05T06:55:11.702Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a project I’ve been working on for a while to give some context to it, here’s a couple of android apps that can do something similar</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*tRfOjbiyqI2wtety-hdZbg.png" /></figure><p>App name: Color Splash</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/143/1*GBs2S2RE1J2sRhLTB25zVg.png" /></figure><p>There’s more than one app with this name so the best way to know it is by its icon.</p><p>You upload an image, it first turns it to grayscale and then you choose which parts of the image you want to retain color by brushing with your finger on top of the image. You can also change the color by selecting the new color and still using your finger to color, it’s hard to be precise though on where you want the changes to apply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*7KC6QFSBUXhNTFjIAQ32Lg.png" /></figure><p>App name: Color Changer</p><p>App Icon:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/155/1*KLzuMOCTVRs9d2sye3dBbA.png" /></figure><p>Works the same way, though the UI feels a lot better and more intuitive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*5St0cd5N83LPbUv5jC3YeA.png" /></figure><p>App name: Color Splash</p><p>App Icon:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*c9320xNaFD8yOctBpw6PXA.png" /></figure><p>You still use it the same way but by far compared to the other two has the most user-friendly interface.</p><p>In contrast when I designed the part of PixelArt that would handle this feature what I had in mind was something to be a challenge to what Machine Learning was doing with coloring images, basically find out the process of coloring an image manually and see how this insight could be reverse engineered as I learned Machine Learning to coloring images.</p><p>Here’s an example from an actual demo screen recorded and available on <a href="https://www.youtube.com/watch?v=wmzVFlczlWU&amp;index=2&amp;t=13s&amp;list=PLXLFDHPJnWD-dJYgVYq9NMRIXuZyxVyRu">youtube</a> using PixelArt:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLXLFDHPJnWD-dJYgVYq9NMRIXuZyxVyRu%26start%3D13&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DwmzVFlczlWU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FwmzVFlczlWU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ca0a0baaaee0a2c2603d37fb7f5c82e/href">https://medium.com/media/7ca0a0baaaee0a2c2603d37fb7f5c82e/href</a></iframe><p>Before and After Pictures</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*3mtqR0oa5HxdNHWkjFIX8Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ObaUnHSjaIsSmIeRL9pRIw.png" /></figure><p>I already decided to make the code available on <a href="https://github.com/six-wars/pixelart">GitHub</a> and open source so everyone can use it. The youtube videos were taking it a step further so I can show you how to set it up locally on your machine. Finally, I’ve been working on putting this up live and I’ve finally done it and you can play with it <a href="http://pixelart.thecoderr.com/color-editor">here</a>, if your curious how to use it, just watch the youtube playlist as it covers the basics on how it works.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec63f167a70e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Edit an Image using Color Editor]]></title>
            <link>https://medium.com/@muiruri.samuel/edit-an-image-using-color-editor-ba2a06037d19?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba2a06037d19</guid>
            <category><![CDATA[art]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Wed, 30 Jan 2019 07:14:19 GMT</pubDate>
            <atom:updated>2019-02-01T06:23:49.112Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been working on a webapp which I Open Sourced called PixelArt with the first finished webapp inside called Color Editor. Here’s a few examples of what you can do with it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ObaUnHSjaIsSmIeRL9pRIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*3mtqR0oa5HxdNHWkjFIX8Q.jpeg" /><figcaption>Here’s an example of coloring a black and white image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*ba2rYObgN-0q0q-DTyuBjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*k7ZvhvRoeJB2Uobw3ouvjw.jpeg" /><figcaption>Here’s another example of coloring a colored image.</figcaption></figure><p>It’s running on Django using PIL to edit the images and Django as the website with the webapp has with javascript ways to send instructions to PIL on how to edit or color the image. Even though it does as expected, the selection process could take some additional improvements to make it simpler and more accurate and more importantly retain the selected area so if you want to try something out again you can use a pre-selection you made.</p><p>This series of videos will show you not only how it works and use it but also how to set this up on both windows and ubuntu.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLXLFDHPJnWD-dJYgVYq9NMRIXuZyxVyRu%26start%3D13&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DwmzVFlczlWU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FwmzVFlczlWU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ca0a0baaaee0a2c2603d37fb7f5c82e/href">https://medium.com/media/7ca0a0baaaee0a2c2603d37fb7f5c82e/href</a></iframe><p>If you want to know how it works it’s best to watch this and get the full idea, or you can start by checking out the <a href="https://github.com/six-wars/pixelart">github repo</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba2a06037d19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New Site]]></title>
            <link>https://medium.com/@muiruri.samuel/new-site-b0ede0ff73e3?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0ede0ff73e3</guid>
            <category><![CDATA[site]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Tue, 29 Jan 2019 11:37:08 GMT</pubDate>
            <atom:updated>2019-01-29T11:37:08.697Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve recently setup my own site <a href="https://thecoderr.com/">https://thecoderr.com/</a> taking into account when it comes to the blog the pro’s I’ve found using medium like adding gist code and the layout. So if you want to keep up to date with all my posts you can checkout the site, I’ll still try to post the really important/impressive stuff here. One by the way is coming up soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0ede0ff73e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stock Predictor using Keras]]></title>
            <link>https://medium.com/@muiruri.samuel/stock-predictor-using-keras-7d64b08c26d9?source=rss-3580abe7151f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d64b08c26d9</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Samuel Muiruri]]></dc:creator>
            <pubDate>Fri, 24 Aug 2018 12:28:30 GMT</pubDate>
            <atom:updated>2019-12-13T16:58:56.744Z</atom:updated>
            <content:encoded><![CDATA[<p>There’s two ways to predict a stock, one is predicting the actual value into an x amount of time into the future, which is usually graphed and this is mainly what you’ll see compared with the “actual value” which is mainly the test set vs. the prediction graphed, which usually is close to the actual graph, that’s the beauty of Deep Neural Networks.This is a regression model, it’s actually supposed to tell you the price of the stock on day X which is likely to be off by some amount, above or below.</p><p>It’s hard to ever get it to be exactly the same unless you intentionally or unintentionally overfitted the model to get high accuracy. The other model is a classifier which could for example predict from the Open Value: <em>the stock’s opening value </em>it’s going to go up or down by the end of the day.</p><p>Usually the stock data you can retrieve from a site like yahoo finance contain the following fields: Date, Open, High, Low, Close and Volume. There could also be Adj Open, Adj High, Adj Low and Adj Close. This are useful because something the company could to get more investors in their stocks i.e. <em>the price is considered too high </em>is split the stocks so that every stock now becomes equal to 2 stocks for example of even 4 there by decreasing the value of each stock by 1/2 or 1/4 respectively dropping the price but every share but each share holder’s total investment remains unchanged. This leads to an increase in the total volume but a decline in the Close value which alone might signify a drop in the value of the stock so Adj Close adjusts for this so the price is adjusted to the change in the Volume of stocks.</p><p>One way to get the model to understand time-series data which this is and keep some memory of the trend is using an LSTM model <em>“Long Short Term Memory”</em> Cell. I’ve not used this model and started with a simple CNN model <em>Convolution Neural Network </em>and it works just fine with a high prediction accuracy, I’ll highlight the issues though with it and a comparison with scikit-learn models.</p><p>Starting with the bitcoin data</p><pre>df = pd.read_csv(&#39;data/BTC-USD.csv&#39;)<br>df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*DjtY3VKGLibCHaklIJOjdA.jpeg" /></figure><p>What you feed a model are the data and what to predict, my intended model will only predict if the price will go up by the end of the day i.e. Open value vs. Adj Close value. Some of the fields aren’t useful to the model like the Date field, can’t also give the Close or Adj Close value because that’s basically cheating and also the Volume, High and Low since it’s only logical to assume these values are derived by the end of the day.</p><p>But what you end up with is only the Open Value and you simply can’t feed it that alone and the predicted Actual i.e. was Open &gt; Close or vice Versa 0 or 1 and expect it will learn easily so with some tinkering I can create some additional fields which look into the past to feed the model some additional info on top of the Open Value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab35ea522ec7b5e815bb93d167c8c128/href">https://medium.com/media/ab35ea522ec7b5e815bb93d167c8c128/href</a></iframe><p>This creates from the top Open 2 which is Open shifted up by 1 so you can compare yesterday’s open price to today’s. Max 7 is the Maximum figure from the Open column for the past 7 days, Min 7 is the opposite, Change is the difference of Open — Open2 and Mean Change 7 is the mean of the Change column for the past 7 days. All the rolling are for 7 days because of the 7 value used in the rolling column, it could be more or less but my assumption is if you know the stock activity for the past 7 days well enough you can know if things are going ok or not.</p><p>Drop 7 is the number of times the Change field has negative values i.e. compared to yesterday’s Open Value there’s a dip for the past 7 days. Up 7 does the opposite and finally Actual compares Open and Adj Close if there’s an increase that’s 1 otherwise 0 and this would include a scenario where the Open and Close price was the same, quite rare but still the point is to be blunt and only be interested in opportunities for profit or the inverse.</p><h3>Training the model</h3><p>First dropping the unnecessary fields</p><pre>df.drop([&#39;Date&#39;, &#39;High&#39;, &#39;Low&#39;, &#39;Close&#39;, &#39;Volume&#39;, &#39;Open 2&#39;, &#39;Predict&#39;, &#39;Prediction&#39;, &#39;Adj Close&#39;], axis=1, inplace=True)<br>df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*f1a4TmYZXe9CNxZGoXrhEw.jpeg" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e927d59c0721506b719f8e3f64903b9/href">https://medium.com/media/0e927d59c0721506b719f8e3f64903b9/href</a></iframe><p>From the top importing keras and some scikit-learn libraries that would be useful, next is using x_y to split the dataframe to X and y and then use scikit-learn’s train_test_split and just as an FYI when i use shuffle=False so it doesn’t shuffle the data I got an accuracy of 1.0 which if 100 which seems like it seriously overfit but the with shuffle it get’s 97% accuracy and this model also has EarlyStopping which avoids overfitting so when there’s no improvement for a limit of 25 cycles from the last noted best val_loss it stops training and uses that last training weight.</p><p>This is a really nice high accuracy which if it holds true would imply you could using this get a prediction whether you should expect the stock to perform well or not.</p><p>There’s also some additional testing I did using another stock record of apple and amazon comparing the bitcoin’s predictor predicting the whole after doing the preprocessing and adding the same fields as it the bitcoin and it would rarely get above 50% accuracy with the first try 45%. I also then made another predictor from the apple data which then get’s around 99% accuracy on it’s test data, trying to also compare it with the amazon stock returns similarly low score so the predictor isn’t universal i.e. it’s specializes to the stock data it was trained on. I don’t think this is proof of overfitting but how current CNN model works, they’re great a specializing and not generalizing so likely as an example a model trained to look at pictures and classify them when they’re always facing upwards would have an issue when the pictures start coming in upside down.</p><h3>Using Scikit-Learn</h3><p>Trying this also with the classifier of scikit-learn that I’ve found with the highest accuracy RandomForestClassifier below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e37705f56e61a1626c77d32c4877339/href">https://medium.com/media/5e37705f56e61a1626c77d32c4877339/href</a></iframe><p>Has an accuracy of 93% which is not higher than the CNN model still pretty close and showing also trying it on different data from a different dataframe also performs poorly.</p><p><strong>Proof of Concept</strong></p><p>First part in proving this is not an overfit model that’s mainly lucky is looking at the distribution of the expected answers: 1 or 0</p><pre>df[&#39;Actual&#39;].value_counts()<br>&gt;&gt;&gt;<br>1    1612<br>0    1341<br>Name: Actual, dtype: int64</pre><p>which are almost equal so a model that’s making blind guesses would likely average around 50% accuracy, on the other hand if the distribution was 80% - 20% then even mainly guessing the category for 80% or only that would assure a high score. So the 93% accuracy of the RandomForestClassifier must be good if it hasn’t overfit.</p><p>The stock market in my opinion is a semi-chaotic system; <em>it’s well known there’s chaotic system with some order inside of them </em>where small variation can lead to totally different results and even running the same model with the same initial conditions will always lead to different and even vastly different results but the underlying mechanics could be well understood but it makes accurate prediction impossible. This is why I’m wary of any model that could supposedly predict well into the future, even with a good understanding of the relationship between the data and outcome and given all the necessary variables a slight change in the actual real world data not modeled in the prediction model can lead to the graphs diverging easily.</p><p>Since the main thing a good stock predictor, as a person should tell you is whether you should buy or sell and know more importantly with a small window into the past <em>for the model </em>whether which of the two, to provide. To prove this model simply didn’t memorize the data or a pattern I’ve created this script to query the latest bitcoin value every 30 seconds and save the data so I can use this new data to confirm the final accuracy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d46e1a7aa0360893e8115726b0e80572/href">https://medium.com/media/d46e1a7aa0360893e8115726b0e80572/href</a></iframe><p>I let it run for a while and after it got enough info terminated the script.</p><pre>df.shape<br>&gt;&gt;&gt;<br>(261, 2)<br>df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*xssp2D7fAf1uG_ERwRnChA.png" /></figure><p>Applying the same preprocessing to create the necessary rows and the Actual row</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*bcf1QOcHpxTwjlvFabfzhw.png" /></figure><pre>df.dropna(inplace=True)<br>df[&#39;Actual&#39;].value_counts()<br>&gt;&gt;&gt;<br>0    134<br>1    120<br>Name: Actual, dtype: int64</pre><p>This also has an almost equal distribution of the values, instead of retraining I’d already saved the last classifier and simply loaded it again and made a prediction on the whole 261 rows.</p><pre>from sklearn.externals import joblib<br>joblib.dump(clf, &#39;data/bitcoin-predictor.pkl&#39;)</pre><pre>X = df[[&#39;Value&#39;, &#39;Max 7&#39;, &#39;Min 7&#39;, &#39;Change&#39;, &#39;Mean Change 7&#39;, &#39;Drop 7&#39;, &#39;Up 7&#39;]].values<br>y = df[&#39;Actual&#39;].values</pre><pre>from sklearn.externals import joblib</pre><pre>clf = joblib.load(&#39;data/bitcoin-predictor.pkl&#39;)</pre><pre>clf.score(X, y)<br>&gt;&gt;&gt;<br>0.9448818897637795</pre><p>With an acuracy of 94% on previously never seen fresh data this proves these model and machine learning models in general can pick up on underlying patterns in almost random behaviour.</p><h3>Getting back some returns</h3><p>There’s a comment of someone who suggested returns is the best way to prove it works, I created a stock_game where you can pick of a list of stocks like bitcoin, apple, amazon and with a player see how well you perform, you can start from day till the end of the stocks or input a start_date not to start when the value was too low and guarantee success as proof of good stock logic, anyway using this predictor I’ve created player_3 to play the stock_game for bitcoin. Mind you the best I’ve got with my <a href="https://medium.com/@muiruri.samuel/bitcoin-predictor-pt-2-a0ea7b436016">hard_coded</a> player_2 is $20.5 million, not bad from day 1 in 2010 and as I stated in the article linked you could say bitcoin matured somewhere in 2017 and since then the market has become volatile and since 2018 if you started then making profits is almost practically impossible, <em>if the value takes a huge dive nothing you do will make you recover your initial investment</em> and what you can hope for is remove some and keep some and hope it picks up beyond you’re initial investment value, the more it drops through this cycles, the more you lose, it’s simple economics math.</p><p>Anyway here’s the <a href="https://github.com/Six-wars/data-science/blob/master/stocks%20trading/Version%201.ipynb">source code</a> for the ipython notebook where all the magic happens and <a href="https://github.com/Six-wars/data-science/blob/master/stocks%20trading/game.py">game code</a> where the player_3 is defined. You can also review at the player code only below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eaa1cdfe8822defb2bf7241cd5f9b5b5/href">https://medium.com/media/eaa1cdfe8822defb2bf7241cd5f9b5b5/href</a></iframe><p>Using the predictor to get a prediction of an expected peak or drop and using what I used prior to predict dips or ups changed to an absolute <em>positive numbers only </em>and then use that to since it’s a digit the higher means the more positively bad or good expected trend <em>from the prior logic </em>to determine how much to withdraw or invest as a fraction of what already is invested or withdrawn and on hand, the game starts with an initial amount of $1000.</p><p>Just to note that some of this data was used in the training data but not all of it and the data was shuffled and 20% was reserved for test data, I also showed it did well on the new data, anyway that’s what you hope it should do anyway, learn.</p><p>First from day 1</p><pre>player_3(output=False, plot=True)<br>&gt;&gt;&gt;</pre><pre>You have 727.2 invested, you want to withdraw 1027.948007299304 which exceeds the amount available, try again with a smaller amount<br>Reached the final day, game ending<br>day: 8/6/2018 profit: 0 loss: 258375.57425815985 amount: 232721919.09876847 invested: 7519133.58425816</pre><p>This makes a total net of $240 million; $232 million amount <em>withdrawn </em>and $7 million in bitcoin invested, from the initial $1000, you can see the graph below with the investment curve, amount curve and the bitcoin Value in USD chart almost a straight line compared to the large digits of the other two line charts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hcKSa1OmUSaeooTbWluSHA.png" /></figure><p>As usual I’ve also started it from far later in the start of 2017</p><pre>player_3(output=False, plot=True, start_date=&#39;1/1/2017&#39;)<br>&gt;&gt;&gt;<br>Reached the final day, game ending<br>day: 8/6/2018 profit: 0 loss: 4.989760121705757 amount: 4496.844152819358 invested: 145.28976012170577</pre><p>This makes far less with from the same initial $1000 to almost $4500, as you can see in the graph below now the value which starts as higher than the initial investment is never overtaken by the amount the user makes and as should be expected there’s a high correlation of making wise investments based on the market.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1FSz9UDWm6Ga7ExocO9xA.png" /></figure><p>The last one is from 2018 which not a suprise for me ends with less; 660 in the amount and only $20 invested in bitcoin.</p><pre>player_3(output=False, plot=True, start_date=&#39;1/1/2018&#39;)<br>&gt;&gt;&gt;<br>Reached the final day, game ending<br>day: 8/6/2018 profit: 0 loss: 0.734349262121448 amount: 660.2833935348347 invested: 21.33434926212145</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZH5fJj0Gd1KE8XzBNksUvA.png" /></figure><p>If someone tells you bitcoin is doing well show them this chart from the begining of the year.</p><p><strong>Update</strong></p><p>So I’ve decided to work on the stock predictor on a real-time basis and make it a live, interactive system anyone can use for free. So far I’ve got a working version with impressive results and a way to showcase not only how it predicts from live data every minute it also uses the information shown to give you an accuracy based on this and info of what action it’s taking whether it’s buying or selling stock. You also have the graph data to see how it performs over time and the option to review multiple stocks from the NYSE.</p><p>You can check it out here: <a href="https://thecoderr.com/stock-predictor">https://thecoderr.com/stock-predictor</a></p><p>And see the latest video I’ve made on how it works below</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZBLV4Nf68sw%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZBLV4Nf68sw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZBLV4Nf68sw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9853a51ad188380ac19e3a1200036c65/href">https://medium.com/media/9853a51ad188380ac19e3a1200036c65/href</a></iframe><p>If you want to support my work, you can do so using paypal below.</p><p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=R526VEHV4T5LA&amp;source=url">Donate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d64b08c26d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>