Showing posts with label data science. Show all posts
Showing posts with label data science. Show all posts

Sunday, December 1, 2019

Fun with Numbers for December 1, 2019

007: GoldenEye gets an orbit right


I was reading the book 007: GoldenEye and noticed that Xenia Onatopp's description doesn't match Famke Janssen's looks; oh, and also this:


At first glance, the book appears to be playing fast and loose with orbits; after all, the ISS, which orbits around 400 km, is also on a roughly 90-minute orbit. So, let us check the numbers.

The first step is computing the acceleration of gravity $g_{100}$ at 100 km altitude. Using Newton's formula we can compute it from first principles (radius and mass of the Earth, gravitational constant... too many things to look up), or we can use the precomputed $g=$ 9.8 m/s$^2$ and solve for the altitude using a ratio of two Newton's formulas at different radii (using 6370 km as the radius of the Earth):

$ g_{100} = 9.8 \times \left(\frac{6370}{6470}\right)^2 = 9.5$ m/s$^2$

This acceleration has to match the centripetal acceleration of a circle with radius 6470 km, $a = v^2/r = g_{100}$, yielding a orbital speed of 7.84 km/s.

The circumference of a great circle at 100 km altitude is $2 \times \pi \times 6470$ km = 40,652 km, giving a total orbit time of 5180 s, or 1 hour, 26 minutes, and 19 seconds. So close enough to ninety minutes for a general.

