Monday, April 30, 2012

MiniMax And Alpha Beta Pruning

Minimax : Minimax (sometimes minmax) is a decision rule used in decision theory, game  theory, statistics and philosophy for minimizing the possible loss for a worst  case (maximum loss) scenario. Alternatively, it can be thought of as maximizing  the minimum gain (maximin).


Problem 1 with Solution:


How it Work :


Step 1 : From 3,12,8 value 3 is the most MIN value so in first step it takes value 3 .


Step 2 : From 2,4,6 value 2 is the most MIN value so in first step it takes value 2 .


Step 3 : From 14,5,2 value 2 is the most MIN value so in first step it takes value 2 .


Step 2 : From 3,2,2 value 3 is the most MAX value so in first step it takes value 3 .


Problem 2 with Solution:



How it Work :


Step 1 : From 6,4,10 value 4 is the most MIN value so in first step it takes value 4 .


Step 2 : From 3,8,7 value 3 is the most MIN value so in first step it takes value 3 .


Step 3 : From 9,1,12 value 1 is the most MIN value so in first step it takes value 1 .


Step 2 : From 4,3,1 value 4 is the most MAX value so in first step it takes value 4 .




Alpha Beta Pruning :  In AB Pruning it is possible to ignore entire sections of the search space and come up with the same answer. If a line of play leads a worse position than another one that already discovered , then it is not necessary to explore that line anymore. 


Problem With Solution : 






I have found this video which is well defined for solving Alpha Beta Pruning Problem. 

Genetic Algorithm Problem With Solution

    Genetic algorithms (GA) were formally introduced in the United States in the 1970s by John Holland at University of Michigan. The continuing price/performance improvements of computational systems has made them attractive for some types of optimization. In particular, genetic algorithms work very well on mixed (continuous and discrete), combinatorial problems. They are less susceptible to getting 'stuck' at local optima than gradient search methods. But they tend to be computationally expensive.
    To use a genetic algorithm, you must represent a solution to your problem as a genome (or chromosome). The genetic algorithm then creates a population of solutions and applies genetic operators such as mutation and crossover to evolve the solutions in order to find the best one(s).

    Genetic Algorithms (GA) use principles of natural evolution. There are five important features of GA:
     
    Encoding possible solutions of a problem are considered as individuals in a population. If the solutions can be divided into a series of small steps (building blocks), then these steps are represented by genes and a series of genes (a chromosome) will encode the whole solution. This way different solutions of a problem are represented in GA as chromosomes of individuals.


    Fitness Function represents the main requirements of the desired solution of a problem (i.e. cheapest price, shortest route, most compact arrangement, etc). This function calculates and returns the fitness of an individual solution.
    
     Selection operator defines the way individuals in the current population are selected for reproduction. There are many strategies for that (e.g. roulette–wheel, ranked, tournament selection, etc), but usually the individuals which are more fit are selected.


     Crossover operator defines how chromosomes of parents are mixed in order to obtain genetic codes of their offspring (e.g. one–point, two–point, uniform crossover, etc). This operator implements the inheritance property (offspring inherit genes of their parents).

   Mutation operator creates random changes in genetic codes of the offspring. This operator is needed to bring some random diversity into the genetic code.In some cases GA cannot find the optimal solution without mutation operator.

Problem :

