Wednesday, July 3, 2013

Handy git tricks

Using Git is a blessing, truly it is. Today is just one of those days when I feel like chopping a limb off because git can't understand what I want it to do.
"Restore a file I deleted from my ide, then revert it to its state when I added that line in, then checkout a single file blah blah jabber jabber"

Each time I discover a neat trick to do what I want in git, I shall henceforth make a note of it here :)

  1. Restore a file that you deleted by accident in the repo or Undo all the changes in a file but haven't committed yet.
  git checkout HEAD^ <path to file>

This should bring the file back to the state it is in in the remote repo.

  2.  List all the files included in a commit

git log master

find the commit reference from here eg: 7bdf3a80243c7029508357c45bf4b918ce2bab86
 
git show --name-only 7bdf3a80243c7029508357c45bf4b918ce2bab86

Saturday, September 1, 2012

Cancer killing virus...Are you kidding me?!



I couldn't believe my eyes when I stumbled across this nugget online. Why on Earth hasn't this been plastered over the front page of every newspaper, the top of every science feed list or on billboards along the highway!
Before I get ahead of myself and incite an outrage, let me briefly tell you what I understood of the article.
At Uppsala University Hospital in Sweden, Prof Magnus Essand and his team have created a virus that eats cancerous cells. When a healthy cell is infected by a virus, it dies to prevent the spread of the virus to other cells. Cancerous cells change this behaviour and prevent their sacrifice (this is what make cancerous cells evil). But if a virus can be created to take advantage of this very feature of a cancerous cell, it would enter the cell, multiply uncontrollably and cause the cell to 'lyse' or explode, thereby spreading the cancer-munching virus (babies?) to other cancerous cells. This isn't a new idea apparently!
Oddly enough, in the 1890s, an Italian clinician found that prostitutes with cervical cancer showed alleviated symptoms when vaccinated against rabies. He then proceeded to roam the countryside injecting women with dog saliva. (Sigh!). In the 1900s, a 14 old year old boy with lymphatic cancer, found his swollen liver and spleen return to normal size after catch chicken pox. (and you never thought that you would find a bright side to chicken pox!).
The virus that Prof. Essand and his team have is said to attack neuroendocrine tumours (the same kind that assailed Steve Jobs). The virus, however, is in cold storage, refrigerated until it can go into human trials.
To be reasonable, the virus' success in rats doesn't necessarily translate into human viability, but that's what human trials are meant for! Money, is a blocker (surprise surprise). They need 1 million pounds to go through phase 1 and 2 of the trials and 2 million pounds to develop a better variety (I'm not really sure what this is even supposed to mean. Doesn't the virus either do its job or not? what does it get better at with an additional million pounds worth of research?) In any case, the virus remains unnamed and the team has agreed to name it after the person who donates a million pounds. I quote verbatim from the article
,
To donate money to Professor Magnus Essand's research on viral treatments for neuroendocrine cancer, send contributions to Uppsala University, The Oncolytic Virus Fund, Box 256, SE-751 05 Uppsala, Sweden, or visit www.uu.se/en/support/oncolytic. Contributions will be acknowledged in scientific publications and in association with the clinical trial. A donation of £1 million will ensure the virus is named in your honour

I also found another rather interesting tidbit. The details of the virus have already been published. This no longer allows them to file a patent (who would have thunk!). Without a patent, a pharma company that would have ordinarily take over the expense of the 3rd phase of human trials in order to profit from subsequent manufacturing and distribution when the drug goes commercial, won't think of investing the money. Devoid of an avenue to accrue profits, pharma companies would shrink away into the darkness. Unless....unless the team makes a modification to the virus, and redoes the entire process, this time taking care to file a patent before a publication. Politics in science...is a nasty business.
Here's hoping that the virus does succeed in human trials, that the team does get the money it seeks to continue their research and that patients with NETs (Neuroendocrine tumours) have a lantern bobbing brightly on the horizon.
If this were to succeed, I would be very excited to see how the results could be modified to deal with other kinds of cancers....could we truly be on the cusp of a breakthrough?
Cheering on the Uppsala team, here's wishing them all the very best of luck!


Links: http://www.telegraph.co.uk/science/9508895/A-virus-that-kills-cancer-the-cure-thats-waiting-in-the-coldc.html

Tuesday, June 26, 2012

Afo the Giant Clove tree