So, yes, GoldenEye's orbit makes sense (-ish). Even though it's much lower than that of the ISS, which also has around 90 minute orbital period (92 minutes, and it's on a very mildly elliptical orbit).

On the other hand, a 100 km orbit would graze the atmosphere (it's inside the thermosphere layer, near the bottom) and therefore lose energy over time, so not a great orbit to place an orbital weapon masquerading as a piece of space debris, because you can't boost up "space debris."

Here are the circular orbital times for different altitudes; because of the approximation of $g=9.8$ m/s$^2$ and radius of the Earth as 6370 km, there are increasing errors with altitude, which are obvious for the GEO orbit (in yellow), still not bad since GEO shows that errors will be less than 2 minutes 38 seconds on all the other orbits:




There's no True(x) function for the internet (or anywhere else)



(Ignore the bad grammar, it was a long day.)

What happens if we feed the [putative social media lie-detector] function $\mathrm{TRUE}(x)$ the statement $x=$"the set of all sets that don't contain themselves contains itself"?

Let's take a short detour to the beginning of the last century...

Most sets one encounters in everyday math don't contain themselves: the set of real numbers $\mathbb{R}$ doesn't contain itself, neither does the set $\{$chocolate, Graham cracker, marshmallow$\}$, for example. So one could collect all these sets that don't contain themselves into a set $S$, the set of all sets that don't contain themselves. So far so good, until we ask whether $S$ contains itself.

Well, one would reason, let's say $S$ doesn't contain itself; then $S$ is a set that doesn't contain itself, which means it's one of the sets in $S$. Oops.

Maybe if we start from the other side: say $S$ contains itself; but in that case $S$ is a set that contains itself, and doesn't belong in $S$.

This is Russell's set paradox and it shows that there are propositions for which there is no possible truth value.



On the price of micro-SD cards


Browsing Amazon for Black Friday deals (I saved 100% on Black Friday with coupon code #DontBuyUnnecessaryStuff and you can too), I saw these micro-SD cards:


Instead of buying them, I decided to analyze their prices, first computing the average cost per GB (as seen above) and then realizing that there's a fixed component to the price apart from the cost per GB, which a simple linear model captures:




All the electricity California needs is about 6 kilos of antimatter


I was reading a report on how much it costs to decommission (properly) a wind farm and realized that if we just had some antimatter lying around (!), California energy needs would be met with small quantities.


Okay, antimatter is a bit dangerous, so how about we develop that cold fusion people keep talking about? Here:


(Divide that by an efficiency factor if you feel like it.)



Relativity misconceptions and the reason I restarted blogging


I was listening to a podcast with Hans G Schantz, author of the The Hidden Truth trilogy (so far… fans eagerly await the fourth installment; highly recommended) and he had to correct the podcast host on what I've noticed is a very common misconception: that "near" the speed of light relativistic effects are very large.

Which is true, for an appropriate understanding of "near."

Time dilation, space contraction, and mass increase are all regulated by a function $\gamma(v) = (1 -(v/c)^2)^{-1/2}$, a very non-linear function. For the type of effects that people typically think about, like tenfold increases, we're talking about speeds near $0.995 c$; for the type of effect that would be noticeable in  small objects or short durations, one needs to go significantly above that:


Interestingly, the decision to restart blogging (first under the new name "Fun with numbers," then back to the admonition to keep one's thoughts to oneself by Boetius) was due to a number of calculations I had been tweeting regarding relativistic effects in the Torchship trilogy by Karl K Gallagher (highly recommended as well). Here are some examples, from Twitter:



And it's always heartwarming to see an author who keeps the science fiction human: that in a universe with mass-to-energy converters, wormhole travel, rampaging artificial intelligences, and AI-made trans-Oganesson-118 elements, there's a place for the problem-solving power of a wrench:





Computerphile has a simple data analysis course on YouTube using R



Link to the playlist here.
Download RStudio here.



Another promising lab rig that I hope will become a product at scale



The Phys.org article is here and the actual Science Advances paper is here.

Strictly speaking, what the paper describes is a successful laboratory test rig, but let's be generous and consider it a successful tech demo, also known in the low-tech world as a proof-of-concept. Note that though not all successful lab test rigs become successful tech demos, the ratio is much higher than the number of lab rigs (successful and otherwise) that become tech demos, so it's not that big a leap in the technology development process.

Wednesday, July 3, 2019

From value to share (in math)



There are a few places online (and in some books) where a kind of magic happens. At some point we go from something like this
\[
v(x) = w_1 x_1 + \ldots + w_K x_K
\]
to, in a single magic jump,
\[
\Pr(\text{Buy } x) = \frac{\exp(v(x))}{1 + \exp(v(x))}.
\]
The $v(x) = w_1 x_1 + \ldots + w_K x_K$ is easy enough to understand: the value of some object $x$ is a weighted sum of the dimensions of $x$; there are $K$ dimensions $x_1, \ldots, x_K$ and associated weights, $w_1, \ldots, w_K$.

But then there's something along the lines of "using appropriate assumptions, the probability of a customer purchasing $x$ is given by" that fraction.

This magic jump appears in so many places discussing analytics, data science, big data, machine learning, artificial intelligence, and other fashionable ways to refer to statistics (because that's what's there) that we could be forgiven for suspecting that the people making the jump don't know where it comes from.

It's fine not to know where something comes from, as long as one is aware of that. But it's instructive to work through the simple cases, like this one. After all, a personal trainer needn't be a super-athlete, but should at least be able to exercise.

So, how do we go from the weighted sum to those exponentials (called the logit formula)?

First, that formula is only correct if, among other things: (a) the choice is between buying $x$ or nothing at all; and (b) the $v(\cdot)$ for buying nothing is set to be zero, denote that as $v(0) =0$. Okay, the (a) makes this a simple choice and (b) is just a threshold; to move it around we can always have a constant $x_0$ added to the $v(x)$.

Now, why isn't the probability either one or zero, then? After all, either $v(x) > 0 = v(0)$ and the customer should always buy or $v(x) < 0 = v(0)$ and the customer should never buy.

That's the second step: there are things that can change the $v(x)$ that we don't observe. Maybe the customer's mood changes and the $w_i$ change with it, for example. We don't know, so we say that the customer optimizes "utility" $u(x)$ instead of value $v(x)$, and the difference is a stochastic disturbance (expensive wording for random stuff) $\epsilon$:
\[
u(x) = v(x) - \epsilon.
\]
(Let's assume that $u(0) = v(0) = 0$. It's not necessary but makes things simpler.) This second step changes the nature of the problem: instead of a decision (buy or not), we can only predict a probability:
\[
\Pr(\text{Buy } x) = \Pr(u(x)>0) = \Pr(v(x)> \epsilon).
\]
Now we can compute that probability: it's just the cumulative distribution for the $\epsilon$ variable evaluated at the point $v(x)$, denoted $F_{\epsilon}(v(x))$.


Unfortunately, by their own nature the $\epsilon$ aren't known, so we need to assume a probability distribution for $\epsilon$, one that's acceptable and is computationally convenient.

We could try the Normal distribution, which most people accept without questioning, so it gets us the first desirable characteristic. Unfortunately the $\exp(-z^2/2)$ makes integrating it difficult. What we need is a distribution that looks more or less like a Normal but can be integrated into a manageable form.

Enter the logistic distribution.


It looks enough like a Normal (it has fat tails but it's hard to tell by looking). And its probability density function
\[
f_{\epsilon}(z) = \frac{\exp(- z)}{(1+\exp(-z))^2}
\]
integrates easily to
\[
F_{\epsilon}(v) = \int_{-\infty}^{v} f_{\epsilon}(z) \, dz = \frac{1}{1 + \exp(-v)} = \frac{\exp(v)}{1+\exp(v)},
\]
which, when replaced in the formula for probability of buy gives the logit formula:
\[
\Pr(\text{Buy } x) = \Pr(v(x)> \epsilon) = F_{\epsilon}(v(x)) = \frac{\exp(v(x))}{1+\exp(v(x))}.
\]
When you know the math, you understand the magic.