Friday, August 12, 2011

Albert Camus speaks out about the war on drugs in Mexico

Well, not quite; it's actually the Mexican poet Javier Sicilia. But that's just an unimportant detail.
The politicians are formulating the drug problem as an issue of national security, but it is an issue of public health. If from the very beginning drugs were decriminalized, drug lords would be subjected to the iron laws of the market. That would have controlled them. That would have allowed us to discover our drug addicts and offer them our love and our support. That would not have left us with 40,000 dead, 10,000 disappeared and 120,000 displaced…
The war is caused by puritan mentalities: like those of [Mexican President Felipe] Calderón and [former U.S. President George] Bush. In the name of abstractions—the abstraction of saving youth from drug addiction—they have brutally assassinated thousands of young people, while transforming others into delinquents.
Albert Camus spoke a terrible truth. “I know something worse than hate: abstract love.” In the name of abstract love, in the name of God and Country, in the name of saving the youth from the drug, in the name of the proletariat, in the name of abstractions, our politicians and war policy makers have committed the most atrocious crimes on human beings, who are not abstractions, who are bones and flesh. That is what our country is living and suffering today: in the name of an abstract goodness, we are suffering the opposite: the horror of war and violence, of innocents dead, disappeared, and mutilated.
Source.

Actually, it probably means that...

There actually is a sensible explanation of the markets' behavior during the days immediately following S&P's downgrade. There's no way to know if it's true, but it sure sounds good. Here it is:


While it's hard to figure out what investors are thinking, it's pretty easy to guess what they're not thinking. No one is thinking that the US government defaulting on its debt is even remotely possible. But if no one is afraid of the default risk, why the panic? Well, both the panic and the fact that its main symptom was a rush to buy Treasury bonds can be explained by assuming that S&P's decision convinced a lot of investors that very deep cuts to US federal budget are imminent in the medium run. This means that very soon there might be a shortage of medium-term Treasuries. So if you think those are a good investment, better get them asap.

Monday, August 8, 2011

This must mean that...

Investors around the world reacted to S&P's downgrade of the US credit rating by selling out stocks. They also started buying up a whole bunch of US government bonds (see here how yields on medium to long-term Treasuries were decreasing today). Which makes sense, right? In the time of uncertainty caused by the fact that the US federal government is apparently more likely to default in the medium run than previously thought, it's a good idea to invest in the safest assets around, such as medium-term US government debt.


What, my explanation doesn't make any sense? You tell me then.

Saturday, August 6, 2011

An AAA-rated quote

You know, if you had told me a year ago that on august 5, 2011 S&P would downgrade the U.S, and the 10-year treasury would yield 2.5%, I would have laughed at you. I would have said that while there were possible futures in which each of those things happened, they were disjoint futures.
--Brad DeLong

A statistician walks into a doctor's office

Doctor: I'm afraid you have Type I diabetes.
Statistician: That's a relief. I thought I had diabetes.
HT: GregS.

Friday, August 5, 2011

But what if it's done with a smile?

Imagine you became friends with someone who was born and raised in a different culture. Imagine also that, unbeknownst to you, your friend's culture considers smiling at someone to be one of the most insulting things you can do to a person. (This isn't meant to be a plausible situation. It's a thought experiment.) Anyway, you're friends with that person. They're a decent friend, although not a close one. They've certainly never harmed you in any way. Then, by some accident or other, you find out about this exotic culture, and discover that whenever you thought your friend was smiling at you, he was actually expressing contempt.

Would you feel insulted? Should you feel insulted?

Last time about this I promise

I mean the weasel stuff. Well, last time for at least a little while. Toy models of evolution (even as simple as the weasel) are very cool in that they show you how powerful selection is in "overcoming" the complete randomness of mutations. In particular, it is worth keeping in mind that--despite the misrepresentations of some of the intelligent design crowd--the algorithm never "locks in" a character that happens to be exactly righ. The right characters also mutate, at the same rate as the wrong ones, and yet this is no impediment to evolution.

