Wednesday, 22 May 2013

More Conformal Maps With OpenCV


So I finally got the conformal maps code to work with some of the  other functions and the results are quite interesting and strange. Not really what I expected to get. The transformed images vaugely resemble the ones in my math textbook but don't match them exactly.

So again, here's the original image for reference:


I then applied the transformation $w = z^3$ to the image.

The results are quite satisfactory. No surprises there.











$w = z^3$ transformation
Next I tried $w = z + \frac{1}{z}$. I didn't really get what I expected ...

$w = z + \frac{1}{z}$
$w = log(z)$ looks like someone flattened the thing along the third dimension.

$w = log(z)$
Another version of $w = log(z)$ with the image in a different position.
The results for $w = sin(z)$ and $w = e^{z}$ were just plain weird.

$w = sin(z)$
$w = e^z$
But my favourite one was the transform $w = tan(z)$

$w = tan(z)$
$w = tan(z)$ with the image in a different starting position
A perfect example of mathematics creating art. They're not as good as fractals but they're still pretty good.

Saturday, 6 April 2013

Thoughts on Free Will and Determinism

The most important problem that comes up when talking about free will is the difficulty in defining the concept. How exactly do we define free will? There are many definitions with different levels of rigorousness. One way to define free will is in terms of the absolute laws of physics. We can define free will as "the ability of a conscious entity to make choices that are not affected in any way by the events that happened to the conscious entity in the past." This is the definition most often used by the group of people who are classified as incompatibilists. Another way to define it is in terms of other living things. We can define free will as "the freedom to chose which action to take in a particular situation without being hindered by other humans or conscious living beings." My opinion on whether free will exists or not is highly dependent on actual definition being used. I think it is extremely unlikely (and even impossible on principle) to have the kind of free will that is independent of influence from physical law. However if the definition on free will does not mention independence from past events and only concerns itself with restrictions on choices we make by other people, then I am willing to accept the possibility of free will existing.

In the second kind of definition, we are merely stating that when faced with a choice such as "Which profession to go into?" or "Which course do I take in college?" we have the freedom to go against the advice of our parents/teachers and do whatever we feel like at the time (not everyone has this freedom ;) ). This kind of freedom in principle exists. Although there are parents that force their children to make certain choices when it comes to college courses, the student can in principle choose not to accept that decision by ignoring or being prepared to accept the - sometimes unpleasant - consequences of their choice. That kind of free will exists and that is the picture of free will that comes to most people's minds when they hear about freedom. In fact, this free will or "social freedom" is the kind of freedom most people expect from modern society. It is what they refer to when they talk about "Freedom of speech" or "Freedom of expression".

However if your definition of free will that tries to say that human decisions are completely independent of the events that took place in your past, I disagree that such a kind of freedom exists. This kind of freedom is impossible to define without generating a contradiction. The human brain is a huge neural network that stores in the neurons different weights that are a result of our past experiences. These are the same neurons that make "conscious" decisions or "choices." I think that it is impossible for a human to make a decision or a choice whose sole originator is the human in question.

Recent results in neuroscience suggest that our conscious "mind" is not really the originator of our actions see: http://www.ncbi.nlm.nih.gov/pubmed/15925808?dopt=Abstract and http://www.ncbi.nlm.nih.gov/pubmed/12191935?dopt=Abstract
The results of these experiments seem to suggest that our "choices" are determined by the brain before our conscious mind becomes aware of the fact that we have made a choice. Results like these reduce the likelihood that the decisions we make are completely independent of past events. It may even be true that the only thing consciousness does is rationalize the involuntary actions of our sub conscious. The very idea that we have "Made a decision" may be an illusion in many situations.

I also disagree with people who simply wave their hands vaguely and say free will exists because Quantum Mechanics. While it is true that quantum mechanics is a probabilistic theory,  it doesn't help to "gift" free will to consciousness. Firstly it is highly dubious whether quantum mechanics is directly involved in human cognition and consciousness. Secondly even if quantum mechanics made our choices probabilistic it still doesn't mean that the decisions are free decisions. Decisions can only be classified as "free" if a people have the same probability of making a particular decision when faced with a particular choice independent of the experiences these people have had in the past. A coin that lands on heads half the time does not have "free will".

