Main

October 20, 2008

The Direction of Time

What determines the direction of time?  At first, this seems to be a non-question: of course time flows in the direction it flows.  But physicists deal with many ideal systems that run equally well in both direction. The physics of the past look just like the physics of the future.  This is true of colliding billiard balls and very simple planetary systems.  If the evolution of a physical system is symmetric in time, what makes time flow one way and not the other?

The common explanation is that when we look at complex (real) systems, the Second Law of thermodynamics, that entropy--approximately disorder--increases with the flow of time, dictates the direction of time. Our habit of seeing this everywhere explains the fascination with a movie of spilled milk being played backward.  It is surreal to see the milk go back inside the glass as it reassembles for the shattered pieces.

This explanation of time's direction is usually presented as a logical rather than causal explanation.  Good for all you physics students who listened to your professors explanation of time's direction and the Second Law and said, hu, what?

In Ilya Prigogine's book The End of Certainty, he argues that the long-time explanation of the direction of time depending on the Second Law of thermodynamics requires an update. To illustrate the starting point, he builds a simple model with a deterministic (i.e. does the same thing given the same starting point) chaotic systems.

The argument behind the simulation explained below goes like this.  There are structures that emerge and evolve in complex dynamical systems that (a) don't have any iterations between the particles and (b) evolve asymmetrically in time.  Thus, the Second Law is not adequate to explain the direction of time.

The simulation below uses a very simple chaotic system, the Bernoulli Map. The equation of motion for each of an ensemble of particles is x(n+1) = 2x(n) mod 1. The new position, x(n+1), is calculated from the old position, x(n), by multiplying by two, then removing the integer part so the new position is between 0 and 1.

Chaotic systems are characterized by exponential divergence of trajectories that start out close together.  Contrast this with a pendulum.  When we have two pendulums of the same length and mass and we start one off at a slightly different point from the other, they just swing back and forth slightly off synchronization.  But the gap doesn't grow over time.

In the Bernoulli Map, trajectories started out arbitrarily close diverge exponentially.  The rate of divergence is measured by the Lyapunov exponent. The plot below shows the distance between two trajectories starting off very close and evolving according to the Bernoulli Map.  The plot is on a semi-log scale; the slope of the line is the Lyapunov exponent.

Lyapunov Exponent


Now we start many many particles together and watch the distribution of the particles along the x axis evolve.  Notice that as time evolves (in the right direction!) the trajectories become uniformly distributed.  This system does not evolve the other direction when run backwards, but rather continues to normalize the distribution.  This is in spite of the fact that the particles do not interact or exchange energy (as they would in a gas coming to equilibrium, for example).

 

 

Bernoulli Map ensemble distribution evolution


The Python code creating this example are available for download--Bernoulli Map.

October 11, 2008

Recursive Play

A few days ago, I needed to collapse any depth of nested lists to a single list.  Using the ability of a Python function to call itself (recursion), one is able to write a short and fairly straightforward routine for flattening a list containing any number of nested lists.

Here is the function I wrote:

def recursive_list_collapse(x):
    if type(x) == type('a') or type(x) == type(1) or type(x) == type(1.1):
        # if the object is already a charater,
        # just return it as a list of 1 char
        return [x]
    else:
        # if the object is a list, step through the objects
        # in the list and call myself with each object
        tmp = []
        for a in x:
            tmp += recursive_list_collapse(a)
    return tmp


Wikipedia has a nice article on Recursion.

It's not quite true that the method will collapse any number of lists--the depth is limited by the number of recursive calls to the function that the environment can support.  Each time the method is called, the environment must store the information from the currently running method so that it can pick it back up again when the function call on the next to last line returns it's sublist.  If you run out of scratch pad space to remember where you are, the methods cause an error.

The Wikipedia articles doesn't make much of a concept that is tied to recursion.  Strictly speaking, recursion is infinite. But to do something useful, we need to stop at some point.

Pure recursion goes all the way down, but with self-reference (a model of self that allows decision making), recursion can be terminated and do something useful.  It is difficult (impossible?) to find the "bottom" of the recursive method without some type of self-reference, without a model of at least part of self. In the method above, I use the ability of Python to look at the type of data in the list to determine if (a) it is another list--therefore, to recursively call itself with the sublist; or (b) if the item is a fundamental type, don't call the function again. Other recursive methods add a counter to the type passed in the recursive call--meta data--to keep track of self.