But toy models that are too simple are vulnerable to one particular line of attack: that even though the execution of the process is unguided, design is nevertheless "smuggled into" it via the fitness function. I think it's important to remember that it's incorrect to defend simple genetic algorithms against this attack. With respect to a lot of them (the weasel included), this objection is accurate. But that's just because they are too simple to capture important parts of the evolutionary process. The objection that design is present in the fitness function is wrong with respect to the actual evolution (and more ambitious genetic algorithms) because fitness function only specifies the goal that competing organisms are supposed to achieve, not the means through which they actually reach that goal. And it's only the latter that can be meaningfully called "design." The weasel is so crude that those two categories are actually indistinguishable in it--the goal is to become a string "METHINKS IT IS LIKE A WEASEL," and the fittest organism is the string "METHINKS IT IS LIKE A WEASEL." The point here is that while the weasel is fun, it's not a good poster boy for evolution. If you want an analogy for the evolutionary process couched in terms of computer code and a Shakespeare phrase, think of it this way. The organisms that evolve are not strings of letters but bits of computer code. Their goal is to evolve into the most efficient weasel program (where efficiency can be defined in terms of minimizing number of generations to convergence, or CPU time, or some linear combination of the two). Now it's easy to see the difference between fitness function and the fittest organism. The goal is simple: produce the string "METHINKS IT IS LIKE A WEASEL" as fast as you can. But stare at the fitness function as long as you want, and you will not be able to tell from it how the actual fittest program is going to work. If someone ran this algorithm, I'm pretty sure the winning program would look unlike anything anyone had expected.

Wednesday, August 3, 2011

An even better one

Here's the new and improved weasel program. It removes a major inefficiency of the version I posted yesterday, in that in any given generation only one string was reproducing. Since in any generation (except of course the last two of them), the content of the fittest string need not be unique, it could speed up evolution a lot if we allow all maximum fitness strings to reproduce. The program below does just that. Now with the number of offspring = 100 and a mutation rate of 5%, it never takes more than 30 generations to achieve convergence. The output of R code below displays all maximum fitness strings from each generation.

# A Version of Dawkins' Weasel in R
# (c) 2011 Przemyslaw Nowaczyk
 
Weasel <- function(phrase,num.copies,mutation.rate) {
  Score  <- function(x,y) {sum(x==y)}
  Output <- function(x,y,z) {cat(x,y,z,"\n")}
  alphabet <- toupper(c(letters," "))
  split.phrase <- unlist(strsplit(phrase,""))
  new.phrase   <- as.matrix(sample(alphabet,size=nchar(phrase),replace=TRUE))
  max.fitness  <- Score(new.phrase,split.phrase)
  generation   <- 0
  while (max.fitness < length(split.phrase)) {
    offspring   <- new.phrase[,rep(1:ncol(new.phrase),num.copies)]
    mutant.flag <- mat.or.vec(nrow(offspring),ncol(offspring))
    mutant.flag <- sample(c(0,1),prob=c((1-mutation.rate),mutation.rate),
                          replace=TRUE,size=(nrow(offspring)*ncol(offspring)))
    offspring[mutant.flag==1] <- sample(alphabet,size=sum(mutant.flag),
                                        replace=TRUE)
    fitness <- apply(offspring,2,Score,y=split.phrase)
    fit.id  <- which(fitness==max(fitness))
    new.phrase  <- as.matrix(offspring[,fit.id[1:length(fit.id)]])
    max.fitness <- max(fitness)
    generation  <- generation + 1
    apply(new.phrase,2,Output,y=generation,
     z=round((max.fitness/nchar(phrase))*100,digits=2))
  }
}
 
# sample run with timing
system.time(Weasel(phrase="METHINKS IT IS LIKE A WEASEL",num.copies=10,
                   mutation.rate=0.01))

Created by Pretty R at inside-R.org

Tuesday, August 2, 2011

Weasel