This was one of the most interesting tidbits to come out of the 'From your own Correspondent' podcast (An excellent podcast about events from around the world told in the form of first person narrative stories as bbc's correspondents become immersed characters in the tales)
Its about a giant clove tree on top of an active volcano in Indonesia!
The tree is on the slopes of a volcano on one of the Spice Islands of Indonesia called Ternate. At its peak, it used to be 40 metres tall and 4 metres wide, but sadly all that is left of it today is a stump. No one knows how old it really is, but estimate it to be a 350-400 ancient.

After the Spanish and Portuguese were routed from the country by the Dutch in 1652, the very first multinational company (called the VOC or the Netherlands United East India Company) formed between them and the East India Company, started to regulate spice exports. They behaved much like MNCs today do; controlling supply artificially to keep demand and prices high. They would allow only 800-1000 tonnes of cloves to be exported per year and the rest of the harvest would be burned or dumped in the sea! Any clove tree that wasn't controlled by the VOC was razed to the ground. Afo escaped this horrendous fate somehow, perhaps because of its remote location

It seems that man's thirst for money (aka power) is unquenchable, today, 500 years ago and cynically, yet realistically 500 years hence. He apparently doesn't care for anything or anyone that causes so much as a speck on his monetary horizon. That rant aside, what are we to do about our beautiful planet if ravaging her is this deeply ingrained in our psyche?

Links:
BBC article - http://www.bbc.co.uk/news/magazine-18551857
Spice Islands - http://discover-indo.tierranet.com/spiceIslands01.htm
FOOC podcast link - http://news.bbc.co.uk/2/hi/programmes/from_our_own_correspondent/default.stm

Thursday, March 29, 2012

Matlab and Movie making

I realize that this is completely against the spirit of my blog, yet I find myself sighing so loudly with relief at having finally been able to make the 'movie making in matlab' process work for me, that I just needed to put it down here (for future reference and for everyone having the same problem)...Believe me, I know how madly annoying it can be to run an 'addframe' command in loop 5000 times, relinquishing control over your screen for an hour, only to find at the end of this excruciating process that the avi is distorted!!!

In matlab...

filename = sprintf('images/Pic%04d.jpg', index);
imwrite(image_matrix, filename);

In the terminal...
ffmpeg -i Pic%04d.jpg -sameq -r 25 outmovie.mp4
or
ffmpeg -i Pic%04d.jpg -sameq -r 25 outmovie.avi
To slow down the movie,
ffmpeg -i Pic%04d.jpg -sameq -r 25 -vf "setpts=2.0*PTS" outmovie.mp4
To speed up the movie,
ffmpeg -i Pic%04d.jpg -sameq -r 25 -vf "setpts=0.5*PTS" outmovie.mp4

And wala!, I now have a perfect movie :D

Sunday, September 11, 2011

Can machines think?

These are my impressions after reading Alan Turing's 1950 treatise in MIND on the subject of 'Can Machines Think?'

As i continue to read the articulation of thinking machines by Turing, it seems so incredible that he should have conceived such far reaching ideas as early as 1950!

An example of 'far reaching' would be in his definition rather the lack thereof of a pinning down means by which thought in the machine may be sought and its similarity to the fashion in which humans are said to 'think'. I quote "May not machines carry out something which ought to be described as thinking but which is very different from what a man does? This objection is a very strong one, but at least we can say that if, nevertheless, a machine can be constructed to play the imitation game satisfactorily, we need not be troubled by this objection".
My own notes at the time that I read this were as follows :
" he seems to have forseen that the mechanism of 'thought' in the machine is unlikely to be of the same kind as in a human being and chooses to ignore it.
If say, a machine were to have used solely machine learning and data mining as a method to find the answers to all the questions of the interrogator, Turing would not have minded it, for he has chosen to give weightage to the ends and not the means. "

Then we come to his definition of the digital computer as a machine that can do anything that a human computer can do. Though, I yet wonder what exactly the 'human computer' is meant to imply. Could it be that in the post world war 2 era, the code breakers et all who crunched numbers are the 'human computers'. But by mentioning this, I deviate from my main intention. His definition of the digital computer is legendary. He states that it should have three components viz.
1. store
2. executive unit
3. control unit

I have also found what my previous job was all about. As a coder/programmer I now know what programming is actually supposed to mean 'constructing instruction tables is programming'.

He makes a remarkable comment about the notion that scientists always proceed from well-established fact to well established fact without making use of 'unproved conjecture'. In his opinion this is a fallacy. He further notes that as long as fact and ungrounded conjecture are stated upfront, no harm can result from the use of conjecture for it may even lead to new lines of research.

This line I am yet to understand, but he states that his opinion of the original question of 'Can machines think?' is that 'it is too meaningless to deserve discussion'.  !!! I think he might mean that 'Can machines think?' is irrelevant, but 'Are there imaginable discrete state machines that can do well in the imitation game' is what it should be replaced with.

He has discussed counters to some 8 arguments that stem from diverse areas such as philosophy, Lady Lovelace, Mathematics and even ESP!
This is where I found out that ESP has three forms viz. telepathy, psycho-kinesis, clairvoyance and precognition! His argument against ESP doesn't seem to be very confident. I believe that he did not like the idea of ESP being 'around' despite science and not bothering anyone as long as they chose to ignore it. Albeit he admitted that it might be of special consequence in the particular question of thinking machines. In any case, he seems to have left the doubt lingering (perhaps much to his dislike!).

He has compared the mind to the skin of an onion. To reveal the inner working, you would need to peel off the layer of skin. In doing so, one would reveal yet another layer to be peeled off. I'm not sure how this ties in with the paragraph of learning machines!
It seems obvious to us now, but the leap that he made from 'let's programme a machine to play the imitation game to mimic an adult human brain to 'let's programme a machine to simulate a child's brain and let it learn via education to become an adult brain' is fantastic! Machine learning's roots!
He admitted that a child machine cannot be subjected to the same teaching/education process that a human child is. Further, do we need to give it legs, eyes and ears? He dismisses the need by citing the example of Helen Keller!!!

He talks about punishment-reward systems; again the roots of reinforcement learning!
He also talks about how the teacher would be largely ignorant of the internal working of the machine. Unlike the previous idea of a machine having to be told exactly what it needs to do (the progamming part!), and as a counter to Lady Lovelace's argument of a machine being unable to create and being able to do what its been told to do, this new learning machine would be creating and be doing more than it is programmed to do (since it is learning!).

In his conclusion he mentions that there are two ways in which he thinks machines should be competing with humans.
1. Abstract activity like playing chess
2. Give a machine the best sense organs that money can buy and let it learn as a child does.

He admits to not knowing which of the two approaches is the ideal one and that both should be tried.

29 pages of a very interesting read indeed!

Thursday, March 24, 2011

Artificial Trees!

Now, this is an interesting idea! Given hat man is entirely hopeless at protecting the environment and compelled by some inner voice to make ash out of any remaining beauty in his path, this concept might actually take off, if only for the selfish need that we have for oxygen.

The idea is this - create artificial trees that would absorb CO2 out of humidity by a technique called humidity swing (more on this later).  They would also be equipped with solar panels to create energy to drive this process. Further, a see-saw below the tree would encourage people to play on it thereby creating more energy to be diverted to the absorption process. Excess energy would be used to light up the tree at night which would then serve as a pretty street light!
Hmmm....thats the first thought that came to my mind.
And the next one, what is this humidity swing process anyway?
and the third, what would the tree do with the CO2 it extracts from the humidity?
Oh, and another thing, the tree would be made out of recycled plastic from old bottles and what not.


To the second thought....A paper by Klaus Lackner and Allen Wright from Columbia University proposes a method of CO2 capture using a humidity swing sorbent.
Two things here,
1. Humidity swing is the process of raising the relative humidity (called RH ;) )  to a large value for a while and then returning it to normal value.
2. A sorbent is basically an absorbent, a material that absorbs another.
So this is how it works...
1. A dry resin absorbs CO2.
This dry resin consists of +ve ions fixed to a polymer matrix and free -ve ions (OH-)
OH- + CO2 -> HCO3-

