Arch Linux Install

Step 1 : Using fdisk partition the drives and wipe the root and boot partitions clean

Step 2: Connect to Internet (I typically use USB tethering from my phone and it works fine. Once the phone is connected, an IP address is automatically obtained by the system)

Step 3: pacstrap /mnt base

Step 4 : pacstrap /mnt grub

Step 5 : genfstab -p /mnt >> /mnt/etc/fstab

Step 5 : arch-chroot /mnt

Step 6 : Write hostname in /etc/hostname

Step 7 : ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime

Step 8 : edit /etc/locale.gen and run locale-gen

Step 9 : mkinitcpio -p linux

Step 10 : Set root passwd

The following steps should be performed if the standard MBR is used. For GPT the steps will be different (Take a look at the Arch Wiki
page for Grub). Somehow, the Arch Wiki does not mention these in the
installation guide directly. It only links to the Grub pages. However, this is ofcourse the most critical operation that one performs during an install :).

Step 11 : grub-install –target=i386-pc –recheck –debug /dev/sdx

Step 12 : grub-mkconfig -o /boot/grub/grub.cfg

Step 13 : Unmount and Reboot

Thats it! All the above steps are from the Arch Wiki installguide, except that they are all in one place.

Fucked up Indian Railways and Fuck you Mr. Railway Minister

The deplorable state of Indian Railways (IR) was once again showcased by the Bangalore-Nanded train accident a couple of days back. What is more shocking is that no one has raised voice against the Railways demanding resignation of the corresponding officials. This has been the fourth of fifth  such accident this year.

A country which fought for the women rights seems to silent even when the fucked up IR time and again suffocates and chars people to death. How many rail accidents happen in other parts of the world? Fuck you IR and Fuck you Mr. Railway Minister.

Some stupid fucks (common citizens) here think that this happens all the time in India so it is not something to be focussed on. It is unimaginable horror to think what the people went through before they finally succumbed. Many of them tried to escape but the doors could not be opened. The IR justifies this by saying that the doors have been locked to prevent theft.

Why cant they put a simple system in place by which the doors can be easily opened? The last such train accident happened last year so they had ample time to learn. In that case too many bodies were found near the doors. And the most disturbing thing is that no person in power says anything about the event. They just convey their condolenses. Put them up your arse.

The real reason for the train accidents may not be known. The AP Forensic team is trying to investigate the case but I am sure their findings are as credible as the fucked up Railway officials themselves.

I hope all the people who perished on the train accident rest in peace. Hope that someday very soon such accidents due to lack of routine maintanence do not take place.

WickedLeak Wammy Desire

Just bought this budget tablet a couple of days back. The standard resolution tablet costs 6500.Add 450 for shipping to hyd. They did not give me the pen that I saw in some other places in the internet. Just got the two connectors – the microusb to USB (female) and the microusb to USB (male).

I had to do a factory reset to make the tablet work. From that time there is no software glitch that I could find. The factory reset was required as the software crashed repeatedly. I don’t think the hardware needs to blamed here, it was just that jelly bean had not been configured correctly.

The display is OK. If you apply the slightest pressure at the back, the finger presses are visible On the screen. However, the biggest inconvenience seems to be the battery. It takes a full 10 hrs to charge completely and it lasts for just over 3 hrs.

A pleasant surprise for me is that, tata photon + works with this device – just have to add an APN with #777. The main reason I bought this was for games and they work superbly with this device. Of course , given Its specs one expects such performance. Everything else is good enough for me.

I have looked at various places over the internet before buying this, so this small review might help somebody out there.

lxde wallpaper slideshow

I concoted this from exisiting code over the internet. This code displays a random image from a specified directory (all subdirectories included) as a wallpaper in lxde. This is working for me under arch linux.

#!/bin/bash
DIR="/put/your/directory/here"

# failsafe - fall back to current directory
[ "$DIR" == "" ] && DIR="."

# save and change IFS
OLDIFS=$IFS
IFS=$'\n'

# read all file name into an array
fileArray=($(find $DIR -name "*.jpg"))

# restore it
IFS=$OLDIFS

