Friday, April 24, 2009

Firefox: system hog

Here's a screen grab from my Ubuntu 8.10 system monitor as I shut down Firefox 3.0.8:

Immediately after shut-down, around 100 MB is released. Then after 13 seconds or so, another 900 MB or RAM is liberated. What??? How can a single code tie up a full gig of RAM. How much memory do I need on this laptop?

I can start it back up again, same tabs, and I'm fine. For awhile. Then I need to shut it down again.

Either this is a memory leak problem (supposedly solved in Firefox 3) or it's a caching problem. In any case, it's out of control.

I've tried Opera, but I'm just not comfortable with that. Google Chrome? Not available yet for Linux. But it's a real candidate.

New bike signs in Sausalito?

Sausalito has passed a plan to "ease the bicycle crunch", including posting signs advising cyclists to "ride single-file". Unfortunately, it's not so simple: cyclists are not required to ride single file, no matter what law makers or enforcers whould like you to believe. Therefore such signs would be misleading. I propose the following, instead:
21202A sign
This does a much better job of describing what cyclists must and should do on the roads. Which when you're riding the speed of traffic on a narrow road, has nothing to do with being single-file.

Thursday, April 23, 2009

Torque Offset

PowerTap
Liar!
My riding so far this year has been really crappy. Hardly a bright spot to be seen: never once have I been climbing thinking "I feel really good". However, when I looked at my maximal power curve, there was one shining exception: the Menlo Park Grand Prix. I had been able to sustain higher power for longer there than I have so far on any climb. But did that make any sense? I'd done the same race in 2008, riding in the pack last year as I did this year, and power was lower. I told myself it was the new course, but that didn't add up. The reality is I wanted to believe I was capable of the numbers my computer told me I was generating on that 8th of March.

Then this Tuesday, "reconfirmation". Despite feeling especially poor in the extraordinary heat, I was able to put up some confidence-boosting numbers during a 5-minute interval on San Bruno Mountain. Nice. Until I was descending and noticed my power hovering around 100 watts, despite the fact I wasn't pedaling. Whoops.

Cycling is a balance between power delivered to the rear hub, the resistance from the rolling tires, resistance from moving through the air, resistance from climbing against gravity, resistance from bearing friction, and acceleration. Sure, when descending air resistance may be considerable. But when descending at a steady speed (no acceleration), wind resistance it's balanced with a negative resistance from gravity. Potential energy is being spent to transfer kinetic energy to the air (eventually heating it). Energy is conserved. There's no way the powertap should read positive power when I'm coasting.

torque histogram
Comparison of torque distributions in last year's versus this year's 35+ 3-4 Menlo Park Grand Prix. Last year I flatted out late in the race, so total samples were fewer. I applied a 2.1 Nm shift in values to this year's data (see shifted curve) to accommodate an improper torque offset on my powertap this year.


PowerTapPowertap reports power, but it really measures hub torque, and separately the rate at which the hub is spinning. Torque times spin rate equals power. The spin rate measurement is rock-solid, but the torque measurement is trickier. Basically, you have an electrical element whose resistance depends on torque. But one day to the next, and one element to the next, the resistance at zero torque may differ. To correct for this, Powertaps have a variable "torque offset" which defines the resistance associated with a zero torque value. This can be set when coasting, using a somewhat complicated set of button pushes, which can only be done when coasting:
  1. left button until top row is selected,
  2. long right push to get power flashing, displaying torque in newton-meters,
  3. long right push to zero this,
  4. short right push to bring back watts.

Fortunately, all of this is usually unnecessary, as unless the option is disabled (doing so involves a far more complex still set of button pushes, or the PowerAgent configuration menu), if it detects coasting of a sufficient duration, it zeros the torque on its own.

The problem with torque auto-zero'ing is the PT must recognize that the rider is coasting. Coasting = zero cadence, and cadence is determined by using patterns in the measured torque. But if the torque measurement is sufficiently wacky, due to a really bad torque offset, it can't accurately determine cadence. This can happen if you swap wheels (the head unit must then be taught to "learn" the ID of the second wheel; yes: another complicated set of button pushes).

At Menlo GP, Cara and I were sharing a wheel, so a head-unit "learn" occurred that day, presumably on mine. Then this Tuesday, I'd left my head unit in my office, so borrowed Cara's, "teaching" it to use my wheel: another wheel swap.