2. The resin is wet with water.

3. When the CO2 saturated resin reacts with water it releases CO2 at a higher pressure. The resin is then ready to be used again as in step 1.
2HCO3- -> H2O + CO2 + CO3-
This the resin regeneration phase.

4. Drying of the resin
When the water and CO2 are released, the RH of the resin drops to the original value and it is ready for reuse.

Now coming to the question of the CO2 that would be stored and then released....where would it be stored? What happens to the CO2 when it becomes time to regenerate the resin? Will the saturated resin be unsaturated in an enclosure that traps the CO2 when it is released from the resin? If so, wha would they do with it once captured? Release it into space? solidify it and bury it?
And a new question that has popped into my head just now....where's the O2 in this process generated from? I wonder if the news articles were misleading.... Rather an unsatisfactory understanding at this stage...but when I do get more detailed information, I'll be sure to update :)

Links :
The news article in the bangalore mirror - http://www.bangaloremirror.com/index.aspx?Page=article&sectname=Tech%20-%20Sci%20Tech&sectid=44&contentid=2011031720110317202342266dbf165cd
http://www.worldarchitecturenews.com/index.php?fuseaction=wanappln.projectview&upload_id=16104
The paper - http://www.google.co.in/url?sa=t&source=web&cd=1&sqi=2&ved=0CBoQFjAA&url=http%3A%2F%2Fwww.zero.no%2Fzero-konferansen%2F2010%2Finnleggene%2FKlaus_Lackner.pdf&rct=j&q=humidity%20swing%20klaus&ei=mySMTa2WNcjxrQfw27TQDQ&usg=AFQjCNFlkJLQOAb387Hnp6XM_vGIbdSMnw&cad=rja

Thursday, March 17, 2011

Planes can fly!

