Monday, May 28, 2012

Artificial Intelligence v/s Developer Part 2 - Why somebody invented the concept of random number?

Artificial Intelligence v/s Developer Part 1 - What the hell is this?
Artificial Intelligence v/s Developer Part 2 - Why somebody invented the concept of random number?
Artificial Intelligence v/s Developer Part 3 - Sensing & acting / IO devices and communication.
Artificial Intelligence v/s Developer Part 4 - Multi-core processors,MapReduce & Hadoop
Artificial Intelligence v/s Developer Part 5 - Are you ready to do some AI apps like this?

As a developer with at-least 2 years of experience in the software industry, you should have used the random number generation 2-3 times. What is a random number is not at all a question.Its simple as a random number as per the name. But what is the importance of a good random number generation algorithm in computer programming?

Answer is simple .It helps the program to take a decision .I am not sure yet about whether we should call that as AI because that is some sort of decision making. If you are still confused about random number generation and decision making let's take an example of a small shooting game.

The rules are simple as shooting the red bubbles coming from the top of the screen.If we shoot the green bubbles we lose some points. Coming to the programming ,how program decides what should be the color of the next bubble coming from the top? We are inside an infinite while loop and need to put a bubble at the top.Can it be a Boolean variable which flashes and helps us to put bubbles in an alternative way ie red then green then red etc...There is nobody stopping us .But if we implement like that, the player seats will be empty. Nobody will play twice.If you are developing for the sake of developing you can go ahead with that. But if you ask me, I will never develop for the sake of developing .I always need users who use my program.

That means the Boolean concept is rejected.What about deciding color based on the current time.seconds along with a delay based on the same second.ie red if the second is odd else green. Little more better in terms of keeping players in seat. If you think more you will surely feel, this is not something I needed. I want to give it an actual feeling of human throwing bubbles which plays like opponent of the player. How can I achieve that ? I need to get a random number and combine with current system variables such as position of the gun etc...to decide on the color and decide on the horizontal position in the screen from where the bubble should come.

This means apart from helping the program to take decisions the random numbers give a feel of computer as human.

What is a good random number generator?

Again a definition "Random number generator should give a random number like how human guess a  number and tell the same to another one". There are so many methods out there which are widely used in random number generation but I like the physical random number generation most as it depends on the physical condition rather than any algorithm or the current time of the system.

Random numbers in AI

Since AI needs same behavior as human intelligence it needs a good random number generator to achieve the tasks such as decision making, decision re-evaluating etc...

If we look at the decision making process we cannot find the need for a random behavior at first. But if we reach to a situation where none of our experience in the knowledge base help us to respond to a given situation, we should create a random decision and experiment with that. Also if there are 2 choices with same weight /rank the system need to choose one based on random number. Isn't it same in case of human intelligence? If we are planning to buy an android mobile and there are 2 matching our requirements including the price,feedback ,company etc... we normally buy one by random selection.Some people even go to the extend of asking his best friend to touch one finger where he had assigned one mobile to each finger. Isn't it a use of random number usage in human intelligence? If you had read my first post about AI and comparison of possessing intelligence like a child, you can easily understand the importance of random behavior.

But over the time the need for random behavior will come down because if the system is in operation for long the knowledge base will get bigger so that the situations which are not in the knowledge will be rare.

Will I be using random numbers directly ?

Never. Because you will not be keeping a list of actions which you can index directly using a random number. Instead it should be some sort of genetic algorithm where the fitness function of selection is based on the random number. This brings random combinations of genes which gives different behaviors.

Hope this gives you the idea that random behavior is a key ingredient in real intelligence which we cannot avoid when building an artificial intelligence system.

Tuesday, May 22, 2012

For fresh programmers

This post is dedicated to fresh programmers. You can’t find anything related to a specific technology here. This contains some guidelines and links, a fresher should look at before he start his programming career. When I started my programming life there were no such chance to get these kind of guidelines as internet itself was too costly and there were not much blogs. When I said I started career it refers to my college days not the time when I joined my first company. I believe everybody agrees with me on my statement

“We start our programming career when we join college after selecting computer software development as primary subject”.

But in India I have seen companies taking employees or people joining software development companies without having the knowledge to write a for…loop.


You are the master of computer. Rule it


When a person starts with computer the first thing he learns is, it has 3 units .Input unit ,output unit and   CPU. Then he learns that computer has no intelligence or it don't have any capability to decide and do things of it's own. Whatever computer does is per the human instructions called computer program.

But most of the professionals will forget this after they became programmers. We could understand their change when they start complaining like "it works sometimes" or "I coded it well. I don't know why it is not working". Do you think the computer is injecting it's own code in to your code in order to take revenge on you? Absolutely not. So keep in mind that computer is a silly slave which works as per our instructions and you are the master.

Computer understands only binary instructions ie assembly language


You may using Visual Studio 2010 /2011, Eclipse, XCode or JBuilder for creating your apps. If you are using LightSwitch you may not have written single line of code to produce a business app. But remember what ever program you created, is going to execute using assembly instruction such as Mov A,B Add A, Push, Pop etc... If you don't have this basic idea about how a computer really process your program it would be really difficult to survive in the field of debugging and performance turning. Also you should have an understanding about how your managed frameworks such as .Net or Java convert the intermediate code to machine code to be executed by the machine.

Attend trainings & train others constantly