Solution : 


               Given Information :
                                              Four integer coefficient varying in between 0 to 9. [Correction on Question from three int to four].  a0,a1,a2,a3. 


                                             Function Y =  f(x)  =  a3x^3 + a2x^2  + a2x +a0


                                             Y follows
                                                             x :  1  2  3
                                                             y :  7  6  2
                                             Fitness of  Y  =
                                                          
                                                                       
                                             In Generation 0 :  Chromosome set [  0  |   0  |  0  |  0
                                             
                                             Population Size is four

                                              0  |   0  |  0  |  
                                             [  0  |   0  |  0  |  
                                             [  0  |   0  |  0  |  
                                             [  0  |   0  |  0  |  
                    
Finding Out Generation 1 :

Fitness :                                            

               y1 =  Use the fitness formula of Y
                    = 0.002624 [As all value are same make highest value from first]  [first highest]


               y2 =
                    = 0.002624 [second highest]


               y3 =
                    = 0.002624 [third highest]




               y4 = 
                    = 0.002624 [fourth highest]

Selection :

     As it is said that 2nd highest and 2nd lowest value will be a pair and other two will be other pair. So after selection data will be like below : 

                 y2  = 0.002624 [second highest]  ==  0  |   0  |  0  |  
                 y3  = 0.002624 [third highest]      ==  0  |   0  |  0  |  
                 
                 y1  = 0.002624 [first highest]       ==  0  |   0  |  0  |  
                 y4  = 0.002624 [fourth highest]    ==  0  |   0  |  0  |  
Crossover :
                
    In question it was predefined to swap the left most bit of chromosome . So  , after swapping the left most bit of chromosome :



                 y2  ==  0  |   0  |  0  |  
                 y3  ==  0  |   0  |  0  |  

                 y1  ==  0  |   0  |  0  |  
                 y4  ==  0  |   0  |  0  |  


Mutation: 


   One bit is selected randomly. The selected bit is incremented or decremented with at most 2 . If the result of mutation make  a bit larger than 9 , the value of the is set to 0 and if smaller than 0 set to 9. And no chromosome is permitted to apper more than in each generation.


                 y2  ==  0  |   0  |  9  |  ]         [ Select 3rd number bit  and do -1 ]
                 y3  ==  0  |   1  |  0  |  ]         [ Select 2nd number bit  and do +1 ]

                 y1  ==  0  |   0  |  0  |  2 ]         [ Select 4rd number bit  and do +2 ]
                 y4  ==  2  |   0  |  0  |  0 ]         [ Select 1st number bit  and do +2 ]

Generation 1 is :



                             0  |   0  |  9  |  ]
                            [  0  |   1  |  0  |  ]   
                             0  |   0  |  0  |  2 ]
                             2  |   0  |  0  |  0 ]

And Generation 1 is the population for finding out Generation 2.


Finding Out Generation 2 :

Fitness :                                              

               y1 = 
                    = 0.002688 [third highest]

               y2 = 
                    = 0.002700 [second highest]

               y3 = 
                    = 0.002610 [fourth highest]


               y4 = 
                    = 0.006134 [first highest]

Selection :

     As it is said that 2nd highest and 2nd lowest value will be a pair and other two will be other pair. So after selection data will be like below : 

                 y2  = 0.002700 [second highest]  ==  0  |   1  |  0  |  
                 y3  = 0.002688 [third highest]      ==  0  |   0  |  9  |  
                 
                 y1  = 0.002610 [fourth highest]    ==  0  |   0  |  0  |  2 
                 y4  = 0.006134 [first highest]       ==  2  |   0  |  0  |  


Crossover :
                
    In question it was predefined to swap the left most bit of chromosome . So  , after swapping the left most bit of chromosome :



                 y2  ==  0  |   1  |  0  |  
                 y3  ==  0  |   0  |  9  |  

                 y1  ==  2  |   0  |  0  |  2 
                 y4  ==  0  |   0  |  0  |  


Mutation: 


   One bit is selected randomly. The selected bit is incremented or decremented with at most 2 . If the result of mutation make  a bit larger than 9 , the value of the is set to 0 and if smaller than 0 set to 9.And no chromosome is permitted to apper more than in each generation.


                 y2  ==  0  |   1  |  0  |  2 ]         [ Select 4rd number bit  and do +2 ]
                 y3  ==  0  |   0  |  7  |  ]         [ Select 3rd number bit  and do -2 ]

                 y1  ==  2  |   0  |  1  |  2 ]         [ Select 3rd number bit  and do +1 ]
                 y4  ==  0  |   0  |  2  |  0 ]         [ Select 3rd number bit  and do +2 ]

Generation 2 is :



                             0  |   1  |  0  |  2 ]
                             0  |   0  |  7  |  ]   
                             2  |   0  |  1  |  2 
                             0  |   0  |  2  |  0 ]




Continue to do same process depending on how many generation you have to find out. 



Monday, April 23, 2012

Distinction Between a class and an object