The moral of the story: when you swap wheels with a PowerTap, you must zero out the torque. RTFM. It's not that hard. But relying on auto-zero in this case isn't reliable.

Anyway, my extracted maximal power curve has now been whittled down to a size more consistent with how I've been feeling on the climbs this year. Uninspiring. Road racing has to wait.

Tuesday, April 21, 2009

Li it so - lxu is khg tame pfle lue lid

codeI was looking at my old (very old) high school year book and I came across the following in the quote section:

Li it so - lxu is khg tame pfle lue lid

An obvious cipher. Amazing the author got away with it; less paranoia in those blissful pre-9/11 days. But that aside, I was intrigued as to what the message might be. I tried all the obvious stuff I could think of, some not so obvious, but couldn't crack it. The distribution of letters is roughly consistent with the distribution of letters in normal English writing, so there's no obvious signature of character translation. But I tried anyway, using character rotations from 0 to 25 characters:

0: Li it so - lxu is khg tame pfle lue lid
1: Mj ju tp - myv jt lih ubnf qgmf mvf mje
2: Nk kv uq - nzw ku mji vcog rhng nwg nkf
3: Ol lw vr - oax lv nkj wdph sioh oxh olg
4: Pm mx ws - pby mw olk xeqi tjpi pyi pmh
5: Qn ny xt - qcz nx pml yfrj ukqj qzj qni
6: Ro oz yu - rda oy qnm zgsk vlrk rak roj
7: Sp pa zv - seb pz ron ahtl wmsl sbl spk
8: Tq qb aw - tfc qa spo bium xntm tcm tql
9: Ur rc bx - ugd rb tqp cjvn youn udn urm
10: Vs sd cy - vhe sc urq dkwo zpvo veo vsn
11: Wt te dz - wif td vsr elxp aqwp wfp wto
12: Xu uf ea - xjg ue wts fmyq brxq xgq xup
13: Yv vg fb - ykh vf xut gnzr csyr yhr yvq
14: Zw wh gc - zli wg yvu hoas dtzs zis zwr
15: Ax xi hd - amj xh zwv ipbt euat ajt axs
16: By yj ie - bnk yi axw jqcu fvbu bku byt
17: Cz zk jf - col zj byx krdv gwcv clv czu
18: Da al kg - dpm ak czy lsew hxdw dmw dav
19: Eb bm lh - eqn bl daz mtfx iyex enx ebw
20: Fc cn mi - fro cm eba nugy jzfy foy fcx
21: Gd do nj - gsp dn fcb ovhz kagz gpz gdy
22: He ep ok - htq eo gdc pwia lbha hqa hez
23: If fq pl - iur fp hed qxjb mcib irb ifa
24: Jg gr qm - jvs gq ife rykc ndjc jsc jgb
25: Kh hs rn - kwt hr jgf szld oekd ktd khc


Then I combined these with one-of-n samplings. But no luck. Then I tried reversing letter order and repeating the whole process. Nada. I even tried increasing the rotation count by ±1 each letter position. Zilcho. My brother-in-law pointed out thata sentence beginning with three two-letter words is rare, so I ignored the spaces. No help.

Obviously there's an issue of gamesmanship here. With something this brief, total obfuscation is fairly trivial. So it needs to be something fairly simple. Too complex, and nobody could solve it, and what fun would that be?

I was fairly embarrassed to be unable to break the code. I used to be fairly good at this sort of thing. But I was more embarrassed because I was the one who'd written it. It was my quote.

Tuesday, April 7, 2009

hacking

I'm a bit better than I was yesterday, but still generally out of commission. I drowned my personal sorrows in my sorry physical state by hacking GoldenCheetah, a great project for managing power meter data. GoldenCheetah has been around for several years, but thanks to a recent infusion of excellent contributions from Ned Harding, it's finally become for me a useful tool.

I decided to dive in and try to implement a critical power model extraction technique I've been thinking about. The critical power model says a rider can produce a given level of "aerobic" power (the "critical power", or CP) forever, but additionally has a fixed budged of "anaerobic work" capacity (AWC) which can be spent as extra power. The shorter the total effort during which the anaerobic work is spent, the higher the average power during that period. For such a simple model, it seems to work fairly well.