# get length of an array
tLen=${#fileArray[@]}

FLOOR=1
while [ 1 -eq 1 ]; do
number=$RANDOM
while [ "$number" -le $FLOOR ]; do
number=$RANDOM
done
let "number %= ${tLen}"  # Scales $number down within $RANGE.
pcmanfm --set-wallpaper "${fileArray[$number]}"  --wallpaper-mode=fit
sleep 10m
done 

Some interesting facts about india

0) Indians consider money to be the most important thing to possess. Honesty (especially) is the most dispensible here. Always try not to be truthful if you want a “happy” life (http://toostep.com/debate/are-indians-money-obsessed).

1) People dislike each other. Honestly, they dont hate each other very often. Only every now and then. This dislike is what most people in India live with daily. They have gotten accustomed to it and they no longer really find it disturbing.

2) India is one of the most corrupt countries in the world. I did not have to say that after point (0).

3) The reason why an Indian lives (can get through a typical Indian day) is because (mostly) he/she has found that some other (arbit) Indian has found the courage to do so. There is never really the question of “What I want?” and living according to that.

5) India has never been limited by resources, it is currently being severely crippled by the attitude of its people.

6) Hyderabad (the city I live in) is a total shit-hole, literally (well, OK, atleast during the rainy season when all the sewage is on the roads!).

7) Some people (especially the poor ones and some rich ones too) survive almost like pigs. One can say that these are some of the most deplorable states in which a human can live.

8) Malnutrition is comparable or worse than Sub-saharan africa. I think countries like Somalia have our rates (http://en.wikipedia.org/wiki/Malnutrition_in_India).

9) Driving: Get an expensive car. You get more respect on the road. If you have a smaller car then God be with you. Well, HE has to be there with you even if you have an costly car anyways. FACT: India has the highest number of road accidents in the world. Dont think it is because of the population: China has less (http://www.dw-world.de/dw/article/0,,5519345,00.html).

10) Very few people give a damn to whats going on around. Indians have the greatest sense of apathy in the world.

11) Indians should be the least creative in the world with a whopping 4 (or 5?) Nobel and 0 Fields medals. Yet, India invented zero and blah, blah. (Should learn something from rajini: past is past).

12) Yet, India has a great culture, tradition, India is great blah, blah. generally written by people who do not understand what they are saying. This is all one can say: India was great (a long time ago that too).

A small question

Let {X} be a set. Let {\mathcal{G}} be a non-empty collection of subsets of {X} such that {\mathcal{G}} is closed under finite intersections. Assume that there exists a sequence {X_h \in \mathcal{G}} such that {X = \cup_h X_h}. Let {\mathcal{M}} be the smallest collection of susbsets of {X} containing {\mathcal{G}} such that the following are true:

If {E_h \in \mathcal{M}} {\forall h \in \mathbb{N}} and {E_h} {\uparrow} {E} then {E \in \mathcal{M}}
If {E}, {F}, {E \cup F \in \mathcal {M}} then {E \cap F \in \mathcal {M}}
If {E \in \mathcal {M}} then {E^c \in \mathcal{M}}

Does {X \in \mathcal{M}} ?

DFT revisited

I was reading a book on image processing by Bernd Jahne and found what he wrote about the Discrete Fourier transform very interesting. The DFT can be computed as {\hat{f} = A f} ({A} has been defined in a previous blog ), so it seems like a linear transformation. A new interpretation is that the rows of {\hat{A}} (or the columns) ({\hat{A}} has been defined in a previous blog ) can be thought of as spanning the vector space of all N-tuples of complex numbers denoted by {\mathbb{C}^N}. First of all, it can be checked that N-tuples of complex numbers form a vector space. On this vector space, an inner product can be defined as follows :

\displaystyle <v,w> = \sum_{k = 0}^{N-1} v_k {\bar{w}_k}

With this definition of inner product on the vector space, one can easily show that, {<\frac{1}{\sqrt{N}}u_i,\frac{1}{\sqrt{N}}u_j> = \delta  (i-j)} where {u_k} is a row (or column) of  {\hat{A}} .

Therefore, if {C \in \mathbb{C}^N} then {C =  \sum_{k = 0}^{N-1} \alpha_k (\frac{1}{\sqrt{N}}u_k)} where {\alpha_k =  <C,\frac{1}{\sqrt{N}}u_k>}. Clearly the {\frac{1}{\sqrt{N}}u_k} span {\mathbb{C}^N}. It can also be checked that {\alpha_k} for {k \in  \{0,1,..,N-1\}} is the 1D Fourier transform. Hence the DFT of a vector {f} is just a projection of {f} on the rows of {\hat{A}}.