To explore the self-reference idea in another way, I rewrite the a non-recursive version of the method that uses a string manipulation algorithm.  This output is identical to the routine above.  This time, the method is to change representation to a string, manipulate the string to remove the "extra" list markers.  But you can't just leave it a string, or it is not the same method. Here's the interesting self-reference part--Python allows you to execute the string as a program statement to turn it back into a list type using exec('r='+ string_manipulation(example)).

 

def string_manipulation(x):
    last = ''
    candidate = ''
    tmp = ''
    # walk through string with all spaces removed
    for c in str(x).replace(' ',''):
        if c == '[' or c == ']':
            candidate = ','
        else:
            candidate = c
        if last != ',':
            tmp += candidate
            last = candidate
        elif candidate != ',':
            tmp += candidate
            last = candidate
    return '[' + tmp[1:-1] + ']'

 

Neat.

P.S. This post was a strange coincidence as BFD emailed after I had started it to talk about recursion. Neat.

Continue reading "Recursive Play" »

August 13, 2008

Synchronizing Fireflies Link

This is a really cool project.  It combines a great example of collective effects like the weakly coupled pendulum experiment with a simple extension of the Programmable LED project.  Nice work Tinkerlog!

July 09, 2008

Fun Fractal Music Video

I saw this on Brad Feld's blog today can't resist passing it along...

May 08, 2008

Coupling and Synchronization Video

There are many natural examples of synchronization of oscillations due to resonance and very small couplings.  But there aren't many prototypical cases that show the effect so clearly.  Bad Astronomy posted a great video and explanation today.  Here's the video:

 

August 06, 2007

Survivor Bias – What does “random” survival look like?

Imagine a sales team of 1,000 salespeople working for Acme Widgets. The management philosophy at Acme Widgets for the last 20+ years has been that they let the bottom 20% of performers go every year and replace them with 200 new salespeople to keep the sales force at 1,000. In this way, they keep the best people around and give newcomers an opportunity to join the group of winners.

Under this (contrived?) scenario, what is the composition of the sales force?  Can I identify a veteran salesperson who survives many years based on their sales skills? Does the sales force look different if the salespeople survive based on skill or due to random attrition of 20% per year? 

To try to understand where my intuition might lead me astray, I ran a simple model of random attrition of 20% of the sales force every year for 20 years.

Below is a table showing surviving sales people from each year back to 1982.  These are the sales people who are still working for Acme Widgets.  For example, 14 of the 200 new recruits in 1995 are still with Acme Widgets, while only 2 of the 200 newbies in 1987 have survived.

 

Year

Employees remaining who started in Year

2007200
2006160
2005128
2004102
200382
200266
200152
200042
199934
199827
199721
199617
199514
199411
19939
19927
19916
19905
19894
19883
19872
19862
19851
19841
19831
19821

 

Now imagine the conversations between the new recruits and the old timers... 

First, all the old timers will have noticed that new recruits “just aren’t made like they used to be.”  That is, they drop out at an alarming rate. Notice the large gaps between the numbers of survivors in the first few years.  “You can’t count on these guys being around long.” Thankfully, the old timers don’t disappear nearly as fast.

Second, stores old timers tell of their sales exploits are likely to be of “skills needed for survival”—otherwise why would they have survived so long when nearly all of their contemporaries are gone? (And there is no one around to argue otherwise—“Survivor Bias”.) 

Further, everyone except the first year recruits has survived their entire time at Acme Widgets. So anyone you talk with will report that they are among the successful. The shorter-timers may be skeptical of their long-term prospects, but the longer they survive the more likely they are to identify as a survivor.

Third, more than half of the sales force has been there for 3 years or longer. This looks like stability. The high attrition rate would horrify the survivors if it left empty desks (or bodies).  But Acme keeps the floors clean and the total sales force at 1,000 persons. On any given day, the desks are full and the sales team is hard at it selling the Widgets.

Does a sales force that identifies and keeps skilled sales people look any different? If so, how? 

In our random example, 10% of the group at any given time has survived 10 years or more. These could be the “old horses” (had some big years early on so Acme keeps them around) or the superstars (had many big years). Does our perception of the proportion of the population that are superstars merely fall out from laws of random attrition?

These numbers come from random selection of the bottom 20%.  Without models of individual attributes, this I what the population looks like. 

I don’t want to argue against skill nor against promotion on merit. But I find the fit of the World to this randomness explanation troubling…

Here is the table for 40% attrition per year.  This might be appropriate for something more risky like forecasting markets (or anything really).

 

YearEmployees remaining who started in Year
2007400
2006240
2005144
200486
200352
200231
200119
200011
19997
19984
19972
19961
19951
19941
19930