Tuesday 2 January 2018

Imitation Game

Think of a number in your head. It could be anything from 0-9. Got it? Good.

Now let me guess what number it is.

First, I'll present you with ten random numbers. They are 3,3,1,4,9,7,8,4,3,1






Did the number on your mind appear in the list? Shout out '1' if it did!
It didn't? Oh well, reply with a '0' instead then.

Let's take a number for demonstration. We'll go with 5 as it didn't appear on the list. In accordance to the rule, at no time should I reveal the number on my mind, but instead let my computer figure it out on its own by feeding it '1's (if my numbers appeared in abundance) or '0's (if it did not)


I chose to input 0 on the first entry as my desired number did not appear on the list. Immediately on the second list we see the number '5' popping up.


By encouraging the computer with '1's when the number 5 is in abundance, it took the hint and increased its preference towards the number

The dominant guesses are now between 4 and 5


4s seems to slowly overtake 5s, so I fed it with a '0' as I am not satisfied with the computer's divided guess. On the following list, we can see the computer went with the number 5.




Slowly, by rewarding/punishing my computers with 1s(which it likes) and 0s(which it tries to avoid), it made out my intention and guessed the number 5.

Voila! A program that knows what's on your mind. Granted it is not the brightest at the game, and requires an average 15-20 inputs to arrive at an accurate guess, but nevertheless this simple app demonstrated an inherent ability to learn and adapt to the user's input.

Here's my goal: To keep the number of guesses down to 5-10. I'll keep you posted when I stumble upon an algorithm that allows for that level of quick learning.

Source Code (Python): https://github.com/ImSandwich/AI-Code-Projects/blob/master/learning_agent.py

To test the code for yourself, simply:
1. Download and install Python 3.6.x from https://www.python.org/downloads/
2. Download the source code
3. Open up Command Prompt
4. type cd [the folder you downloaded the source code to]
For example: C:\Users\User\Desktop\Code Projects\
5. type python learning_agent.py

Enjoy! All feedback and suggestions for improvement is greatly welcomed =) Peace out.


No comments:

Post a Comment