Showing posts with label Neural Networks. Show all posts
Showing posts with label Neural Networks. Show all posts

Saturday, June 11, 2011

One day PyBrain came to power....

Recently, I went straight away to PyBrain and found it is useful to AI researchers and enthusiasts. Python rocks once again. PyBrain is a modular library for python. As far as PyBrain developers is concerned, it is Python Based Reinforcement Learning, Artificial Intelligence and Neural Network Library. PyBrain is opensource and it is licensed under BSD software license.
PyBrain simulates neural networks inside our brain in a computer. Once you created the neural networks, you need to train it for a particular task. Sometimes training of more than thousand times is required to properly get done it's job. Sometimes, training will be frustrating especially when you didn't give proper degree of freedom to the neural network structure. However, I found pyBrain interesting.
It is good idea to start with pyBrain documentation. In the beginning of the tutorial, they provide a simple example of training for an X-OR gate. But it will take a lot of training steps to work properly. But for the same neural network structure, if you are trying to simulate an AND gate or an OR gate, you probably get everything done.

Wednesday, March 9, 2011

Story of a 'spinning lady'


Did you notice the figure above? To see the spinning lady, click this link and return back. Is it a spinning lady? In which direction, you feel the lady is spinning? clockwise or counter-clockwise? One can feel the spinning of the lady in either clockwise or counterclockwise. But once you feel lady spin in one direction, your brain continues in that state and insist to be in that state. If you feel that the lady is spinning in clockwise, it is too difficult to see the motion in counter-clockwise direction. But sometimes our brain switches from one state to other state automatically, but changing the state of feeling of brain is difficult to achieve manually.
This is a beautiful eye illusion. Do you know how that beautiful lady, cheated your brains?
Answer is, the lady didn't cheat you, but the cheater is her shadow. Actually, the image shows the shadow of a spinning lady. In this, a 'shadow' plays in important role in cheating you. The pure shadow of an image will not provide the entire information about an object to the brain. From a shadow, we can't predict whether the front side or backside of the object we are viewing. If you didn't understand what I just said, please go through an example.
Look at the picture below.
The middle picture is photo-shot of the spinning lady. Concentrate on the picture and tell what you are viewing- the frontside or backside? It may be both. Look at the left picture. It is the modified version of middle one by adding eyes in her face. Now you feel that you are viewing the front side of the lady. At the same time, you see the backside of the lady in the right picture, but that also a modified version of middle picture with marking of a hair bud. This is important to be noted. While you are viewing the middle picture only, your brain fall in to the mess of finding whether the shadow is of the front side or backside. Then your brain 'randomly' choose one possibility (not actually). But in other pictures, your brain has powerful proof that indicates the state of the lady's body.
Now the problem associated with the spin direction of the lady is not vague. If your brain 'assumed' a side of the lady's body you are viewing, this will determine which direction, she is spinning.

Wednesday, December 23, 2009

How do we think? A brief introduction

Thinking about how we think is difficult, because thoughts of thoughts are limited by thoughts itself. But learning of how we think is essential in computing as well as AI powered robots. The basic reason of our thinking ability is a special type of cells in brain - neurons. A neuron is not perfectly known to human yet, but many similar models are proposed. The power of neurons is in its networking ability. Neurons are connected to each other and these complex networks may called as neural networks. I am not describing much about neurons because it is beyond our task. It's well enough if you just get an overview from Wikipedia. As I said, many convenient models are there to explain the behaviour of a neuron (Of course, a networked neuron is complex than a single one), but I am just touching simplest one named Perceptron. I will also mention back propagation during the example. I have pasted one figure from Wikipedia because you need it.The area in the shaded square can be considered as a neuron. x1,x2,......x7 are the inputs and w1,w2.......w7 are the corresponding weights (I will tell you what it is). and f is simply a function and outputs y. If the weighted sum of the inputs exceeds a particular threshold (which is previously be set), output y fires out. In actual neurons, y depends on other parameters such as input frequency. Since whole process in actual neurons are chemical, the explanation become rather complicated. But in all models we consider input as well as output signals are electrical in nature.I am explaining once again: first find
x1*w1+x2*w2+.........+x7*w7
If the resultant value is greater than a threshold (Typically 0), y=1; otherwise y=0.
I hope you understand something. But I know most of you are not satisfied because, you don't know what is really going on! Right?
Let me tell an example. This is a story. Here is you, Heroin is you.
Consider you have three friends and you(your brain) thinks that they are:
  • Albert - Your best friend. You have a confidence level of 0.7 on him. You trust him and ask his opinion before every important attempt
  • Deepika - Your classmate. Confidence level 0.3. Good personality.
  • Tom(me) - Confidence level of -0.55. Always say lie. Cheating personality.