In two dimensions, we consider the set of all {M\times  N} complex matrices. This is again a vector space over the field of complex numbers. The basis “vectors” now are the matrices {(B_{u,v})_{m,n} = D_{m,n} =\frac{1}{\sqrt{MN}} exp(\frac{-2\pi  imu}{M}) * exp(\frac{-2\pi inv}{N})} for all {u  \in \{0,1,...,M-1\}, v \in \{0,1,...,N-1\}}. The inner product for two complex matrices is defined as :

\displaystyle <A,B> = \sum_{m=0}^{M-1}\sum_{n=0}^{N-1} A_{m,n} {\bar{B}_{m,n}}

Any complex matrix can then be written as a linear combination of the Basis matrices {B_{u,v}}. {C =  \sum_{u=0}^{M-1}\sum_{v=0}^{N-1} \alpha_{u,v} B_{u,v}}. Then it can be shown that {\alpha_{u,v}} is the 2D Fourier transform for {u \in \{0,1,..,M-1\}, v \in  \{0,1,...,N-1\}}. So, we are projecting {C} onto the Basis vectors {B_{u,v}}. By this reasoning it can be shown that the 2D Fourier transform for a matrix {C} can be written as {A_M C A_N}, where {A_M} is the {M\times M} DFT matrix and {A_N} is the {N \times N} DFT matrix.

NOTE: I was only mentioning {\hat{A}} as I was lazy to write the basis vectors. Hope this did not confuse.

Hakell and Image processing

I love to do image processing and Haskell and wanted to put these two things together in an “effective” way.

Why do I want to program in Haskell? The answer is simple: I love the declarative style of functional programming. I can directly write my formulas into code. I waste less time doing rote jobs and think at a higher level, so it is good for my grey cells as well.

Also, I hate the fact that I have to manage the memory by myself in C / C++. My biggest problem with C is that, I am never at peace with my code. There might be a memory leak somewhere, a global variable might not have been updated and all that crap. My mind twists and turns in trying to reason about code. I just wanted a language where I would write code and just forget about it and it works just fine 🙂

The problem with doing image processing in C is that, using the default Haskell data types (lists, functions) makes the program too slow. One has to expect such speed hits as this is a very high level programming language. However, there are a few array libraries that speed up the code. The sped up code might not compete with C but it is reasonably fast.

I have used the hmatrix library for representing an image. What I like about this library is that there are a whole lot of lapack algos that can be implemented on them. This library allows one to write purely functional code. Just write the image as a 2D function( func (i,j) ) and use buildMatrix, voila! you have a new image.

Hmatrix was just perfect for the array library. I still had lot of problems with interfacing with my web camera. I understand that there is a HOpencv library which can do that but after glancing through the doumentation I felt that the API requires me to stay inside the IO monad. Which means the same stateful programming that I much abhor. Added to that it did not compile on my system and I had to find another way to grab images.

There seem to be nice examples on internet for grabbing images from web cameras (using v4l2 in linux) and I modified a C source and wrote FFI bindings to it. I am truly elated to find that the FFI bindings to v4l2 based image grabbing and the hmatrix work seamlessly :).

If any of you require the bindings reply and I will try to post them.

Convolution

Convolution is mathematically well understood, both in the continuous and discrete domains. There is a simple formula to comupte it. However, I recently needed to implement this in code and found that it was not all too easy. In this post, I tried to come up with a formula that can be used for programming convolution. In later posts about this, I will also try to analyze the computational complexity and spruce it up with some real working convolution code.

Firstly, what is discrete convolution? There is a straight-forward formula :

\displaystyle  h[n] \equiv (f*g)[n] = \sum_{k=-\infty}^{k =\infty} f[k]g[n-k]

For generality we will assume that {f} and {g} are discrete functions (i.e. functions from the Integers to the Reals). For example, {f} might be such that it is defined from {fl} to {fh} and it is zero outside. This is the most general representation for the signal. Similarly, let {g} be defined on {[gl,gh]} and zero outside. When we are asked to convolve these two signals, it is apparent that {fl,gl,fh,gh} would play some role in the computation. However, MATLAB for example, does not care about these values. So, it is slightly confusing how convolution is carried out. Let us examine.

In the definition of convolution, what are the values of {n} that are interesting? Before thinking about that, it is better to understand what values of {k} are important for our considerations. Fix any {n} and note that

  • { fl \leq k \leq fh}, because outside of this range, {f[k]} is zero and hence does not add to the convolution
  • Similarly, {gl \leq n - k \leq gh} which implies that {n - gh \leq k \leq n - gl}

