Posts

Principal Component Analysis - A Geometric Approach

Image
Overview Principal Component Analysis is a neat statistical trick, with a simple bit of linear algebra backing it up.  Imagine you've got a dependent, or response variable, $Y$ and a large number of independent, a.k.a. explanatory, variables $X_1, ... X_p$.  You also have $n$ measurements of each, giving you a matrix $$ \begin{align} X = & \begin{pmatrix} x_{11} & x_{12} & ... & x_{1n}\\ \vdots & & & \\ x_{p1} & x_{p2} & ... & x_{pn}\\ \end{pmatrix} \\ = & \begin{pmatrix} -\mathbb{x_1}- \\ \vdots \\ -\mathbb{x_p}- \\ \end{pmatrix} \\ \end{align} $$ You want to build a model explaining how $Y$ depends on the $X_i$, perhaps a linear model like $$ Y = \beta_0 + \sum_{i=1}^p \beta_i X_i $$ but first you need to check that the $X_i$ are more or less independent of each other, otherwise there's no way of uniquely setting the $\beta_i$ values and the stats package is likely to produce an unreliable output.  In general the $X_i$ are not inde

Ubuntu hack

Image
Getting the faffing auto-suspend feature working properly I use Ubuntu on all my computers and it always works 99% well.  But there's always one minor issue that I could live with, were it not for my pathological perfectionism.  On this one it's the auto-suspend, which just wasn't working at all.  This computer lives in the living room and I don't like any noise pollution there, or the idea of pointlessly consuming power.  I think the ethernet card was continuously keeping the machine awake, even if auto suspend was enabled in System Settings -> Power Management .  Eventually I found a solution Add a startup program via Preferences -> Startup Applications Disable auto suspend Log out and back in again (or reboot) For the disabling of auto-suspend I actually just removed the power manager altogether with sudo apt remove mate-power-manager .  If you're using gnome instead it's probably sudo apt remove gnome-power-manager .  The one-line startup program was

Taking Liberties

Image
This Go problem was presented to me by my Tsumego Pro mobile app this morning.  It's not particularly difficult, but I think it nicely demonstrates some ideas about liberties. It's Black's turn to go, and it's pretty obvious that a race is on, and the winner is going to take some stones.  If Black wins it'll take the 3 white stones in a row, and if White wins it'll take the six connected black stones just below. A connected group of stones is taken prisoner when the other player removes it's last "liberty", i.e. the last place into which that connected group can grow.  At the moment White has 4 liberties and Black has 3.  So it would seem Black is on to a loser, since the players can just take turns removing one liberty at a time from each other's stones.  However, it's not quite as simple as that. Black's move can leave White's liberties unchanged or reduce them by one. It can also leave it's own liberties unchanged or reduce t

Integral Identities

Image

Hutchinson's Theorem (1981)

Image
See below for code This was the most up to date thing we proved in my maths degree.  It's a lovely little theorem in the field of Fractal Geometry that enables you to create images like the ones above.  But first some primers.... A fixed point of any map $f:X\to X$ is a point $x\in X$ such that $f(x) = x$.  If $X=\mathbb{R}^N$ we can define a contraction as a map $f$ which brings pairs of points closer together, i.e. we can say $f$ is a contraction if there's some $\lambda < 1$ such that for any $x_1,x_2$ we have  $|f(x_1)-f(x_2)| < \lambda |x_1-x_2|$.  Now, it's easy to see that if $f$ is a contraction then it has a unique fixed point.  All you have to do is note that for any $x$ the following sequence converges $$ x, f(x), f^2(x), f^3(x), ... $$ Why's that?  Well if we let $\epsilon = |x-f(x)|$ then $\epsilon\lambda^{n-1}$ is an upper bound for the distance between the $n^{th}$ and $n+1^{th}$ members of the sequence.  Since $\sum \epsilon\lambda^n$ converges

Simple model that gets you in spitting distance of a reasonable estimate of Equilibrium Climate Sensitivity

Image
Background ECS - Equilibrium Climate Sensitivity - is the temperature change on Earth as a result of a doubling of atmospheric CO2.  That means going from 280 ppm (the level prior to the industrial revolution) past 420 (where we are now) and on to 560 ppm.  Most people probably understand why this would increase temperatures by now, but I'm going to repeat the argument briefly anyway, for completeness

Why is it so difficult to untangle a knot?