I think a lot of the confusion surrounding the debate about free will and determinism is because of the wide variety of ways in which people define "Free will". It's got so many definitions that it is impossible to say what people mean when they say "I believe in Free will". If someone ever says that the very first thing I will do is to ask them how they define free will. The debate should be pretty straightforward from that point on.

Tuesday, 12 March 2013

Playing around with OpenCV and Complex Functions

Last week my college hosted a technical fest. It was pretty cool. There was some really cool tech on display at for the exhibitions, some awesome guest lectures, robotics competitions and a lot of workshops. It was quite a busy and interesting week. I attended this really interesting workshop that introduced us to image processing using Matlab. We managed to get matlab to track a ball in the field of view of my laptop's webcam and use this motion to control windows media player and the movement of wheeled bots. Recently, I've become really interested in the field of Artificial Intelligence so this simple computer vision exercise got me excited. I came back to my room that evening and started exploring my options.

That evening I discovered an excellent Open Source alternative for doing image processing called OpenCV. I decided to abandon Matlab and do image processing in OpenCV instead (Because it's freeeeeeee!). That very evening I got OpenCV compiled and set up on my Ubuntu partition and started learning image processing.

I had a bit of difficulty starting out because I'd never really learnt C++ 'officially'. So I had to use my basic knowledge of C and a lot of googling to understand the basics of setting things up. The biggest hurdle was understanding how classes and objects worked. It took a few hours to smooth those concepts out. As soon as I had a rudimentary grasp of what they meant I could start writing my first image processing program.

So fooled around with flipping and adding noise to images for the last week. Then I got a brilliant idea. I was having a bit of trouble visualizing what I was learning in math class. We were doing conformal maps. So I thought that it might be a good idea to use OpenCV to visualize conformal maps. So I set out trying to apply conformal maps to Lenna,  one of the most famous test images used in image processing.

It took me a couple of days to make the code completely bug free. There were some really annoying bugs. The fact that images were stored in matrices whose indices followed a left handed coordinate system added to the difficulty of implementation. I had to apply multiple transformations in series to get the code to work. But in end everything came together and this was the result!

The result of applying the transformation $w = z^{2}$.
Right now, the only transformation that works perfectly is $w = z^{2}$. Other functions give really weird outputs. I'll figure them out eventually.

And I've decided to open source the code I used for this! It's very messy because it's not the final version of the code and it's full of commented code and random cout statements.  But maybe somebody will find it useful.

The code can be found here: http://pastebin.com/kBBP2ASe

Wednesday, 2 January 2013

Do People "Look" Like Their Names?

I've had this thought many times but was recently reminded of it when I watched this video by the PBS IdeaChannel (go check this channel out! It's awesome!) where YouTube commenters were talking about the presenter in the video looking like someone named Mike.

It made me think, do people really look like their names or is it just that the we associate the names with the faces? When we ask someone what their name is and they say "Ariadne" and we think "Hmm.... she really looks like an Ariadne(I wrote this post right after reading the latest Percy Jackson book and reading up on Greek mythology. That's the reason for the unusual choice for a name.)  Is it because she really does look like an Ariadne or is it just because we make the association the other way round?

I think my question really boils down to this: Do names given to people have any intrinsic ability to describe the way they look? It's very unlikely. Most parents give their children names based on a factor completely independent form their appearance. It's impossible to do that anyway since most babies look the same as soon as they are born. It reminds me of a talk Michael Shermer gave about the believing brain and how humans always tend to notice meaningful patterns in noise even if they're there by pure chance or sometimes even if they aren't there. If someone points out that that girl named Ariadne looks like an Ariadne then people will automatically start thinking that "yes she does look like an Ariadne". When I was young I really did think this way. When someone was introduced to me by name I would start thinking about how he or she 'looked' like their name.

An interesting experiment would be to take two large groups of people; one control group and one test group. The memebers of the group are not told which group they belong to of course.

Then each member of the group is shown a face and a name. The control group gets the right name for every face and the test group displays a fake name for every photo. We then compare the groups and see if the group given the false name had a higher proportion of faces labelled "does not look like name" than the control group.

To make the experiment simpler, we could just get one large group and give them a huge list of faces and names and then ask them to say whether the faces look like the names or not. False names and true names are randomly mixed into the list. Then we can compare the true names to the false names and see if the faces of the people in the falsely named photographs were more likely to be marked as not matching the name.