Clearly, if {[fl,fh] \cap [n-gh, n-gl] = \phi}, the convolution is zero and we do not have to care about such an {n}. Otherwise, one can immediately see that the interesting values of {k} are :

\displaystyle [fl,fh] \cap [n-gh, n-gl] = \max (fl, n- gh) \leq k \leq \min (fh, n - gl)

Let us rewrite the formula again (for those {n} such that {[fl,fh] \cap [n-gh, n-gl] \neq \phi}):

\displaystyle  h[n] \equiv (f*g)[n] = \sum_{k= \max (fl, n- gh)}^{\min (fh, n - gl)} f[k]g[n-k]

Now, what are the values for {n} for which {[fl,fh] \cap [n-gh, n-gl] \neq \phi}? Consider, {  n = fl + gl}, then

\displaystyle  \begin{array}{rcl}  [fl,fh] \cap [fl+gl-gh, gl+gl-gl]  &=& \max (fl, fl+gl- gh) \leq k \leq \min (fh, fl+gl - gl) \\ 		 		 &=& fl \leq k \leq fl \\ 				 &=& fl \end{array}

When {n < fl + gl}, {\min (fh, n - gl)  < fl} and hence the convolution is zero. The upper limit on {n} can similarly be found to be {n = fh + gh}. Therefore, the full definition of convolution useful for computer implementation is:

\displaystyle  h[n] \equiv (f*g)[n] = \sum_{k= \max (fl, n- gh)}^{\min  (fh, n - gl)} f[k]g[n-k] ~~\forall n \in [fl+gl,fh+gh]

Upon further thought, it can be easily seen that {fl,fh,gl,gh} are not important for the core convolution. If the signal {(f, [fl,fh])} is replaced by {(a, [0, fh-fl])} and {(g,  [gl,gh])} is replaced by {(b, [0,  gh-gl])} there would no difference in the computation of the main convolution function. Only the range of {n} for which the convolution is defined change. This is the primary reason why MATLAB does not care about these things.

Siddharta

I have been reading (actually listening to) the book Siddharta by Hermen Hesse. I did like this book as I know that when I listen to something for a couple of hours continuously, it has captured my attention.

Briefly, this book talks about a young boy who vows to understand the meaning of life (aka attaining enlightenment) and quits social living to become an ascetic. However, after a few years have passed by and he is in his thirties or so, he realizes that he has not attained the goal he had set out to achieve.

During this time he comes to the conclusion that “teachings ” even from the great masters do not appeal to him. He meets the Buddha and tells the “Venerable One” that his teachings have a “gap” or a logical error. He further tells him that even though the Buddha can teach all he wants within the limitations of language, he can never explain how it would have felt when he expreienced Nirvana. Having said such things to the Buddha, Siddharta quits being an ascetic.

He comes back to the “social” world and initially has reservations about having sex (with women!). The desire continues to surge in him and he learns the art of love making from a Courtesan (an euphemism for a high-end prostitute?). This woman (kamala in the book) teaches him all that she can and finally proclaims that he is the best in the business!

Oh! by the way, he is also the best in the town in another form of business, I mean the real one now, selling and buying stuff such as mechandise (!!).

After he has spent a good ten years or so in lustful living he finally obtains the badge of honour – usually given to men who have all the three vices, mukka, chukka and ? (Please replace the question mark for me as I dont know anything appropriately rhyming in gult).

As with some men, after obtaining the badge of honour, he is disgusted with his “lowly” life. How did an ascetic end up like this? Ofcourse, this is not all happy times for Siddharta as he contemplates suicide. Right at that moment he has a “flash” and becomes unconsious.

When he gets up, he is unknowingly more happy. He understands that he always had a false sense of (intellectual) superiority over everyone else and this has led him to take the path of the vices (and the obtain the badge of honour). Ultimately, he is happy at the end of Chapter 8. Still three more chapters to go.

What I could gather from the book till now is that there is no substitute for experiences in life. The goal of eliminating the ego might be reached by deep contemplation but it could more easily be attained by “living” life (by this I mean to live in an emotionally connected way with others) and slowly pushing ego out of the system.

The only great danger might be that, one forgets that the purpose of life is the elimination of ego. Once this is forgotten, the real reason for living has been lost.

PS: BTW, I forgot to mention that Siddharta gets Kamala pregnant, so there might still be some story left 🙂