Dawkins' weasel is a toy model of evolution in which the goal is to write an algorithm that evolves the phrase "METHINKS IT IS LIKE A WEASEL" out of a random string of 28 characters via random mutation and non-random selection. The one constraint on the algorithm is that you're not allowed to "lock in" characters; i.e. if one of your strings happens to contain the right character in the right position, you can't exclude that character from the possibility of mutating.

I wrote a weasel program in R, in which the "evolution" proceeds as follows: you draw a random string of 28 characters; the string "breeds" n "offspring," but each character in each of the offspring strings has a probability m of mutating into any character of the alphabet; each mutated string gets a fitness score which is simply the number of same characters in the same position as in the target string; (one of the) strings with the highest fitness survives and breeds in the next generation while the rest are erased.

Below is a sample run of an R-weasel with the number of offspring = 100 an mutation rate = 0.05 (the number to the right of each string is its fitness score):

1 L Z F Z N Y O F N O Z E B I X N P X H B O P U M L A 1
2 L Z F Z N Y O F N O Z E B I N P X H K O P U I L A 2
3 L Z F Z N Y O F N O D E B I N P X H K O P U I L L 3
4 L Z F Z N Y O F N O D E B I L P X H K O P U I L L 4
5 L Z T Z N Y O F S O D E B I L P X H K O P U I L L 5
6 L Z T H N Y O F S O D E B I L P X H K O P U I L L 6
7 L Z T H N Y O F S O D E B I L P X H K O P U I L L 6
8 L Z T H N Y O F S O D E I I L P X H K O P U I L L 7
9 L Z T H N Y O F S O D E I S L P X H K O P U I L L 8
10 L E T H N Y O F S O D E I S L P X H K O P U I H L 9
11 L E T H N N O F S O Q E I S L P X H K O P U I H L 10
12 L E T H N N O S S O Q E I S L P X H K O P U I H L 11
13 L E T H N N O S S O Q E I S L P K I K O P U I H L 12
14 L E T H N N O S S O Q E I S L P K I A P U I H L 13
15 L E T H N N O S S A T E I S L P K I A P U I H L 14
16 L E T H N N O S S A T E I S L P K I A P U M E L 15
17 L E T H N N O S S A T X I S L P K I W P U M E L 16
18 L E T H N N O S S A T X I S L P K I W P U M E L 16
19 L E T H N N O S U A T X I S L P K I W P U M E L 16
20 L E T H N N O S U A T X I S L P K A W P U M E L 17
21 L E T H N N O S U B T X I S L P K A W P U M E L 17
22 L E T H I N O S U B T X I S L P K A W P U M E L 18
23 L E T H I N O S U N T X I S L P K A W P U M E L 18
24 L E T H I N O S U N T G I S L P K A W P U M E L 18
25 M E T H I N O S U N T G I S L P K A W P U M E L 19
26 M E T H I N K S U N T G I S L P K A W P U M E L 20
27 M E T H I N K S U I T G I S L P K A W P U M E L 21
28 M E T H I N K S I T G I S L P K A W P U M E L 22
29 M E T H I N K S I T U I S L I K A W P U G E L 23
30 M E T H I N K S I T U I S L I K E A W P U G E L 24
31 M E T H I N K S I T U I S L I K E A W P U G E L 24
32 M E T H I N K S I T U I S L I K E A W P U G E L 24
33 M E T H I N K S I T U I S L I K E A W P U G E L 24
34 M E T H I N K S I T U I S L I K E A W P U G E L 24
35 M E T H I N K S I T U I S L I K E A W P U G E L 24
36 M E T H I N K S I T U I S L I K E A W P U G E L 24
37 M E T H I N K S I T I S L I K E A W P U G E L 25
38 M E T H I N K S I T I S L I K E A W I U G E L 25
39 M E T H I N K S I T I S L I K E A W M A G E L 26
40 M E T H I N K S I T I S L I K E A W E A G E L 27
41 M E T H I N K S I T I S L I K E A W E A G E L 27
42 M E T H I N K S I T I S L I K E A W E A G E L 27
43 M E T H I N K S I T I S L I K E A W E A G E L 27
44 M E T H I N K S I T I S L I K E A W E A G E L 27
45 M E T H I N K S I T I S L I K E A W E A G E L 27
46 M E T H I N K S I T I S L I K E A W E A G E L 27
47 M E T H I N K S I T I S L I K E A W E A G E L 27
48 M E T H I N K S I T I S L I K E A W E A G E L 27
49 M E T H I N K S I T I S L I K E A W E A G E L 27
50 M E T H I N K S I T I S L I K E A W E A G E L 27
51 M E T H I N K S I T I S L I K E A W E A G E L 27
52 M E T H I N K S I T I S L I K E A W E A G E L 27
53 M E T H I N K S I T I S L I K E A W E A G E L 27
54 M E T H I N K S I T I S L I K E A W E A G E L 27
55 M E T H I N K S I T I S L I K E A W E A S E L 28
user system elapsed
0.09 0.00 0.10