Image
Short answer: If there were a simple formula to follow there would also be one for proving or disproving any mathematical statement. Before setting out a sketch of a proof I need to be more clear about the problem.  I want to rule out the trivial method of untangling where you simply thread one end backwards through the tangle till it meets the other end.  So we're going to imagine it's a loop of string that's knotted, and "untangling" means getting back to a simple loop, without magically passing one bit through another. For most closed loops it's not possible to untangle to a loop.  For example if you look at the Trefoil Knot above (a.k.a. Granny Knot) it's obvious that no amount of fiddling with it is going to get rid of the knotty bit and leave just a loop.  But if your loop $L$ can be deformed into a simple loop then it follows that the complement in 3D space $\mathbb{R}^3 - L$ can be deformed continuously into the complement of the simple loop $\

Spinning Tops - by Professor J Perry FRS

Image
  I picked up this fantastic little book in Cambridge market a few days ago.  Published in 1908 by the Society for the Promotion of Christian Knowledge , it summarizes a lecture performed by Professor J Perry in 1890 in Leeds. The theme of the Romance of Science series is that remarkable and unexpected things can be discovered from the study of the apparently mundane.  In this lecture Professor Perry performs a series of experiments on various designs of spinning top and shows i.) What causes the precessional motion of a spinning top ii.) That a subterranean race could determine that we live on a spinning planet without ever seeing the stars iii.) Why the precessional motion of a top is in the same orientation as the spin, but the precessional motion of the Earth is in the opposite orientation iv.) Why some spinning tops stand up when you spin them on their side and even v.) A model of how a magnetic field might cause the observed rotation of plane polarized light The qualitative exp

1 gallon of fuel

Image
  Sometimes it helps to express things in human scales

64

Image
  I'm getting arty now. Following my previous post on greyscale, I wondered whether the numbers 0..63 can be made to look pretty too.  So I ran this in a terminal and then rotated and stretched the result in an image manipulation program. for i in range(64): s = f "{i:06b}" print(s.replace( '0' , ' ' ).replace( '1' , '\u2588' )) Mesmerizing!

Lord Greyscale

Image
  Posting a pretty picture of some greyscale in which the fractal nature of it is clearly visible.  Black rectangles represent zeros and white rectangles represent ones. Read it as an array of columns going from left to right.  In each column exactly one bit changes relative to the previous, making it an ideal scheme for a head to determine its position. An $n$-bit greyscale sequence has $2^n$ members, and the last member always differs from the first in just 1 bit position.  This makes greyscale ideal for determining position around a cylinder. Here's the code: #!/usr/bin/env python3 def __greyscale_fwd(nbits, preset_bits): if nbits == 1: yield 0 + preset_bits yield 1 + preset_bits else : for x in __greyscale_fwd(nbits-1, preset_bits): yield x for x in __greyscale_rev(nbits-1, preset_bits | (1 << (nbits-1))): yield x def __greyscale_rev(nbits, preset_bits): if nbits == 1: yield 1 + preset_bits yi

Lightweight building material seen in Devs