The interesting thing is, that this applies to everything else as well. There is nothing inherently 'tabley' about a table and there is nothing inherently 'birdy' about a bird. It's just a random sequence of sounds that we make with our mouths. At some point people got together and agreed that this particular sequence of sounds would represent animals that fly. So all languages arbitrary. It's just an abstraction that helps us to let each other know what what's going on in our minds.

I guess this is a thought Christopher Paolini had when he was making up languages for Eragon universe. In The Ancient Language names of an object are supposed to be true names that describe the inherent nature of the object. It does look like he gave the matter of words in languages being completely arbitrary quite a bit of thought. In the real world mathematics comes closest to this ideal of representing the true nature of reality.


Saturday, 15 September 2012

Pokemon and The Sagrada Família

When I watched the movie "Pokemon: The Rise of Darkrai", I noticed that the town in which Ash finds himself had absolutely gorgeous buildings. It's remarkable that I even noticed that since I'm not really a person who knows or appreciates architectural art. It struck me that the buildings must have been really well designed if they beautiful enough to make someone like me sit up and take notice. I particularly fell in love with the huge Space-Time towers. Something about the shape of the building really caught my eye. I remember thinking to myself, "Wow... That building looks awesome.."


Two views of the Space-Time Towers

Out of interest I went through the movie's Wikipedia page to find out what inspired the Creators of the movie to make the building. I discovered that the town in the movie, Alamos Town was based on the Barcelona, Spain and the Space-time towers were inspired by this beautiful building called the The Sagrada Família designed by an architect called Antonio Gaudi.



 I think this building looks breathtakingly beautiful. Usually appreciation of of a particular form of art is a learned taste. But sometimes an artist creates a masterpiece that is so good that it transcends these borders and appeals even to even the complete novice. If I think this building looks so good, I can only imagine how awestruck those people who really learn architecture must be.

Another amazing thing that i learned is that this building is still under construction! Work on the building began in 1882 and is still going on. That means the building has been under construction for over 130 years! And it's only expected to be completed by 2028! That is one long construction project. What I find remarkable is that even in it's incomplete, half finished state it looks so beautiful.

Even the inside of the building looks fantastic.

Detail of the roof in the nave. Gaudi designed the columns to mirror trees and branches.

Antonio Gaudi must have been a real genius.

Friday, 14 September 2012

Installing Ubuntu 12.04 on a Dell XPS L502x

Installing

So after years of indecision I've finally decided to install Ubuntu on my laptop. Why? Because I identify strongly with the open source software movement and eventually hope to contribute to it. I will be documenting the installation process on my blog so that other users with the same laptop can use my experience to guide their own installation.

My installation is guided by many sources including some very linux-experienced friends. I've also found the blog of another person with the same computer who has installed ubuntu on the system. So I got some help from there as well.

Since one of the main reasons I wanted to install Ubuntu was so that I had a backup OS in case my Windows became infected with some sort of virus, I decided to go ahead and install the operating system on it's own partition.

So I have a Dell XPS L502x with the following specs:

Intel core i7 Sandy Bridge processors.
Nvidia GT540M graphics Card
Intel HD3000 integrated graphics
1080x1920 full HD screen

Before I go into the installation process let me go into the details of all the problems which could occur if you partition you drive. Now from what I've learnt from hours of browsing forums is that most of the problems that occur when partitioning are due to human error. If you windows installation dies while installing ubuntu it's usually because you misread some instructions or misclicked somewhere. So my advice for you is to DO YOUR RESEARCH. Make sure you understand exactly what is going on when you partition your drive and you'll be able to Dual Boot with windows without a single problem. I spent nearly two weeks reading up articles and tutorials on Ubuntu installation and disk partitioning before I installed it. By this time I had a really good understanding of how partitioning works and knew exactly what to do to minimize error from my part. I'll try to explain the process the best I can but make sure you read up on your own as well. Generally if you don't know the difference between a logical partition and a primary partition don't meddle with partitions.

First download the ISO image of the latest version of Ubuntu from here. Choose 64 bit or 32 bit depending on which processor you have. My laptop has 64 bit architecture and runs a 64 bit version of Windows 7 home premium. So I downloaded the 64 bit image and then verified the MD5 sums.

