Tuesday, 7 February 2012

Replacing Unity with LXDE on Ubuntu 11.10


Let us face it, many like me were disappointed that Ubuntu 11.10 came only with the Unity interface. I am sure I would have gotten used to it in a while, but it was too darned slow for my liking. One of the reasons why I like to work with Linux is that it doesn't have unwanted extra baggage that bogs down the system. It is not that I dislike the interface, it is a new idea, especially the Dash, but it is sluggish. And when I say sluggish, I mean really sluggish. The Dash takes more than 2 seconds to open after its icon is clicked. Now that is unacceptable to me.

A good option is to switch back to the Gnome Shell. This is different from the classic interface on previous versions and it is sluggish too, but not as sluggish as Unity. To install, run the following command in a terminal :

$ sudo apt-get install gnome-shell

In case of any problems while logging in, refer to this : Ubuntu Forums

The best option, according to me, is to install LXDE. To install, run the following command in a terminal :

$ sudo apt-get install lxde

After you finish that, logout of Ubuntu and then on the login box click on the gear-shaped icon on the top right corner. Choose LXDE and login. Voila, you have a new desktop environment that is lightweight, well designed and gets the job done without reducing the performance of your system  :)

Also, if you have problems selecting a wifi hotspot after installing LXDE, do the following :

Open the autostart file for LXDE by going to Menu > Accessories > LXTerminal and type the command -


$ sudo nano /etc/xdg/lxsession/LXDE/autostart

Then add the following for the user : @nm-applet


Save changes and reboot. The applet will appear in the lower right of the panel and you should be able to view and connect to your wifi hotspot.

You can switch back to Unity anytime you feel like by choosing Unity from the menu while logging in. Hope this helps :)

Monday, 6 February 2012

K-Means Algorithm



There are two types of learning algorithms : Supervised and Unsupervised. In supervised algorithms we have a collection of labelled target data. This helps us provide the right answers to the algorithm for a set of sample data. This isn't always possible as it could be tedious to list all the right answers, while another possibility is that we don't know the right answers in advance. Unsupervised learning algorithms work in situations where no information about the correct outputs is available.

In regression, we group the inputs based on similarities, but since we don't have the right answers, we can't derive a function for regression. If we figure out a way to exploit similarities between inputs and clustering them based on this, then classification is done automatically. So in Unsupervised Learning, the algorithm needs to find clusters of similar inputs and it needs to figure out the similarity by itself.

The aim of every learning algorithm is to minimize some error function. In supervised learning we use measures like the sum-of-squares error which can't be used in Unsupervised learning as we have no means of measuring the error, since there is no target data. We can't use any external criteria and need to figure out something internal to the algorithm. This measure should also be task independent. Else we would need a different measure for each task.

For a general error criteria, it is helpful to remember that if two inputs are close together then the Euclidean distance between them is small (since their vectors are similar). So inputs that are close to each other can be clustered as being similar. If the elements of a vector are close to the weight values of a node, then that node is a good match for the vector.

Suppose input data needs to be clustered into k categories. An example would be rainfall over the month of January, February and March, in which case k=3. We need to partition our input space into k clusters and allocate cluster centers such that there is one cluster center at the middle of each cluster. So now we need to think about defining the cluster centers and the error criteria.

Assuming Euclidean space, the distance between points is Euclidean distance. The center will be the mean average. This only holds for Euclidean space and so we will always assume that to be the case. To position the cluster centers, we calculate the mean of points in each cluster and assign the mean as the cluster center.

We can place the cluster centers randomly in the input space. In each iteration of the algorithms, their position will be updated according to the data. For each data point we calculate the Euclidean distance to all the cluster centers and the point is assigned to the cluster that it is closest to. Now that the members of the clusters have changed, we again calculate the mean (cluster center). Now each data point is re-evaluated and assigned the same or different cluster depending on the Euclidean distance. This process is repeated till the iterations stop producing new changes.