A class creates a new data type that can be used to create objects . All of us know this  but a class creates a logical framework that defines the relationship between its members . When we declare an object of a class, we are creating an instance of that class. Thus , a class is a logical construct . An object has physical reality. Because of it, an object occupies space in memory.
It is important to keep this distinction clearly in mind.

Thursday, April 19, 2012

Debugging In Android

Debugging in Android is more easy and faster than any other application development. DDMS is short for Dalvik Debug Monitor Server, which communicates with the low-level services of a device or emulator. Switch to the DDMS perspective now by selecting Window > Open Perspective > DDMS.






The Devices view, located in the left column of the workbench, is where you will see any Android devices available to your computer. This includes both phones attached to your machine and running emulators. Under each device, you will see all the running processes. There are toolbar buttons on the view for launching the debugger on a process, getting information about heaps and threads, stopping processes, and taking screenshots.
The Emulator Control view, also in the left column, lets you do the following:
  • Set the status of the voice connection.
  • Set the status, speed and latency of the data connection.
  • Simulate an incoming call or SMS from a supplied phone number.
  • Provide a simulated set of points for the GPS via a latitude/longitude point, or GPX/KML file.
  • Using the File Explorer view, accessible as a tab at the top-right of the center column, you can browse the file system of a device. For an emulator or a rooted phone, you will have access to the private directories /data and /system. For non-rooted phones, you will only have access to /sdcard.


    The debugging perspective will provide in-depth information about your applications. Switch to the debugging perspective by selecting Window -> Open Perspective -> Debug .






    The Debug view will show you the running apps being analyzed, and, when stopped on a breakpoint or exception, the call stack of the application as well. The Variables view displays the contents of any local variables at the current breakpoint.
    The LogCat view in the lower right hand corner displays all logging output using the android.util.Log class. You can filter based on tags, or different log levels such as debug, information, error, etc.

Monday, April 09, 2012

Use Banglalion AX226 in Ubuntu ( 32bit )


        To use internet in ubuntu by banglalion usb modem I have used the below process. I don't want that you spend a lot of time [as I have spent ] just for connecting the internet in Ubuntu and stop the using Ubuntu as it is quite impossible to think Ubuntu without internet.

         So, use Ubuntu and enjoy it. At first you have to download below two software :

                  1. "Beceem-Control-Panel.tar.gz" [For Windows to change the device ID]
                        [Download Now]    

                  2. "blion-wimax-0.0.3.deb" [Unix software for Banglalion modem]
                        [Download Now]

         " Beceem Control  Panel " 
  
          Install "Beceem-Control-Panel.tar.gz" in windows operating system. After installation of  "Beceem-Control-Panel.tar.gz"  run it. Select device like in the below picture. In [Figure 1].               



                                                               Figure 1


          Then go to DSD tab and click in the left panel , after that click on "Modify USB Autoinit Data". In [Figure 2].



                                                                Figure 2  


            Then click " Read from Device " , ID will be appeared in the box . In [Figure 3]

                                                                  Figure 3

            KEEP IN MIND if  you mistake this step modem will be deactivate. So be careful. ID 19D2 and 0172 change to ID 198F and 0220 . Then press " Write to Device " and wait for a while . You  
will see DEVICE ID will change . Then go to Linux operating system , your modem will be detected.

       " Blion-wimax-0.0.3 "

          After download install it by pressing Ctrl + Alt +T for opening Terminal . Then write down below command :
                sudo dpkg -i <blion-wimax-0.0.3.deb drag the download file>


           Restart your computer. Then go to "unity dash" or press super key . Click on Internet Apps. 
Then you will be able to see picture like below in [Figure 4]:


                                                                     Figure 4

          Then do as usual . First click "Setup Connection" and write down your Userid, Password, MAC Address .
         
           Then click the "Initialize Modem" .

           After initializing complete Click on " Click'n Connect " . It will connect internet automatically.

            But it sometimes doesn't work properly.  Then you have to click on " Connection Console " . After some seconds you will get some Freq(Frequency) and BW(Bandwidth). Then write " connect 2610 10 ". You can use ZTE AX226, WU216 and ACCTON U211 in this way.

Special Thanks to Aniruddha Adhikary who have developed the software.