Friday, September 27, 2019

Fun with numbers for Sep 27, 2019

Near-miss asteroid? Pah!


Asteroid 2017 KP27 just missed Earth on Sep 26th; well, missed by almost 1 1/2 million km, but considering how big space is, that's a close-ish call.

Whenever one of these close calls happens there's a lot of Tweeting and Facebooking and Instagramming, not to mention the ignorant bleating from the absurdly ignorant of science official voice of the establishment traditional media, about how we could have all died just-like-that. Where are Ben Affleck and Bruce Willis when we need them?

Not so fast. (Literally, that's the issue: velocity squared.)

Asteroid 2017 KP27 relative speed in this pass was 4,805 m/s and its diameter is between 19 and 42 meters. There's no estimate of its mass in the Nasa database, but we can make a few approximate calculations. Generally these asteroids fall into three types: carbonaceous (think giant snowball, only made of methane and carbon dioxide), silicate (big rock), or metallic.

Data from Krasinsky et al. (July 2002) "Hidden Mass in the Asteroid Belt," Icarus, 158 (1): 98–105, puts densities for these three types at 1.38, 2.71, and 5.32 g/cm$^3$ respectively.  (Source: Wikipedia for the reference and the actual article for the numbers, viva la public library proxy server.)

Assuming as reference cases the two extremes in diameter and using the geometry of a sphere (we're just doing order-of-magnitude calculations, really), we can compute the kinetic energy KE for both this close call and the next time we pass asteroid 2017 KP27 (Sep 15, 2020; closest approach will be 44 million km at a relative speed of 13,178 m/s):


As is clear from the table, even at its higher speed in 2020, this puny little pebble is at best a single city-buster, while at its recent speed it carried less energy than a theater-wide tactical nuke.

So, not the ELE some people feared. Still, could ruin your day if it landed within the same neighborhood.



Visible from space? Double Pah!


From Orson Scott Card's The Swarm:


Visible from space isn't really that distinctive, in fact it's positively common, as long as there's enough color and light contrast. For purposes of this analysis, space starts at an altitude of 100 km (could also be 80 km, but, what the hay, I like round numbers in metric).

I can see objects 1 m tall at a distance of 1 km, and I'm not exactly hawk-eyed, so an object more than 100 m along its smallest dimension should be visible from space by someone like me (possibly much smaller, for people with better vision who didn't spend most of their life reading, coding, writing, or doing math), as long as there's enough contrast with the surroundings.

My heavy-reader eyes have a resolution of at least 1/1000 radians per pixel (actually more, since I can see some detail in 1 m objects at 1 km, but let's keep it simple), which is 3 minutes and 26.3 seconds of angle [in degrees].

For comparison, the Cheyenne Tactical M200 Intervention marksmanship rifle has sub-MOA (Minute Of Angle) accuracy at over 2000 m. (A pair of these rifles are important in Red Metal by Mark Greaney, a [mostly] good piece of MilFic I recently read. And, no, it's not a Grey Man novel, it's a different storyline.)


Monday, September 23, 2019

Weight loss, moving averages, and cheating.

If you don't measure it, you can't manage it. — Old management consulting saying.

Like most people who do HIT, I track all my gym data; unlike most people who do HIT, I use fancy-pants (technical term) algorithms to analyse it. (Hey, if you gots thems, you uses thems.)


I also weigh myself almost every morning, and log the weight. But since I noticed clothes getting looser, I didn't actually analyse the weight data. There it was, in a nice .csv file, and nothing ever done to it. Not even a chart.

To be fair, when you lose 22 percent of your bodyweight in 7 months, you don't really need a chart… What?! Who are you and what have you done with Jose Silva?? Data without analysis is just wasted bits!

So, I decided to see if there was any insight there. And, lo and behold, there was.

The problem with bodyweight data is that it's too noisy. Small things, like whether you've been to the throne prior to weighing or had a few gallons of caffeine delivery liquids earlier can make your weight vary a lot. And bathroom scales, even digital ones, can be quite a bit off depending on how your weight is distributed over the platform.

One way to deal with any noisy sequence data is to take moving averages: by averaging a data point with its neighbors, idiosyncratic noise is cancelled out and only information stays. Of course that's only correct if the spectrum of the noise fits within the bandwidth of the averaging. So we simplify (in less engineering-centric terms: cheat) and filter the filtered data, or in our case, average the averages.

An average of this type in a time series is called a moving average; say we want to make a five-datapoint moving average, called MA(5). We start by averaging data points 1 through 5, that's our first result; then 2 through 6, for the second, etc. This creates a new time series, the first-order moving average MA(5). Then we take this new time series and use the same process again, which creates a second-order moving average.


(We could choose a different number of datapoints to average, but I'm staying with 5, a number I pulled out of my ars… a number that my old and trustworthy time series textbook uses as "a good starting point." Note also that these averages may be weighted averages to express a specific filtering function. We'll be using simple, or unweighted, averages.*)

For privacy, and because it's actually useful as we'll soon see, we'll plot the data normalized to the time period: in other words, the heaviest weight will map to 1 and the lightest weight to 0:


The dashed line is a linear model fit to the data in the chart (that is the second-order moving average) and it can be used as a reference for analysis. And that reference shows quite clearly that things went a bit wrong around July.

July, July… yep: due to social pressure and a few events where I had to be present, carbs were consumed, or as I like to call it, cheating on the eating rules** was potentiated by outside events. (Always blame the environment.)

Now, the use of normalized results shines when we use the quartiles: how long it took to lose the first 25 percent of the weight, the second, the third, etc:


And this shows what the cost of cheating was: lost time in the weight loss progression. Because of the cheating, there was a delay of about seven weeks to return to the trend.

As a result, I just threw out my last rice cakes. What am I doing eating carbs? If the general idea underlying fat loss is to have the body burn it for energy, there's no [nutrition] point in eating carbs, whose only nutrition function is as energy.

I didn't know about those lost seven weeks until I run this simple data analysis. Now I adhere to my eating rules more closely, seeing what a waste of time it was to cheat. Quantitatively, not qualitatively.

Data without analysis is just a waste of bits.

- - - - - - -

* Since we're using unweighted averages, we could have simply turned that second-order process into a first-order weighted process. (You can always do this, minus the "simply" in the first sentence.) It's easy to see that the second-order MA(5,5) above is equivalent to a first-order MA(9) with weights
\[
   [0.04,0.08,0.12,0.16,0.2,0.16,0.12,0.08,0.04],
\] which is a triangular smoothing function. If we wanted to be fancy about it, we'd use Gaussian kernels with support over the full data set and variable bandwidth, and tweak said bandwidth just enough to get rid of unsightly noise in the data. Yes, by eye… or using information criteria, if we were really really overthinking a simple weight loss analysis.


** The eating rules, derived from P.D. Mangan and Ted Naiman, MD:

1. Eat only when hungry, not peckish or bored. This usually means around 18 hours of fasting daily, for me. Sometimes I eat only one meal in a day (OMAD), though usually I eat two, one of which is a protein shake or Greek yogurt mixed with protein powder.

2. When hungry eat protein (in the culinary sense: meat, fish, eggs, mostly; Greek yogurt with whey protein supplements on occasion, protein shakes when 'needs must'), minimize added fat, and avoid all carbs. Don't count calories or macros or any other pretend-science metric; those only lead you astray.

3. Cheat only at Michelin-starred restaurants and only on someone else's expense account. (This rule is my personal addition. These occasional gourmet cheats are enough to keep life interesting, gastronomically speaking. As for the someone else's expense account, I use mine for important things, like computers, software, and books, not hospitality.)

These worked for me, because they solve the only problem that really matters in fat loss: they're easy to adhere to; note how I'm never hungry for long, as when I'm hungry — and only then — I eat.

Monday, September 9, 2019

Fun with numbers for Sep 9, 2019


So, this might become a thing, blogging augmented tweets.

Rotten Tomatoes is at it again



Dave Chappelle apparently has a Netflix special that has critics and audience at loggerheads. Being a little more quantitative, we can say that the critics are 862,712 times more likely to be using criteria opposite to those of the audience than the same criteria. The logic is in this post.

There are two differences between that blog post and this calculation that are worth mentioning:

1. Computing $c(12352,124)$ without loading special numerical packages that can handle large numbers is beyond the capabilities of most mathematical software, so we use a trick: as we're only interested in a likelihood ratio, and those combinations appear in the numerator and denominator, we know that in the end they'll cancel out, so we ignore them altogether.

2. Small probabilities raised to a large exponent quickly get to the precision limits of the floating point representations; to deal with that we make our calculations in log-space. So instead of computing $0.01^{124}$, which would be well below the 1E-99 ($10^{-99}$) limit for most numerical software, and be treated as zero, we compute $124 \times \log(0.01)$, do all the operations in this log space and at the end we exponentiate the result.

Used Apple Numbers (in lieu of RStudio) for this one, was surprised to learn that LOG is $\log_{10}(\cdot)$ despite Numbers also having a LOG10 function. Oh, well, no problem as long as one is careful:




Tesla bull tries to praise superchargers, arithmetic and hilarity ensue


Sooooo I tried the 250kW charger for the first time and I think I'm in loooooove 🥰 -- Went from 19% to 60% I kid you not in just 5 mins. Thanks @elonmusk @Tesla 🙏

Your battery capacity is 51 kWh?!
5 minutes = 300 s
250 kW * 300 s = 75 MJ
75 MJ = (60%-19%) * Capacity, or
Capacity = 183 MJ = 51 kWh
I thought TSLA batteries started at 75 kWh?! 🤔 Possible explanations:

1. Tesla bull is exaggerating; if it took 10 minutes, or the starting point was close to 40%, that would point to a 100 kWh battery.

2. Tesla software is lying to the car owner, making the numbers look rosier than they actually are.

3. Battery has lost capacity, which happens to batteries because of the underlying principles (two main chemical reactions, one exoelectric, one endoelectric; but secondary, parasitical reactions exist that lower the battery capacity over time). Even for a 75 kWh battery that would be a very big loss (1/3), unless his charging cycles are deep and irregular (that kills batteries faster).



Counting calories is like Enron accounting


Just thinking logically, here, if you were bailing water out of a boat, would you keep adding water in?

Okay, so if you're trying to lose weight by using body fat for energy, why would you eat carbs, whose sole nutrition value is as energy? Why eat when not hungry? *

(Most of the arguments I have about calories are with people who for some reason want others to eat carbs. Counting calories biases you towards choosing carbs over fat, since fat is more energy-dense.)

But more to the point, the whole foundation of calorie counting is Enron-like accounting, where some things are counted (more or less), some things are estimated, and many other things are sort-of, kind-of assumed away in some "basic metabolic energy needs" or other ways of saying "let's assume everyone has the same basic efficiency in chemical energy extraction and mechanical power production."


The lack of accounting for energy lost as heat, which anyone out of shape who's ever jogged with an athletic friend can tell you varies a lot with the person, is the most obvious Enron-like accounting.  Higher body effort for the same mechanical output is reflected in heat loss, and differences in that heat loss can be (as calculated in that figure) in the 100-200 kCal/hour range.

That's the same difference as the mechanical energy difference between jogging and walking.  One hour at the low end of that difference (remember, this is just heat, the mechanical energy is the same for both people) every other day is equivalent to 2 kg of fat extra per year if we believe in the basic model of calories-in calories-out.

Now,  how much difference can there be in unmeasured chemical energy output? Depends on the person and the diet, but note that on a 2500 kCal/day diet a systemic difference of 2%, that is 50 kCal/day, is equivalent to 2 kg of fat extra per year if we believe in the basic model of calories-in calories-out.

Can different people with the same general diet show a 2% difference? Yep. For example, a paper called "Energy content of stools in normal healthy controls and patients with cystic fibrosis," by Murphy, Wootton, Bond, and Jackson in Archives of Disease in Childhood (1991) [thanks PubMed], includes data about the controls' intake and stool. Here are the computations for the first 5 healthy controls:



Yeah, just like that, if CICO were true, these people, on the exact same diet, would show a 3 kg per year weight gain difference. 30 kg per decade.

So, whenever people start talking about calories, be aware that they might be looking for a way to say "you're overweight because of your moral failings; if only you were as virtuous as I am!"

- - - - -
* 1. Carbs are delicious, even addictive. Just be aware of the trade-off: they slow down body fat loss and make you hungrier faster. Because controlling appetite is key to fat loss, that second part is much more damaging than the first. Any "diet" that requires constant attention and self-control is going to fail for normal people with normal lives in normal society: just look around you.

2. There's a situation when I'll eat even though I'm not hungry: if I know I'll become hungry later when no high-protein food will be available and the hunger will be inconvenient or require iron will to avoid eating institutional carbs-and-fat food. Usually this situation can be avoided by taking high-protein foods like Biltong (no, it's not jerky; yes, it's worth the price) or hard-boiled eggs with you, but there are situations when that's socially unacceptable.



Nerding out with science fiction




The book is Dream of the Iron Dragon by Robert Kroese. Highly recommended science fiction.

At $c/3$, each kg of mass in the ship has kinetic energy of 607 TJ, the equivalent of a large tactical nuclear weapon (145 kiloton TNT), or about nine times the Hiroshima explosion. The relativistic increase in mass in small (around 6%, of course), but that velocity-squared, that's the big deal. (At these speeds we have to use the relativistic formula for KE, the one with $mc^2$ in the numerator.)

A table of temporal dilation (it's a highly non-linear transformation):


At 99.95% of the speed of the light, one hour of ship time would be 31 hours, 37 minutes, and 48 seconds in the resting frame. At that speed, each kilogram of mass in the ship would have 2.75 exajoule of kinetic energy or, in big boom terms, about 13 times the energy of the largest hydrogen bomb explosion (the Tsar Bomba at 210 PJ or 50 MtTNT).

Another excerpt of the same book, non-numeric, but very dear to anyone who's ever worked in a large bureaucratic organization:


#NerdWhoMe

Sunday, September 1, 2019

Fun with numbers for Sep 1, 2019

Apple declines to burn 17 billion, Tesla boosters disappointed.


Ross Gerber, a Tesla booster who provides endless entertainment on TSLA twitter, had an interesting idea (the same idea he's had for the last 4-5 years), that Apple should burn 17 billion dollars instead of giving them to people who hold AAPL stock.


The first Tesla car that was targeted at the general public (as opposed to tech billionaires and centi-millionnaires who wanted to be thought as forward-thinking) was the Model S, introduced in 2012. So we'll use 2012 as the beginning of Tesla as a real car company.

As I write this it's Sunday, September 1st, 2019 and the last TSLA close was on Friday, August 31st at 225.61. We'll compare this number with the stock closing price for the closest date for all years 2012-2018 and compute the annualized growth. Then we use that growth to forecast the evolution of an hypothetical Apple stake of 17 billion.


Using a 5-year growth rate for that tweet was basically the textbook default, but looking at that table, the last two columns really tell an interesting story… didn't Ross suggest Apple buy Tesla in late 2017 and in late 2018? Because the numbers in that table say something about financial acumen.


Calories, calories, calories... What a bunch of nonsense!

This marvel of mechanical engineering is the Siemens STG5-9000HL gas turbine. Running in single-cycle mode at nominal power it takes in almost 59,000 kg of LNG per hour or around 900 MW (Calories in: 755 million kCal/hour) and delivers around 400 MW of spinning power to a generator, for about 360 MWe (Calories out: 310 million kCal/hour) of electrical power.

Wait, what? Isn’t it Calories-In-Calories-Out? Is the turbine getting fatter or something?

No. Running in single-cycle mode the system loses around 60% of its power to unrecovered heat.

This is the real problem with CICO and 'Just Get a Caloric Deficit' recommendations: because no one measures the energy lost in radiated, conducted, and convected heat, or the energy content of urine, feces, and ‘outgassing,’ and because those show large variation across people (and across different situations for the same person, including changes in diet), the whole thing is nothing more than pretend science: like astrology made with computers, adding the trappings of science to a flawed foundation yields nothing valuable.

Well, of no real value, but monetizable; and there’s also the moral posturing afforded by telling others that being fat is proof of their lack of willpower or moral failings. (And, of course, since it doesn’t work, leads to continuing supply of clients.)

Thermodynamics is not a magical incantation. But some people use as if it were.


(I'd be willing to bet that 90% of the people who invoke 'thermodynamics' as a magical incantation to ward off the evil spirits of low-carb diets couldn't have made the junior-high Physics computations in that first paragraph.)


More infrastructure


"How can you take photos of those ugly things when there are all these flowers and rocks?"

Me: because when you understand what these things are, you marvel at the detail, at the functionality, and at the fact that they work to begin with. Also, I photograph nature too.