This is not a typical run; it's on the shorter side (for these parameters the median length is something like 70). Note how fast it converges though; R can be quite fast f you do things in vectors and matrices rather than loops.

The next step is to allow the strings to mate and swap their genes.

R code for the weasel is below the fold.




# A Version of Dawkins' Weasel in R
# (c) Przemyslaw Nowaczyk 2011

score <- function(x,y) {sum(x==y)}

weasel <- function(phrase,no.kids,mutation.rate) {
  alphabet <- c("A","B","C","D","E","F","G","H","I","J","K","L","M","N",
                "O","P","Q","R","S","T","U","V","W","X","Y","Z"," ")
  split.phrase <- unlist(strsplit(phrase,""))
  new.phrase   <- sample(alphabet,size=nchar(phrase),replace=TRUE)
  distance     <- score(new.phrase,split.phrase)
  generation   <- 0

  while (distance < length(split.phrase)) {
    m.newph     <- as.matrix(new.phrase)
    offspring   <- m.newph[,rep(1,no.kids)]
    mutant.flag <- mat.or.vec(nrow(offspring),ncol(offspring))
    mutant.flag <- sample(c(0,1),prob=c((1-mutation.rate),mutation.rate),
                          replace=TRUE,size=(nrow(offspring)*ncol(offspring)))
    offspring[mutant.flag==1] <- 
      sample(alphabet,size=length(mutant.flag[mutant.flag==1]),replace=TRUE)
    scores <- apply(offspring,2,score,y=split.phrase)
    new.phrase <- offspring[,which(scores==max(scores))[1]]
    distance   <- score(new.phrase,split.phrase)
    generation <- generation + 1
    cat(generation,new.phrase,distance,"\n")
  }
}

# sample run with timing
system.time(weasel(phrase="METHINKS IT IS LIKE A WEASEL",no.kids=100,
                   mutation.rate=0.05))
Created by Pretty R at inside-R.org

What's the square root of William Lane Craig?

I heard the following quote in a debate to which one party was a philosopher and Christian apologist William Lane Craig (no link, he's easy enough to find if you're into that sort of thing):
Mathematicians recognize that the existence of an actually infinite number of things leads to self-contradictions. For example, what is infinity minus infinity? Mathematically, you get self-contradictory answers.
Assuming that Craig's premise ("Infinity minus infinity is undefined") is true, his argument is ridiculously wrong. To see this, replace his premise with another (true) one, and watch it lead to an absurd conclusion:
Mathematicians recognize that the existence of a number that represents null leads to self-contradictions. For example, what is zero divided by zero? Mathematically, you get self-contradictory answers.
Craig is confusing coherence with applicability. Yes, the division function is undefined for the pair (0,0); but this doesn't mean that "zero" is a self-contradictory concept. Similarly, the fact that the subtraction function is undefined for the pair (infinity,infinity) does not mean that the concept "infinity" is nonsensical. There doesn't exist a single relation defined for all possible things in the world, so when you're talking about relations, you need to remember to stick to their respective domains. If you don't think this is an important distinction, I have a puzzle for you. It's the title of this post.