Like all the other professions software development too changes its way of doing .Also it changes it's tools and targets. But in programming the rate of change is really fast and if you need to stay with that you should always open to learning. If you think that I studied everything from college and can say bye to learning, please don't enter to the software development industry.

Are you confused and thinks that I selected a wrong path? Before answering it let's take the field of automotive. Centuries back, there were steam engines .The engineers at that time had to deal with steam engine's internals. Later the petroleum based engines came and they all had to learn the technology of petrol and diesel engines. Now we are in the age of electronically controlled hybrid engines and battery based vehicles. If you look at the tools, the manual screw driver is replaced by electronic screw driver.Also the targets, earlier there were only cars now we have hundreds of types and models of vehicles.

Don t' you think that, this is same as software development except the rate of change. We had big room full of machines first. Then it came to desktops,laptops and now to tablets and mobiles.In other industries it will take decades for a change but in software development its couple of years .Another field which we can compare with programming is the medical where doctors had to learn about new diseases and diagnostics tools every year.


so never miss a chance to attend a training or train others. At-least attend online training. If you are not a good speaker and afraid of talking in front of a big crowd start training your team which is comparably small. When you train somebody you will at-least learn 2-3 new things which you may had missed earlier because each individual thinks and asks differently.

Also read the books .Don't depend only on online media. Books give you vertical in-depth knowledge about the subject where internet blogs and search can only give you horizontal knowledge.

Be a blogger


Now a days without google developers cannot proceed further. In one way its true and should be like that because why should we memorize all the APIs of different languages which are going to be replaced by another set in next 5-6 years. Being in this context we need to think about one thing.

Where from the contents in google search comes from? Is Google creating contents by employing typists? No.Its due to the other fellow developers and their kindness to share their knowledge through blogs and tutorials. Are they just simply sitting and thinking about some scenarios and blogging the same ? 90% are not. They just share their day to day experience with programming and we are making use of it. If they had thought of completing their works and enjoy rest of the time we can never enjoy our life. Isn't it?

Same way think about new developers coming into our way. Do we need to make their life harder? If not please start blogging. Or post articles and tutorials. Don't say that I don't have topics. If you work 40 Hrs per week you might have come across at-least one situation which will help others in future. Write about it. Initially your language may not be good. But over time you will became a good writer. If you are looking to monetize your writings time just put google ads in your blog.

Read, debug and make use of other's code

One of my colleague always want's to code himself. When he wanted to try AI he started writing his on AI program using if...else which acts like any other publicly available AI chat programs. It's good that he wants to write himself which will help him to learn. But whether he really need to write himself where AI chat programs are available in open source such as AliceBot ? According to me as a smart programmer we should make use of other's experience.

The main advantage of using other's code is, they might have faced so many hard situations and resolved the same.Why should we face the same situations again? Another advantage is we could learn better ways of programming by looking at other's code or we can mix their coding style with ours to create a better one.So keep reading, reviewing and understand by debugging other's code

But be careful. Before using public code, read and understand carefully. Sometimes they may be less efficient than you. Also after adopting their code, don't say "Oh its not my mistake, it is the bug in their code".Keep in mind, once you adopt, that's your code.

Some sites you should really look into


These are some sites which I feel a developer regardless of your experience should read.
http://samizdat.mines.edu/howto/HowToBeAProgrammer.html
SOLID Principles

Site for non-software people to learn programming
Learn coding - http://www.codecademy.com/

Books to understand basics
Code By Charles Petzold - Explains the evolution or computer and programming from basic electronics to assembly language & high level language.
Head first Object Oriented Analysis and Design

Monday, May 14, 2012

ASP.Net MVC 3 : ActionResult to return primitive data type as view

There were some requirements couple of weeks back which needs to return 'true' or 'false' from a MVC action based on some conditions say user has alreay registered or not. I first searched for any built-in PrimitiveResult in MVC 3 framework. But not able to find suitable one. Tried to write one myself. But before that I thought I should check for any other way to avoid reinvention of the wheel :-). That made me start digging about the ViewResult where we can return anything without type checking. Yes that worked and below are the steps to have a ViewResult which returns primitive types as string.

Action which returns the ViewResult with the primitive type as model


Just look at the code

        public ActionResult TestPrimitiveResult(string id)
        {
            //This action just returns the input param as it is .You can have your own processing.
            double resultDouble;
            bool resultBool;
            ActionResult result;
            //Uses primitive type as model.
            if (double.TryParse(id, out resultDouble))
                result = View(resultDouble);
            else if (Boolean.TryParse(id, out resultBool))
                result = View(resultBool);
            else
                result = View(id);
            return result;
        }

View which renders the model without master page or any other html element


Had to struggle little bit here as I was not familiar with how to avoid the influence of master page which was mentioned in the _viewstart.cshtml .Its simple..

TestPrimitiveResult.cshtml

@{
    //Removes the effect of master page.
    Layout = null;
}
@*Returns the primitive data value*@
@Model


Now I am almost in a stage like any other MVC developer who thinks Asp.Net web application should be done through MVC only.ie ASP.Net web application => ASP.Net MVC.
Happy coding...

Monday, May 7, 2012

Android designer - Online & offline

Came to an online designer for Android applications. They have the standalone version as well. Noway we can compare this as VisualStudio & Expression Blend partnership for WPF and Silverlight apps.

Seems Eclipse is better than this designer sometimes.
http://www.droiddraw.org/