I then bought one of those extremely cheap 700MB "write once" CDs and burned the disc image on to the system. For doing this your best bet is to follow the instructions here. The process is incredibly straightforward on Windows 7. It took about 10 minutes for me to burn my own CD.

I put the CD into the CD drive and then restarted the computer. I pressed F12 to enter the boot menu  and chose the "Boot From CD drive" option. Once I made sure the CD was working fine, I proceeded to the installation. Several sources helped me here.

I wanted to be as safe as possible so I shrunk one of my Windows partitions from inside windows using the Windows drive partitioning utility. Just search for partition in the start menu and you'll find it. This left about 220 GB of unallocated space on my drive. (I have a 750 GB WD hard drive. So plenty of space for both operating systems.) The rest can be done when installing Ubuntu.

Every step from partitioning onwards, I followed from this website. My boot partition was 500MB, root was 20 GB, my home was ~180GB and my swap was 8GB. Here's what you need to know when you try to partition. There are two types of partitions. Primary partitions and logical partitions. A hard disk can only have a maximum of four primary partitions but it can have a lot more logical partitions. From what i understand, all the logical partitions in a disk together are called an extended partition. A hard disk can only have a maximum of four primary partitions. So if you want more partitions on your drive you should only create three primary partitions on your disk. Then make the rest of the partitions logical. I had it easy. My laptop's hard disk had only three partitions in it (One for the windows System Reserve, my C drive and my D drive). So it was easy enough for me to shrink one of my drives and leave some unallocated space for Ubuntu. However, some laptops already have four partitions on the hard disk. If that's the case you have to completely delete one of your partitions and maybe extend another before you install Ubuntu. This is a bit more complicated but there are a lot of excellent websites which tell you how to do it.

And that was pretty much it. I booted into windows, used EasyBCD to configure my boot screen as shown on the website. I booted into Ubuntu and everything just worked. No hardware issues at all except for the Nvidia graphics card. I solved this by installing the Bumblebee project and I was ready to go.

There was another hurdle in my case. Since I don't have access to a reliable WiFi network I use a 3G mobile broadband dongle to connect to the internet. To get this to work I needed to get a few updates and for that I needed an internet connection. On the third day after installation I was able to connect to the unreliable wifi network for a few minutes to perform a few critical updates. After that the modem started working ... sort of. It still seemed to have some trouble doing the modeswitch from a storage device to a modem. I found that if I booted into Windows first, then restarted (so that the power to the modem wasn't cut off) and then booted into Ubuntu, the modem would be recognized just fine. However if I just plugged in the modem after booting into Ubuntu, the network manager didn't detect it. It took me almost a week to get it fixed. It turned out that it was a problem with the USB ports. My laptop has 2 USB 3.0 ports and 1 USB 2.0/eSata port. I've always plugged my modem into one of my USB 3.0 ports. Yesterday, I tried plugging it into the USB 2.0 port and it just started working normally. Maybe I should submit a bug report to Ubuntu.


User Interface and Hardware

What impressed me most is that Ubuntu booted up for the first time and everything just seemed to work perfectly. Ubuntu's hardware support is commendable. I only to download extra drivers for my Nvidia Graphics Card. Everything else worked just perfectly with the fresh install including my webcam (Which interestingly stopped working in Windows after a driver update a few weeks before I installed Ubuntu). 

So the most obvious difference between windows and Ubuntu is the user interface. The Ubuntu user interface is just amazing! I just love the fresh clean look of my desktop.



Thursday, 30 August 2012

Drunk on the Universe

Usually, all my blogposts are well thought out and proofread once or twice. Today I decided I would do something different. I am going to write down my train of thought exactly as it happened. That means there will be a lot of wrong conclusions and going revision of opinions going on. A lot of jumping about.

Richard Feynman was right. You really can get a kick out of thinking about things.

Today I chanced upon someone wearing a T-Shirt with this interesting design:

Life's priorities ... money, food and sleep..... It started me off on a very interesting train of thought. These are necessities in everyone's life. A complete absence of any of these three in a person's life will most definitely kill him/her sooner or later. Then I realized, we don't choose our necessities. We have absolutely no control over what our necessities are just like a little frog has no control over its diet. Just as the frog is destined to spend the rest of its mundane life hunting for flies, humans are destined spend most if not all of their lives hunting for basic necessities. Or are they? It's interesting how those  things that are the most important to us turn out to be our greatest weaknesses. In fact, this is inevitable for all living things. Evolution changes any organism so that it adapts to thrive on whatever is most abundant in it's environment which means that most living things are completely useless outside their natural habitat.

