Gini Coefficient and Income Distribution
The gini coefficient is a measure of income inequality. It is calculated by ordering the given population by income, then calculating the cumulative distribution, and finding out how much it deviates from total equality.
So for example, assume there are four people, and everyone makes the exact same amount:
Then, the cumulative distribution just sums the values to the left, so for this hypothetical equal society of four, the cumulative distribution would look like this:
So, as you can see, the cumulative distribution would be a straight line. The gini coefficient is calculated as two times the area of the difference between this straight line and the actual distribution. Since in this hypothetical world, the distribution is totally equal, it follows that the gini coefficient is 0.
The way to read the gini coefficient is that 0 is totally equal, and 1 is totally unequal. In the totally unequal case, one person would make everything, and everyone else would make nothing:
As is probably obvious at this point, the gini coefficient can be any real number between 0 and 1, with lower meaning more equal, and higher meaning less equal.
However, reality is always more interesting (and messier). The real world gini coefficient in 2014 of the United States 0.42, and Switzerland is 0.31
By modeling the cumulative distribution function as a power, such as x^{n}, you can find an n that reproduces the same gini coefficient:
In 2013, the United States had a gini coefficient of 0.42, which corresponds to a distribution curve that is about x^{2.45}, by contrast, Switzerland has a gini coefficient of 0.31, which corresponds to a distribution curve that is about x^{1.9}
It’s important to note that the cumulative distribution function is most likely not a simple power, but this shape does give a decent guess at what the respective distributions might look like.
Also, the gini coefficient says nothing about the absolute standard of living, meaning that a rich country and a poor country could have the same gini coefficient. For example, Norway and Czech Republic both have a gini coefficient of about 0.25, but Norway’s GDP per capita is about 5 times more than Czech Republic’s.
Given these limitations, the gini coefficient is a useful number for getting an idea about how income is distributed in a given population.
Script for Logging Standing Desk State Transitions
At work I have an adjustibleheight desk, that way it can be both a standing or a sitting desk. In order to better understand my own usage habits, I made the desk script, which logs state transitions.
Running desk up
records the time that the desk was moved up into a standing position, and desk down
records the
time the desk was moved into the sitting position. Later, when I have a few months of data, I’ll do some analysis and
see what the probabilities are in the following state transition diagram:
The script builds a CSV file, and implements a simple interface:
1 2 3 

Here’s the source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 

This will allow me to use a Markov chain to model my sitting/standing habits. More on markov chains in a later blog post.
On the health benefits (or problems) with standing, I am not a medical professional, but I think alternating sitting and standing is probably better than all sitting or all standing.
Visualizing the ‘Belongs to’ Relation in Rails App Models
When working on rails apps, I usually have to make a mental map of the models and how they interrelate.
An Active Record model can belong to another, but when you have more than half a dozen models, keeping all the belongs_to relations in mind quickly becomes impossible. As a solution to this, I made a command line program called argraph, for ‘ActiveRecord graph’, it produces a digraph in the DOT language, which can be rendered as an image using GraphViz.
The nodes are models, and the edges are the ‘belongs to’ relation.
The way to use it is to check it out or fork my bin repo, make sure that directory
is in your PATH variable, cd to the root of your rails app and run argraph
.
As an example, suppose you have the discourse rails app checked out, and you want to find out how some of it’s models are interrelated:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 

The above graph renders as:
You can also run the command with no arguments, in which case it maps out all models, but on bigger apps, this can be hard to follow, so I found it useful to be able to explore subgraphs containing more models than my memory could fit, but not so many that the image was polluted and hard to follow.
Traveling to the Future
Traveling to the future is easy, everyone is doing it at 1 second per second. There are a few possible ways to beat this though, one is relativistic, and the other is thermodynamic:
Special Relativity
For time dilation, you can simply travel at a very high speed. The time dilation (or Lorentz) factor is
So suppose you are flying away from Earth at v meters per second for t seconds, then your clock is slower by a factor of γ. If you turned around and traveled back at v meters per second, you would arrive at Earth having experienced 2t seconds, whereas γ(2t) Earth seconds would have passed.
As a concrete example, suppose you traveled away from Earth at 99.49% the speed of light for 10 years, then γ = 10, meaning that 100 Earth years would have passed. Then, you turn around and head home at the same speed, after 10 years, you arrive. However, if you left in 2014, you would have aged 20 years, but it would be year 2214 back on Earth, you would have effectively traveled 200 years into the future.
The big thing preventing this from being applied any time soon is energy. Kinetic energy is given by ½mv^{2}
Assuming the spacecraft has the same mass as the SpaceX Dragon capsule, which is 6,000kg, The energy of motion for traveling at 99.49% the speed of light would be (1/2)(6000kg)(0.9949*c)^{2} = 1.868x10^{20}kg m^{2} / s^{2} or about 0.44 times the amount of energy consumed by the world in 2001.
While that amount of energy is available to humanity, it would need to be carried by the spacecraft, which would add to the mass. The relativistic option may not be possible until humans become a Type II civilization.
Cryonics
The trip to the future using cryonics would require far less energy than the relativistic one.
All that needs to be done is for a cryoprotectant (basically, antifreeze) to be flooded through the body so that most of the water molecules have been replaced with the cryoprotectant, then, cool the body to 196°C (Liquid Nitrogen temperature), and wait 200 years.
There may not be a functioning civilization in 200 years, or even if there is, they may not have the technology to undo the effects of being saturated with a cryoprotectant and cooled down to such low temperatures.
However, recent developments in suspended animation of humans to buy time while fixing tissue damage suggest that this will be possible, and it may happen in less than 200 years.
Either way, as long as there is a stable civilization with a steady supply of liquid nitrogen, people from our time can stay in a suspended state, where the chemistry of life has stopped, until some time later in the future when medical technology is advanced enough to revive them.
USA FREEDOM Act Passes House
About 9 months ago I wrote about NSA bulk spying and how the way the FISA court is being used upsets the balance of powers in the government, the two bills I referenced have a 4% and 2% chance of being enacted, according to GovTrack. Both of those bills still haven’t left the House, and chances are they won’t.
A more promising bill is the USA FREEDOM Act, which just passed the House:
Unforunately, Rep. Justin Amash noted that the changes to it are so bad, that most of the original cosponsors are out:
Just how bad were changes to #USAFREEDOMAct? MAJORITY of 152 cosponsors voted NO. Roll call: http://t.co/2kaG5hrmw1 http://t.co/13gUpANOEN
— Justin Amash (@repjustinamash) May 23, 2014
Also, the EFF doesn’t approve. Fortunately, Sen. Patrick Leahy said he intends on fixing a lot of those problems in the Senate version of the bill.
It’s easy to get cynical and fatalistic about the erosion of civil liberties and the problems in government, but recognizing the problems and paying attention, putting pressure on congress can make a difference. Stay rational and contact your representative and senators.
Remember that the Congress is the most powerful branch of government, it makes and destroys laws, with or without the President’s consent (1). Each and every member of congress cares about what we citizens think, because they wish to be reelected, and we elect them. They are more accesible than you might think.
(1) Even if the President vetos a bill, Congress can still override with a 2/3 supermajority in both houses