Power-based training isn't typically based on the critical power, but rather on a "threshold" power which is less sustainable. Andrew Coggan, in his excellent book (written with Hunter Allen) Training and Racing with a Power Meter, advocates the definition of a "functional threshold power" equal to the maximum power a rider can sustain for an hour. Basically start fresh, perfectly dial in your sustainable power, and collapse in an exhausted heap at the end of the hour. Hard to do, obviously.

Since it's so hard to nail the perfect one-hour effort, typically FTP is extracted using shorter efforts. For example, power averaged during a 20 minute effort might be discounted 5% to estimate FTP. But the problem remains: you've got to nail that 20 minute effort. And even if you do, not everyone can sustain the same fraction of power when increasing an effort from 20 minutes to the full hour. For example, Eric Heiden had the record (14:15) up Old La Honda Road, despite the fact that even a quick glance at Eric's legs show he's not a spindly climber-type. Yet he was able to excel at the (by Euro standards) short 390 vertical meters of Old La Honda, whereas he wouldn't rank as high on a climb four times that length. You see this in European racing, where guys like Samuel Sanchez who might break away over the relatively short climbs in Liege-Bastogne-Liege can't always hang with the best up L'Alpe d'Huez or Mont Ventoux.

So I prefer rolling out the critical power model for this purpose. Instead of using a single 20 minute effort, combine two different efforts using the two power values to estimate the two parameters of the critical power model: CP (measured in watts) and AWC/CP, the latter the time during which the model predicts one could ride at double CP (in reality the model breaks down at short efforts, so this may not be attainable). This shorter effort should be long enough that one can fully "spend" AWC, but short enough that AWC is responsible for a considerable fraction of total power, improving the sensitivity of that parameter estimate.

But the rider still needs to do two essentially perfect efforts at these two time intervals. In reality, we often ride hard for various distances or times, but we don't always know ahead of time how long we'll be able to sustain a given level of power. Given a large body of data, wouldn't it be better for an algorithm to figure out from the data itself which interval lengths work best for estimating the CP model parameters?

The scheme I came up with is the following:

  1. Make an initial guess for AWC/CP.
  2. For time intervals from 12 to 60 minutes, calculate the value of CP necessary to match the maximum power the rider was able to sustain for each time period.
  3. Choose the maximum of these CP values as the estimate of CP.
  4. Now forget about the previous value of AWC/CP. For each time interval from 2 minutes to 6 minutes, calculate the value of AWC/CP which would be needed to match the maximum average power sustained over the interval given the current estimate of CP.
  5. Choose the largest of these values as the estimate of AWC/CP, unless the number is less than 30 seconds, in which case use that. The reason for this lower bound is because it's quite possible a set of data lacked anaerobic efforts of sufficient quality. For example, during base training, or during races where there was never the luxury of an absolutely maximal 2-6 minute effort starting fresh.
  6. If the value of AWC/CP changed by more than some threshold (for example 1 milliminute), then use this new value and go back to re-estimate CP.
  7. Then, given AWC and CP, FTP is simply calculated: FTP = CP + AWC / 1 hour.


Once I got over my fear of C++ (I'm basically a Perl hacker) and QWT, relying on the nice examples packaged with the QWT source code, I found it wasn't as hard as I'd feared to implement my algorithm. Here's a result (click on the image for a larger version).

CP Curve
CP model and derived zones with March maximal power curve as displayed by my hacked version of GoldenCheetah

It's a bit busy... first, the black line shows the maximal power curve for a given ride. In the rainbow colors is plotted the maximal power curve derived from all rides in the data set (in this case, March-to-early April rides). The smooth red curve is the critical power model derived to fit these data. That smooth curve is used to estimate the power I could have sustained for an hour, my estimated FTP, and that FTP was used (with Coggan's recommended conversion factors) to generate my seven power-based training zones. These training zones were used to color-code the maximal power curve.

It came out looking better than I anticipated, I must admit. Hopefully some version of this can be incorporated into the official GoldenCheetah release at some point. There's still work to be done.

Monday, April 6, 2009

Idaho Stops

I've been sick the past few days. "Something's going around." But then around here, it always is... I almost don't remember the last time I felt the euphoria of a nice long ride. But on to today's subject.

Stop!

It looks like the Idaho stop may actually have a chance in Oregon. The Idaho Stop is the a law that in general cyclists may treat stop signs as yield signs, red lights as stop signs. Honestly, it's what most people do anyway when they're on a bike. They roll slowly up to a stop sign, check to see if the intersection is clear of cross-traffic, and if it is evident that it is clear, they ride on through without coming to a total stop. Is it always a good idea to roll through stops? Obviously not. Is it true that every time a cyclist rolls through a stop sign they do so responsibly? Obvious not. But then the Idaho law doesn't say it's always okay for cyclists to roll through stops. What it says is (italics mine):