But can we make an exception for humans? Yes we can, in a way. We're clever enough to take our environment with us wherever we go. We were clever enough to walk on the moon! (a moment of silence for Neil Armstrong is appropriate I think).

So can those three things up there really be considered life's priorities? Yes, they are but they re not priorities I would choose. Sure, there are plenty of people who are completely satisfied if they have plenty of those stuff. Suddenly Maslow's Hierarchy of Needs comes to mind.



I'm wondering now, how true this is. I'm wondering how many people actually get past the third level. How many people break out of the monotonous work-eat-solve life's problems-sleep cycle and actually think about the more interesting stuff like how the universe began or what are the laws behind the beautiful complicated dance all the atoms in the universe perform so tirelessly. I wonder out of all the 7 billion people on earth, how many people look up at the stars regularly and take a moment to appreciate how very far away they are from us. Then again there are pragmatists who claim that all that is unnecessary. Why should we do all that when we can be perfectly happy otherwise? Well, I think we should do it just because we can. Out of all the species on earth humans are the only ones that can appreciate the fact that all the atoms in their body was once part of a giant supernova. Only human brains can do that. What a complete waste it is to not grab the opportunity to do something like that! Things like that are my priority. There should be a dichotomy between "priority" and "necessity". Necessities are things that we need in our life that we had no choice over. Those things which you need to seek whether you  like it or not. "Priorities" should be what you really want. I would gladly trade my ability to eat for a chance to view the vast depths of the universe from a transparent bubble floating through space. I would gladly give up my ability to breathe if given a chance to travel at near lightspeed (and maybe beyond) and explore the entire galaxies from my transparent bubble. But then, is giving up eating and breathing really a sacrifice at all? If eating is a necessity that wasn't our choice, then wouldn't giving it up be like getting a superpower? In that case it's not really a sacrifice at all. The only reason I eat is to prevent my body from breaking down. The only reason I breathe is to supply my brain (and its mode of transport, my body) with oxygen for normal functioning. If I could maintain life without these functions, if they figure out how to upload my consciousness into a robot, I would be one of the first in line. It would eliminate the need spend so much time maintaining my hardware.

It's getting dark now. I can see the first stars winking at me. The stars are so tiny. They really are very far away. And here I am on this tiny corner of the universe, a bunch of atoms that have come together for a negligible fraction of the lifetime of the universe. A small subset of these atoms in my head are doing a complicated dance with other atoms, changing electric potentials inside and outside my neurons using energy from ATP molecules. These waves of polarization and depolarization are travelling back and forth through this immensely complicated biological neural network, a process that is right now allowing me comprehend the fact that the universe exists, the fact that I exist.

And with a jolt I realize that I am a part of the universe that has become self aware!! Here's a little part of the universe that is thinking about itself! Here's a bunch of atoms that are billions of years old and still following the laws of physics just as they were billions of years ago. And these bunch of atoms are thinking about themselves!? The thought sends a shiver down my spine, a sudden passing sensation of excitement, a shudder of emotion from the epicness of it all.

The twilight deepens, and the mosquitoes start their relentless attack on my legs. I walk back to my room slowly, drunk on the beauty of the universe. 

Monday, 16 July 2012

The Chaos Walking Trilogy


Here is what I said about fiction from a previous post:

"Another mark of a good story is how it draws you in. Many books (like Eragon and Harry Potter) talk about worlds in which, deep inside, everyone wishes to live in. Reading them makes me want to live the book so badly that sometimes I can't help laying awake at night thinking of all the cool, amazing things I would do if I were in the place of the protagonist."
No book I've ever read so far does this more perfectly than the Chaos Walking Trilogy.

I read the three books in this trilogy with a level of concentration that had eluded me for over a year. I've never come across a book with such endearingly real characters and such a realistic and deeply moving plot. The author manages to keep the plot complex and events unexpected without the use of unbelievable coincidences. I also found the whole concept of Noise and how the plot revolves around it incredibly original and creative. It's original enough that for the first time in many years I found it impossible predict the plot. A very worthwhile and enjoyable read.