Algorithm :
  • Initialization : 
    1) Choose a value of k
    2) Choose k random positions in the input space
    3) Assign the cluster centers μj to these positions
  • Learning :
    - Repeat

    1) For each data point xi, calculate the distance to each cluster center. Then assign the point to the nearest cluster center with distance d= min d(xi,μj) (calculated for j ranging from 1 to k)

    2) For each cluster center, move the center to the mean of all the points in the cluster.
    μj = (1/Nj)*
    Σi (xi)  (for a cluster with Nj points and Σ for i ranging from 1 to Nj)

    - Until the cluster centers stop moving.
  • Usage :For each test point, compute the distance to each cluster center.Assign the data point to the nearest cluster center with distance d= min d(xi,μj(calculated for j ranging from 1 to k)
That is it for now. I will paste the code for this in Python in some time. I will also post a numerical. This tutorial is based on the book Machine Learning : An Algorithmic Perspective. Hope you found this post informative.

Sunday, 5 February 2012

Installing Android SDK on Ubuntu


My version of Ubuntu is 10.10 (Maverick). The following procedure should work for newer versions too.

Eclipse IDE : The first thing to do is install the Eclipse IDE on your system. Ubuntu Software Center provides Eclipse, but it is the 3.5 version called Galileo and you would need at least the 3.6 version (Helios). I went ahead and installed the 3.7 version (Indigo). The 3.8 version called Juno is scheduled for a July 2012 release, so if you are reading this after that, get Juno.

Go to : Download Eclipse IDE

Extract the contents to any folder, I chose "/home/my_username". If the exlipse.sh file is not an executable, then go to the terminal, cd into the folder where you extracted eclipse and then execute this :

$ sudo chmod +x eclipse.sh

That finishes the Eclipse installation.

Android SDK : Download the SDK Android SDK

Extract the files to any directory of your choice. I did it at "/home/my-username". Then cd into the folder and execute "/tools/android" to run the SDK and AVD Manager.

Choose from the available packages. I chose Android 4.0.3 (API 15) and 2.3.3 (API 10). Now click "Install Selected" and you are done.

Installing and configuring ADT plugin in Eclipse : Start Eclipse and ho to Help -> Add New Software and click on Add. Enter ADT Plugin as name and "https://dl-ssl.google.com/android/eclipse/" as location and click on OK.

Select Developers Tools and click Next and then click Finish after accepting the Terms and Conditions of Service. Once the download is completed, it is time to configure the plugin. Select the location where the SDK was extracted and click Apply/OK. (There appears to be an option of installing the SDK from the ADT plugin configuration menu. This might obviate the step of manually downloading and extracting it. But I didn't do it that way so I don't know if that works.)


That is it, the installation and configuration is complete. Happy development and tinkering :)


Installing OpenCV on Ubuntu



Before I begin, I am using Ubuntu 10.10 (Maverick). I am certain that this process will work with most versions of Ubuntu, but still, if it doesn't work with your specific version, then message me. To check the version of Ubuntu that you are running, open the terminal and type lsb_release -a and press Enter.

Prerequisites:

  1. A C++ compiler. g++ is most suitable. To check the version of g++, type  g++ --v  in the terminal. Mine is version 4.4.5. If g++ isn't installed, run the following command in the terminal :

    $ sudo apt-get install g++

  2. A Graphical User Interface library, GTK+ ver 2.0 or higher. To check your version of GTK+, run this on the terminal :

    $ dpkg -l | grep libgtk

    If the required version of GTK+ is not installed, run the following command :

    $ sudo apt-get install libgtk2.0-dev

If both the above requirements are already installed, then go to System -> Administration -> Synaptic Package Manager and search for "opencv". Install the main package and these library files :
libcv
libcv-dev
libcvaux
libcvaux-dev
libhighgui
libhighgui-dev

Optional : python-opencv - This contains the Python bindings for OpenCV. Install it if you want to program in Python.
opencv-doc - This contains the documentation. Not necessary to get OpenCV working, but useful nonetheless. 

Now set the default path for OpenCV libraries by executing the following commands on the terminal :

$ export LD_LIBRARY_PATH=/home/opencv/lib
$ export PKG_CONFIG_PATH=/home/opencv/lib/pkgconfig

To check the path where the OpenCV library files are stored, execute these on the terminal :

$ pkg-config --cflag opencv

The output will be -I/usr/include/opencv

$ pkg-config --libs opencv

The output will be -lcxcore -lcv -lhighgui -lcvaux -lml

Open gedit and type a simple program to test whether the installation is working. I provide a sample code taken from the book Learning OpenCV:


#include <highgui.h>

int main(int argc, char *argv[]) {
  IplImage* img = cvLoadImage(argv[1]);
  cvNamedWindow("Example", 0);
  cvShowImage("Example",img);
  cvWaitKey(0);
  cvReleaseImage(&img);
  cvDestroyWindow("Example");    
  }

I saved this as cv_example.c

Now to compile this, type the following command in the terminal :

$ g++ -I/usr/include/opencv -lcxcore -lhighgui -lml cv_example.c

The output is in the a.out file in the same directory. As can be seen from the code, you need to provide an image file as argument and this file should be in the same directory. I used a file by the name "mustang.jpg"

$ ./a.out mustang.jpg

If all has gone well, you will find a window by the name Example that displays your .jpg file. 

I hope this helps. If you face any difficulties, contact me.

Sunday, 1 January 2012

Genesis


From today I begin the task of penning down my thoughts on a variety of topics. I have never maintained diaries or penned down my thoughts before this. So forgive the rawness of the posts :)