49-720. STOPPING -- TURN AND STOP SIGNALS.
(1) A person operating a bicycle or human-powered vehicle approaching a stop sign shall slow down and, if required for safety, stop before entering the intersection. After slowing to a reasonable speed or stopping, the person shall yield the right-of-way to any vehicle in the intersection or approaching on another highway so closely as to constitute an immediate hazard during the time the person is moving across or within the intersection or junction of highways, except that a person after slowing to a reasonable speed and yielding the right-of-way if required, may cautiously make a turn or proceed through the intersection without stopping.
(2) A person operating a bicycle or human-powered vehicle approaching a steady red traffic control light shall stop before entering the intersection and shall yield to all other traffic. Once the person has yielded, he may proceed through the steady red light with caution. Provided however, that a person after slowing to a reasonable speed and yielding the right-of-way if required, may cautiously make a right-hand turn. A left-hand turn onto a one-way highway may be made on a red light after stopping and yielding to other traffic.
(3) A person riding a bicycle shall comply with the provisions of section 49-643, Idaho Code.
(4) A signal of intention to turn right or left shall be given during not less than the last one hundred (100) feet traveled by the bicycle beforeturning,owing to a reasonable speed and yielding the right-of-way if provided that a signal by hand and arm need not be given if the hand is needed in the control or operation of the bicycle.


For some reason, Idaho has been able to live with this law for 27 years without carnage. Now Oregon is once again proving it is more enlightened than its southern neighbor by treating the idea seriously. The idea of an Idaho stop was floated in San Francisco last year, and the response was a spew of frothy rage. Some of the sentiments:

  • "Cyclists don't deserve to be rewarded with special favors as they show disrespect for the law": First, "cyclists" are not an autonomous group, "cyclists" are people, like all people, who happen to be on bicycles. And among people as a whole respect for the law, sorry to say, isn't very high. How many of these critics report their inter-state purchases and pay the mandated sales tax every April 15? How many cross streets only at cross-walks? How many double-park their obscenely oversized vehicles at church every Sunday? The list goes on.
  • "If you give them a little, they'll take even more." I have never seen any evidence for this. If anything, unreasonable laws breed contempt for the law, not increased compliance. As I just noted, people don't respect the law, they (hopefully) respect each other, and respect more general rules of social conduct. When the law deviates from these general principles, people tend to view the law as silly, and pay it as little respect as they feel they can get away with. What are these rules of social conduct? On the roadways, I'd say they are to be safe, respectful, and predictable. Within this restriction, people then wish to get where they're going as quickly and easily as possible. Really, traffic laws are all designed to promote respect, predictability, and safety. If they fail to do so, they should be fixed.
  • "It's only fair the same rules apply to bicyclists as to cars": This is really dumb. Fair? If the neighbor's kid runs out into the street, I on my bike swerve and avoid him. The guy in the pick-up truck smears him into road kill. What would be "fair" would be that bicyclists and drivers were each held to a high standard of risk they present to their fellow beings. It makes as much sense to conclude cyclists need follow the same rules as drivers as it does to conclude the same standards should be applied to a water pistol as to a 45-caliber handgun.

Anyway, I really hope this thing passes in Oregon. California is California: it like to talk the talk but the reality is in progressive social issues, especially those threatening the supremacy of the car, it often lags behind. But with the more other states move ahead on rationally treating cycling as a specific transportation mode, the more California will be prompted to follow.

Thursday, April 2, 2009

Tyranny of the Farm Box

Every Tue it comes: a new load of fruit and vegetables. And the clock starts ticking. 168 hours left before the next one arrives. It has to be eaten. All of it. 168 hours.


Thus was inspired the Way of the Farm Box:
  1. Cooking must be done using primarily produce from the farm box. Only produce contributing a small fraction to the total macronutrients, such as spices, may be added.
  2. Last week's farm box must be fully eaten before this week's can begin.
  3. All edible parts must be consumed. No discarding broccoli stems.

The clock is ticking. One week to go. Forever ticking. Week after week. Forever.

I don't want to seem to negative. The farm box is a wonderful thing. But I sort of miss eating out more often.