It all started out with that blasted xkcd comic! It came up at random and it got my fingers itching to know the answer. So as is my way, i spent an afternoon digging up information, when i finally hit on this gem.

There are a couple of things that need to be noted here :
1. Bernoulli effect : "when the speed of horizontal flow through a fluid increases, the pressure decreases" quoted from wisegeek . I especially liked the analogy about a fluid flowing through a narrowing pipe. It speeds up, but considering that there's no change in mass or gravity, the pressure behind the fluid must have to increase compared to that in front to push the fluid faster.


2. Cambered airfoil : basically this means an unsymmetrical airfoil.


3. To avoid the suspense :-
  • airplanes CAN fly upside down
  • lift is not because of airfoil shape (What a world do we live in when we can't even begin to trust our own school textbooks!), though it does contribute...read on ;)
  • airfoils can be symmetrical, asymmetrical and even flat :D
4. Two criteria are essential to an airfoil :-
  • It should have a sharp trailing edge
  • the trailing edge should be aimed diagonally downward
Now to the explanation.
Oh wait, first off, forget what you read in school about airfoil shape being responsible for anything....hmm, next i'll have to find out what the different shapes are really for!
One answer that I know of is : the camber is there to prevent stall (reduced lift from upper surface compared to lower surface) and to allow a plane to fly at lower speeds


Two explanations of the lift
1. Newton's 3rd law and Coanda effect
2. Bernoulli effect
According to the source that I've cited, both explanations are equally viable and are not competing in any way...they're just both right!
So, on to the first :-
FIRST EXPLANATION
When an airfoil (remember that this can even be a plank of plywood, though it wouldn't be a very good one) goes through the air at a positive angle of attack, both the upper and lower surface of the airfoil are responsible for the lift; a greater portion of which is from the upper surface. The air along the upper surface is stuck to the surface or attached to it because of the Coanda effect (fluid or gas stream will hug a convex contour when directed at a tangent to that surface) and hence it flows along the upper surface and since the trailing edge of the wing is aimed downwards (see point 4 above), the air is pushed downwards resulting in a downwash. By Newton's 3rd law, this produces an upward force on the airfoil. Now, to the lower surface. At the +ve AoA (fancy abbr for angle of attack), the air is pushed downwards by the lower surface, hence the air pushes upwards. These two forces, combine to produce lift. YAY!


REMEMBER
Without the downward deflection of air, the AoA is irrelevant since lift won't be created.

SECOND EXPLANATION
The leading edge of the airfoil splits the airflow current into two, sending one over the upper edge, and another below the lower edge. If the airfoil has a +ve AoA OR if the airfoil has a classic shape (like we've always been taught), then the stream of air travelling above the airfoil will be well over the upper edge.
Enter Bernoulli...The air flow on the upper edge, since it travels in an arc well over the upper edge, causes the creation of a pocket of low pressure. Air therefore rushes in to fill this low pressure area. However, the air flow along the lower edge, since it collides with it, causes a region of high pressure to develop. This high pressure region slows the air stream on the lower edge down. The pressure differential generates a lift.
But the difference in air velocities over the upper and lower edge is caused because of the pressure difference, and not the other way around.

Now that that is all sorted out, lets move on to the airfoil shapes....
1. The classic shape
From above, we see that the classic shape is good in the case we want large lift even at low speeds. Also, it reduces drag significantly.
2. A flat wing
This would require a much larger AoA to generate the required lift. Though, it would still develop the pressure differential and downwash in the same explained manner. But the increased AoA would mean a greater drag.
Helicopter blades are nearly flat. This is preferred because drag is almost not an issue for them. What is required is a maneuverable AoA and airspeed. This is encouraged by nearly flat or tear-drop shaped (symmetrical) blades.
3. symmetrical wings
A symmetrical or tear drop shaped wing (like most planes do), will resemble the classic shape when positioned appropriately. This is why planes can fly upside down. Both lifting phenomenon still work. 

A really good explanation is quoted below from http://www.dynamicflight.com/aerodynamics/airfoils/

"Airfoil sections are of two basic types, symmetrical and nonsymmetrical.
Symmetrical airfoils have identical upper and lower surfaces. They are suited to rotary-wing applications because they have almost no center of pressure travel. Travel remains relatively constant under varying angles of attack, affording the best lift-drag ratios for the full range of velocities from rotor blade root to tip. However, the symmetrical airfoil produces less lift than a nonsymmetrical airfoil and also has relatively undesirable stall characteristics. The helicopter blade (airfoil) must adapt to a wide range of airspeeds and angles of attack during each revolution of the rotor. The symmetrical airfoil delivers acceptable performance under those alternating conditions. Other benefits are lower cost and ease of construction as compared to the nonsymmetrical airfoil"

Other sources were :
http://amasci.com/wing/airfoil.html
http://warp.povusers.org/grrr/airfoilmyth.html