Image
Quantum physics slash Silicon Valley drama Devs features an interesting architectural idea, namely a floating laboratory.  In order make a laboratory float you need very lightweight construction materials and it seems that they've solved this problem by using Menger Sponge bricks, which are very lightweight indeed. A Menger Sponge is a 3D version of this To make a Menger Sponge you need to perform an iteration.  Start with any shape, then make 8 copies each scaled down by a factor of 3, and use them to construct the perimeter of a square.  Then take that shape and do the same operation, and keep repeating.  The picture above shows that you end up with the same thing whether you start with a solid square or a hollow square.  But actually it doesn't matter what shape you start off with (as long as it's bounded). So, what's the area $A$ of the 2D version Menger Sponge shown above?  We can see from the first row in the picture that it's made up of 8 copies of itself,

Fossil Fuel Free Pensions

Image
Fossil Fuels are dragging your pension down!   At the end of last year I finally managed to switch to a fossil fuel free pension.  The journey wasn't completely straightforward, but it was worth it and hopefully this will become a lot easier in the near future. Why do this? There's a bunch of things you can do to reduce your carbon footprint including giving up flying and eating less meat, and I recommend all of them.  But right at the top has to be to stop investing in fossil fuel companies.  A typical pension pot in the UK is around £88,000 of which - typically - 4% is invested in oil, gas, and coal.  That's three and half grand of your money going directly to the likes of ExxonMobil.  If you simply spent this much on tax free petrol it would buy you about 8.8 tons of fuel which would create about 29 tons of CO2, or about 5x the annual emissions of an average Brit.  But investing probably results in an order of magnitude more emissions $^\dagger$ . But it's worse t

How much of the UK's arable land will be needed to make it's biofuel?

Image
According to this story on today's BBC news website the UK government is set to mandate the proportion of ethanol in standard petrol is increased from 5% to 10%.  The 5% grade is known as E5 and the new grade will be known as E10. So, how much of the UK's arable land would be needed to make this, if it were made here? The article says " Ethanol is a kind of alcohol manufactured from plants, including sugar beet and wheat ".  Since sugar beet can be grown successfully in the UK, and it has a higher ethanol yield than wheat per square metre, I'm going to assume that we make the ethanol entirely from sugar beet.  So let's see if we can work out what proportion of the UK's 60,000 sq km arable land would be needed to power 10% of it's vehicle miles: In [ 1 ]: beet_ton_per_sq_km_per_year = 1320 In [ 2 ]: litre_biofuel_per_ton_beet = 108 In [ 3 ]: litre_biofuel_per_sq_km_per_year = beet_ton_per_sq_km_per_year*litre_biofuel_per_ton_beet In [ 4 ]: gallon_b

Mass Extinction and ... Flying Cars!

Image
What's Strange about this clip?   (fair use)   This programme about the future appeared on my TV last night, and it touched on an issue close to my heart: the future viability of life on Earth.     The first 3 minutes 45 seconds delivers some of the stark evidence for what we are doing and projections for where we are heading.  There's no emotion on display, but that's fine - we can't be emotional all the time and there's room for dispassionate analysis as well as appeals to the heart.  But then something strange happens at 3:48 - the presenter Hannah Fry introduces the next subject with an incredibly chirpy "Flying Cars! There - I've said it". Watching this one is left thinking:   Either I'm mad or everyone else is.  We've just been told that the average population decline across all species between 1970 and 2020 will be 67%.   And after dedicating three and bit minutes to that we're now talking about flying cars!  I'm worried we won

Why are we talking about hydrogen boilers?

Image
  Hydrogen is an incredibly inefficient way to heat your home compared with heat pumps.  Heat pumps move about 4 times as much energy in the form of heat as the electrical energy they consume.  With hydrogen boilers the heat is created from chemical energy rather than moved and so there's no such upscaling.  In fact it's worse than that since the hydrogen has to be created in the first place and if you're creating it from renewable electricity about a third is wasted. Despite the horrendous waste, hydrogen boilers may have a role.  Heat pumps require an insulated hot water tank and many houses, especially in the UK, will not have space for an airing cupboard.  So perhaps the solution will be to install heat pumps where-ever possible and then use the much-less efficient hydrogen boilers to mop up the rest.  The risk, however, is that the government's enthusiasm for Hydrogen will slow down the decarbonisation of our heating sector. We are in a deadly race, with only a fe

Comparison of Covid deaths India vs UK

Image
  The news here in the UK over the last couple of months has focussed on the unfolding catastrophe of Covid19 in India.  It has been implicit in pretty much all of the coverage that the situation there is much much worse than we have suffered in the UK, and this has been backed up by numbers showing just how many more people have died in India than here. True to form, our media have almost universally failed to take into account the fact that the population of India is nearly 25 times bigger.  I think dividing one number by another is not part of the training.... Here's a chart that puts things in context.  I've used 66.65 million for the UK population and 1.366 billion for India: INDIA OFFICIAL:   These are the Indian government official statistics republished by JHU CSSE COVID-19 Data showing 311,000 deaths INDIA ESTIMATE: These are from David Spiegalhalter and are based on excess mortality.  The best estimate is 1.6 million but could be as low as 600,000 or as high as 4 mi

Spinning Top

Image
Simple example from The Theoretical Minimum I recently re-read The Theoretical Minimum - Classical mechanics , an excellent book. The authors give an example of the use of the Hamiltonian formulation of mechanics to illustrate how much easier it makes things (compared to the Newtonian formulation) and that inspired me to have a go myself. The example they give in the book is of a negligible mass charged sphere spinning in a magnetic field pointing in the z direction. In this case the Hamiltonian $H = T + V$ is proportional to $L_z$ where $\mathbf{L}$ is the angular momentum $L_x \hat{i} + L_y \hat{j} + L_z \hat{k}$. Let's say $H=\omega^2L_z$. The book explains that for any function $G(q,p)$ of the generalized coordinates $q_i$ and the conjugate momenta $p_i$ that $$ \dot{G} = \{G,H\} $$ i.e the time derivative of $G$ is the poisson bracket of $G$ and the Hamiltonian. And indeed this does make the solution simple because the components of angular momentum satisfy $$ \begin{align}

Cathy Comb Home

Image
 I've just found this design I must have drawn when I was 16 I had a girlfriend at the time called Catherine with very long hair.  In fact it was so long she could sit on it.  Anyway, I was amazed at how much time she spent combing - about half an hour every day.  She'd start at the bottom and work her way up, combing all the way to the ends with each stroke. I thought that there had to be a better way, so I came up with this machine.  The two belts rotate in opposite directions and the angle between them gradually decreases so that it starts off just untangling the ends and ends up combing the whole length of the hair. Fortunately it never got built.