These prejudice are taken by your brain from your experience. May be true or may not be.
The problem starts here. You are getting ready to go to your office/college. There are two ways to go. One is short path (easy way). Other is long. But short way has a problem is that sometimes it will be blocked. If you take the long path, you may reach the destination late. But if you choose the short path and in any case if blocked, you can't reach the destination on that day.
Then you come to know that today short way will be blocked. Then you consult your friends. Check their opinion:
  • Albert - Short road is not blocked. Damn sure.
  • Deepika - Someone told me about it. Short way may not be blocked. But I am not sure.
  • Tom - Hey man, road is blocked.
Can I go straight away through the short path?
Let's look how your brain solve the problem. Albert surely says that road is not blocked. Put a value of +0.95 for his opinion. The positive sign indicates that he is opposing. If Albert says sure that road blocked, the value may be -0.95. You don't know much about Deepika. But she may be right. Put a value of +0.1. Tom says it is blocked. So put -0.8.
Here threshold value is 0. If weighted sum is greater than 0. road is blocked. It is good to choose the long way. I not, road is not blocked, choose the short path.

Weighted sum is:
signal strength of Albert * confidence level+ signal strength of Deepika * confidence level+ signal strength of Tom * confidence level
=0.95*0.7 + 0.1*o.3 + (-0.8)*(-0.55)
=0.66+0.03+0.44
=1.13 which is greater than 0.

The brain successfully derived a decision for you. It is almost sure that road blocked with a confidence level of 1.13. Did you notice the analysis of Mr.Tom's opinion. You think tom is cheat. So the opposite of what he tells will be right. If you didn't understand the meaning of previous sentence just read one more time because some interesting things hidden in that sentence.

Ok, let's continue our story. Then you started going straight away through short path. You started journey in your own car but Alas! road is blocked. You couldn't just believe your eyes. but suddenly you realize the fact that you can't reach your destination today - you trapped in a huge road block.
Here, your brain attempts to rewire the entire circuitry inside it. Your thoughts were entirely wrong. Both Albert and Deepika was wrong, but Tom was right. You change the congedence level as,
  • Albert - 0.4 - I can't blive he cheated me.
  • Deepika - 0.1 - no coments.
  • Tom - 0.2 - oh, sorry Tom.
The actual working principle of neural networks is far deviated from the above story, but the fundamental thing in both is same. Actual neurons has a lot of diifernces and complexities than the neuron models

Sunday, December 6, 2009

Don't believe your eyes!


Don't believe your eyes, because everything you see, touch and feel is just a feeling only. Consider you are traveling in a space ship. No way to look outside. Space ship is traveling with higher velocity. If there is an obstacle present in front of the spaceship, sensors feel the presence of obstacle and it is reported on your computer. Then you turn the spaceship left or right. Then sensors feels that obstacle is removed (not obstacle, you!) and computer indicates that you can go straight way.
The above explained is a successful turning. But here I go in a something different way. The sensors are intelligent enough to send a fake signal that "there is some sort of obstacle" on the monitor. Actually, there is nothing in front of it. But your computer shows some obstacle. So you put a signal to turn right. Then the sensors shows that "now obstacle is removed. Go straight". You feel that you done well, but the sensor and the computer system really cheated you. Sometimes it was not a cheating, because ,there will be a possibility of thinking that there is an obstacle.
Our brain is not much different or error free in similar cases. If you are think that you know the universe, I think it is actually bad. Things you feeling from the surroundings may be different from reality. Your eyes are similar to the spaceship sensors. Not only your eyes, every sensors just see one phase of the reality. That really implies that knowing reality is too difficult.
I am not going too inside. I am not a philosopher. So let's have a fun. just go thruogh this link. A number of good eye illusions are included. Here I give a puzzle from eyetricks.com - Find which is longer?

Monday, September 14, 2009

Battle Game - The computer thinks!

Recently I built a game and named 'Battle' as a consequence of my studies in the field of artificial intelligence. As a first step, I built a mathematical model instead of more flexible neural network model. The work on neural model is on the way and the work is very slow. The mathematical model also not much efficient but I took care to make the program 'act' as intelligent (I know intelligence is needed to act!). Rarely the program may crash. I not interested to make this game for commercial use and I am givin it under GPL. The program is not much pretty both in efficiency and it's intelligence. Since I am not a proffessional programmer, the rules for a good program may not be satisfied. I compiled it in C++, but the entire structure is like C.
The game is like ordinary 'Tic Tac Toe'. but has a little difference that maximum number of players is limited to 3 and If you placed your all three players, you can move them to adjacent places to align the players in a line. For the simplicity of learning the game I have put a video of how to play the game.



I have built a Qt (which is cross platform) GUI for my game for beginners but have put also the CUI mode game for code diggers. Even though this game is not intended for entertainment surely it provide some entertainment if you read the code. I need you comments to speed up the development of neural model of the game. I did all the work in win32 platform and linux users also can compile the code because, Qt is cross platform. But you need to install Qt on your distro.
Here's the download links:
GUI BattleGame (Recommended)
CUI version 1a.0
CUI version 1b.0