piatok 22. apríla 2016

Running – Biology in practice

Even a runner's body produces energy in this way.
Since my High School I have been a fan of ceteris paribus – "given all other factors unchanged". Today I came to feel again that sometimes it does not hold, and the results do not approximate the expectation.
I went for a good run on Tuesday night. I did not expect the weather to be so windy and cold, so I had to put on a hoodie (I never do). It was in the evening; I was a bit tired: hardly ideal conditions. After a few kilometres on the city pavements, I hit the runners'/cyclists' lane and could accelerate. The whole run felt very good, I covered 13 km at 4:41 min/km. The last 10 km were at 4:41. Here are the data:

km avg. pace
1 05:11
2 05:08
3 05:00
4 04:49
5 04:37
6 04:44
7 04:40
8 04:29
9 04:29
10 04:31
11 04:30
12 04:30
13 04:23

avg. 04:41

I knew it was a useful workout. So over the week I thought about replicating the intensity. This morning I got a chance to run, so I put on my running shoes and set off. I intended to hold back for the first two kilometres, then accelerate to 4:30/km, and fade out to 5:00/km at the end, all in 11 km. The conditions seemed perfect: I was fresh (morning), had better shoes on (I did run in fivefingers the other day), and did not need a hoodie! Yet it did not work out as planned:

km n. avg. pace
1 04:46
2 04:47
3 04:30
4 04:36
5 04:39
6 04:54
7 05:32
8 05:07
9 05:32
10 05:27
11 05:09

avg. 04:59

What happened? Based on my feeling during the run I suspect the two important factors (the ceteris paribus not met) working against me were energy and tiredness. I avoided running hungry on Tuesday by eating two snacks (horalky) about half an hour before the run. This morning I had a banana (and not much last night). Perhaps unsurprisingly, I felt like unable to keep with 4:30 at kilometre 4, and 5, and all but abandoned the ambition of 6 or 7-km span at 4:30. It felt a bit like in some marathons: you will to go on or accelerate, but the return is modest. Cardio feels ok, but the legs do not respond well. Empirically, this would suggest that two (early) horalky are better fare than a banana. More importantly, a half-empty stomach is not good enough. 
The other factor is tiredness. Had I felt soreness in my muscles, I would not have been so adventurous. Still, I must have forgotten Pfitzinger's rule of thumb for tempo runs or long runs: keep 4 days between them (P. Pfitzinger: Advanced Marathoning). I did not. I'll learn.

Perhaps I will be able to get close to 7-10k at 4:30 soon. Obviously, I need some time off first.

utorok 5. apríla 2016

Programming is thinking!

"In search of a new car, the player picks a door, say 1. The game host then opens one of the other doors, say 3, to reveal a goat and offers to let the player pick door 2 instead of door 1." Taken from wikipedia
A colleague of mine, Lisa DiIorio like saying that writing is thinking. A part of me tends to disagree fiercely, but I still have to find solid evidence that it is not. If I really wanted to argue, I might start proposing writing Vogon poetry or something woefully associative and irrational. On the other hand, I have seen how right she might be. Today Lisa's mantra showed her truth when I tried to solve an old puzzle by ogre-like piece of programming.

I distaste the Monty Hall problem profoundly. My main reason is that it does not figure intuitively. In order to get a reward (a car), you are to guess the correct one of the three doors. As soon as you make your choice (say 1 or 2 here), you are shown that one of the options you have not chosen (3 here) does not get you the reward (a goat is not considered a reward). Should you switch?

I have remembered that I should switch since a student presentation in 2013, though I did not find the argument (proof) easy to reproduce. And it sounded arcane. Similar to the statement that DNA-helicase splits the double stranded DNA – it's name is -ase (analysis), DNA is double-stranded helix ... guess it figures.. I had less enthusiasm for the Monty Hall switching strategy because it lacked even nominal sense. (I did not forget about the proof.)

Thinking about an introduction into probability, Monty Hall came up today. I dared to ask myself – can I look into it properly? I told myself it would be best to write a simulation testing the two alternative strategies: switching vs. not-switching.

The basic architecture of the program is simple: generate N (~1000) random integers between 1 and 3. Do it twice: the first set (array) corresponds to secret locations of the car (Reward), and the other corresponds to the Guesses. Call the strategy function with the two pieces of information and your choice of strategy (not switch or switch) to get your success rate. What does the evaluation (strategy) part function do?

For case of non-switching, it compares corresponding elements of Reward and Guesses and calculates the frequency of such occurrence. By virtue of Law of large numbers this should be close to 1/3.
Let's look at the switching. There are two cases. In the obvious one (A), my original guess was correct, but I dutifully switch to a non-reward option. Bad. In the other case (B), I was wrong, and as I am shown the other incorrect option, I choose the right one.

As I was about to start coding the switching part, the proverbial light-bulb seemed to light up. The probability of the first scenario (A) is 1/3, and it gives me goats. Zero. On the other hand, the second scenario (B) occurs with probability of 2/3, and I always win there. Eureka!

Even though I have a proof, I still run the the program. Winning in 66.75% for a switching 33.19%  for non-switching for runs of 100,000 tries. Job's well done. I suppose I understand the MH puzzle/paradox a bit better.

I guess programming is thinking as well:)