Sunday 30 December 2012

interesting use of the present tense

I was surfing an on-line TV channel guide, to find when a particular episode of Wizards v Aliens  that we had missed was being repeated.  I came across:
TV channel guide. See what you can watch today, yesterday and tomorrow.
"See what you can watch yesterday".  This really is living in the future (but watching the present)!

Saturday 29 December 2012

peek-a-boo Jupiter

This happened on Christmas Day, but I've only just come across it.

Rafael Defavari took a video of the moon occulting Jupiter.  It's marvellous, and made even more so by what you can see as Jupiter re-emerges from behind our moon:

Lunar occultation of Jupiter - 25 December 2012
The little dot just visible above-left of Jupiter is one of its moons: Europa.  And the darker dot on Jupiter itself is Europa's shadow!  (It's easier to see on the video.)

There's more info where I found out about this, at Phil Plait's Bad Astronomy site.


Friday 28 December 2012

ambiguous instructions

So, I'm preparing a large document.  There are instructions for the layout.  One reads:
All margins (top, bottom, left, right) should be at least 15 mm (not including any footers or headers).
Hmm. Does it mean that, when measuring the margins, do not include any headers and footers in that measurement (that is, measure from the edge to the main text), or, when measuring the margins, do not include any headers and footers in the margins (that is, measure from the edge to the top of header/bottom of footer)?

Instructions are always unambiguous when you write them, because you know what you mean, so don't even see the alternative interpretation.  They become ambiguous only when someone else reads them. Sigh.

Thursday 27 December 2012

ODE to a Petri net

Writing ordinary differential equations (ODEs) to model various natural world processes comes more readily to some than to others.  And once written, it can take some effort to pick apart their real-world meaning.  It would be nice to have a more visual form.  Petri nets are one such approach.

Epidemics


For example, consider the simple SIR model of epidemic infection.
  • +++S+++ : those uninfected, but susceptible -- their number is reduced as they become infected, at a rate proportional to the number of susceptibles and the number of infected
  • +++I+++ : those infected -- their number is increased by susceptibles who become infected;  it is also reduced as those infected recover, at a rate proportional to the number of infected
  • +++R+++ : those recovered -- their number is increased by those who were infected recovering
For those happy with ODEs, it is straightforward to write down a set of coupled equations to model this:
$$\dot{S} = - i S I $$
$$\dot{I} = i S I - r I$$
$$\dot{R} = r I$$
In addition to natural language (the bullet list) and maths (the ODEs), there is another language useful to explain and understand models: diagrams.

For example, we could draw a simple state transition diagram to show the movement from susceptible to infected to recovered:

This captures some of the information, but not all of it.  A (continuous) Petri net can do better:


The circles are called "places", and represent the "things" involved: here the susceptibles, the infected, and the recovered.  The rectangles (the colours aren't significant) are called "transitions", and represent how the things in "input" places get transformed into things in "output" places.
  • transition +++r+++: an infected comes in, and a recovered comes out
  • transition +++i+++: a susceptible and an infected come in; two infected come out (the two infected outputs are the newly infected, and the original infecter)
This diagram has enough information in it to reproduce the original ODEs.  We have one ODE per place, with the terms being given by the transitions feeding that place.
  • place +++R+++. +++R+++ has only one transition feeding it: transition +++r+++.  It is feeding into +++R+++ at a rate proportional to all the inputs to +++r+++: here just +++I+++.  Hence +++\dot{R} \propto I+++.  If we call the constant of proportionality (the rate constant) +++r+++, we get +++\dot{R} = r I+++
  • place +++S+++. +++S+++ has only one transition, +++i+++, removing stuff from +++S+++.  It is removing at a rate proportional to all the inputs to +++i+++: here +++S+++ and +++I+++.  Calling the rate constant +++i+++, we get  +++\dot{S} = - i S I+++ (the minus sign is there because we a removing from +++S+++, and it is conventional to keep the rate constants positive)
  • place +++I+++.  +++I+++ has two transitions: +++i+++ both feeding it (two input arrows) and removing from it (one output arrow), and +++r+++ removing from it.  We get +++\dot{I} = i S I - r I+++
Thus we have recovered the original equations.

We can write this focussing on the transitions, in a more algorithmic way (algorithms, or pseudo-code, are yet a further language we can use to explain, describe, and define processes).
  • initialise the rates of change to each place to be +++0+++.  +++\dot{S}, \dot{I}, \dot{R} := 0+++
  • transition +++r+++.  This is removing stuff from place +++I+++ and adding it to +++R+++ at a rate +++rI+++. Update the output place +++R+++ and input place +++I+++ appropriately: +++\dot{I} {-}{=}\ rI+++, +++\dot{R} {+}{=}\ rI+++
  • transition +++i+++.  This is removing stuff from place +++I+++ and from place +++S+++ at a rate +++iSI+++ and adding it to +++I+++ at a rate +++2iSI+++ (from the two input arrows).  Hence there is a net input to place +++I+++ at a rate +++iSI+++.  Update the output place +++S+++ and net input place +++I+++ appropriately: +++\dot{I} {+}{=}\ iSI+++, +++\dot{S} {-}{=}\ iSI+++
We can write this as a general algorithm:
  for each place Pi
    Pi_dot := 0
  for each transition Ti
    let Pin = < Pin_1, ... , Pin_n > = list of n places,
                                       one for each input arrow of Ti;
        Pout = list of m places, one for each output arrow of Ti;
        t = Ti x Pin_1 x ... x Pin_n
    for each Pi in Pin
      Pi_dot -= t
    for each Pi in Pout
      Pi_dot += t
So now we have a diagrammatic form, and an ODE form, that are equivalent, and an algorithm to translate on to the other.  This is useful, because we can use them interchangeably, without risk of losing information.  In particular, notice how explanation accompanying the Petri net focusses on what is happening in the transitions, whilst that for the ODE form focusses on what is happening to the places.  Having different forms of explanation can be useful in different circumstances (modelling, communication, modification, validation, calculation, etc).

Catalysis


Although that all works well, the handling of the infecter in the +++i+++ transition seems a bit unnatural: infecter goes in, infecter comes out, resulting in an addition and subtraction of this rate.  The infecter is needed for the transition, and affects the rate of the transition, but is not itself changed by the transition.  In chemistry, this is called a catalyst, and there is some special Petri net syntax for it.  We can draw the SIR Petri net above equivalently as:


Here the dashed arrow means that +++I+++ is a catalyst: it is needed for the transition, but is not consumed by the transition. Hence there is now only one arrow out to +++I+++: since the catalyst wasn't consumed, it doesn't need to be replaced; the remaining single arrow represents the newly infected.

The algorithm needs a little  modification:
  for each place Pi
    Pi_dot := 0
  for each transition Ti
    let Pin = < Pin_1, ... , Pin_n > = list of n places, 
                                       one for each input arrow of Ti;
        Pcat (sublist of Pin) = list of catalytic input arrow of Ti;
        Pout = list of m places, one for each output arrow of Ti
    let t = Ti x Pin_1 x ... x Pin_n
    for each Pi in Pin \ Pcat
      Pi_dot -= t
    for each Pi in Pout
      Pi_dot += t
So the catalytic arrows still contribute to the functional form of the overall rate +++t+++, but not to the changes to the specific places.

Logistic equation


Possibly the simplest bounded growth model in biology is the logistic equation:
$$ \dot{N} = rN(1-N/K)$$where +++r+++ is the growth rate, and +++K+++ is the carrying capacity (so when +++K=N+++, +++\dot{N}=0+++).

This can be drawn as an equivalent Petri net:


  • transition +++r+++ (birth): one in, two out
  • transition +++rK+++ (competition): two in, one out
These two transitions can also be shown in a simpler catalytic form (if maybe not with the same intuition as before):

  • transition +++r+++ (birth): one "catalyses" the birth of the other
  • transition +++rK+++ (competition): one "catalyses" the death of the other

Lotka-Volterra predator-prey


The simple predator-prey model, usually cast as rabbits and foxes, has rabbits being born, predated on by foxes to produce more foxes, who then die.  A simplistic version of this might be:


  • transition +++b+++ (birth): one rabbit in, two rabbits out
  • transition +++d+++ (death): one fox dies
  • transition +++p+++ (predation): one fox and one rabbit in, two foxes out
This however has a problem: it has a new fox produced every time a rabbit is eaten.  Real foxes need more food than this to reproduce.  We can't solve the problem by changing the rate +++p+++, as this affects the consumption of rabbits and production of foxes equally.  What we really need is for the consumption of a rabbit to produce a bit of a fox.  We can do this by adding a separate rate to the arrow:


  • transition +++p+++ (predation): one fox and one rabbit in, one plus +++\epsilon+++ foxes out
The algorithm needs to be updated to multiply the rate by the weight of the arrow before adding/subtracting  as appropriate.  This then yields the familiar equations:

$$\dot{R} = R(b-pF)$$
$$\dot{F} = F(-d+p\epsilon R)$$

If we use the catalytic form, the diagram simplifies to:


  • transition +++p+++ (predation): one fox "catalyses" the transformation of a rabbit into +++\epsilon+++ of a new fox

Lotka-Volterra competition


The simple competition model, usually cast as rabbits and sheep, has rabbits and sheep being born and dying following their own logistic equation, and also competing with each other for resources.


  • transition +++rb,rs+++ (birth): one +++x+++ "catalyses" the birth of the next +++x+++
  • transition +++rc,sc+++ (competition): one +++x+++ "catalyses" the death of another +++x+++
  • transition +++rs+++ (rabbit/sheep competition): one sheep and one rabbit in, a proportion of each out
$$\dot{R} = R(rb-rcS) + (pr-1)rs RS$$
$$\dot{S} = S(sb-scS) + (ps-1)rs RS$$

Combining predator-prey and competition


The competition example has two logistic "subnets", showing how these diagrammatic forms can be readily combined.  So, for example, we could easily add some foxes to the brew:


$$\dot{S} = S(sb-scS) + (ps-1)rs RS$$
$$\dot{R} = R(rb-rcS) + (pr-1)rs RS -pRF$$
$$\dot{F} = F(-d+p\epsilon R)$$

If the foxes also worried the sheep, the diagram would get messier, but would still visually represent the relationships between the different components.

Diagrams v cartoons


Pictures can be very helpful at getting across ideas, but they have their problems if they are ambiguous, incomplete, or otherwise open to misinterpretation.

The (continuous) Petri nets shown here have a formal meaning: they can be translated into equivalent ODEs. They are not informal "cartoons", merely sketching some part of the meaning.  There is an algorithm from diagrams to equations, and it is possible to build a tools allowing the manipulation of diagrams and equations as two different "concrete syntaxes" of the same underlying model.  Which syntax to use depends on what you are doing: it truly is the best of both worlds.

Acknowledgments

  • I first came across the formal link between continuous Petri nets and ODEs on Alexi Sharov's web site
  • I was reminded of using Petri nets to model population dynamics on reading David Tanzer's guest post on the Azimuth site
  • I drew the diagrams in graphviz
  • The maths is formatted with LaTeX and displayed using MathJax

Wednesday 26 December 2012

four

The flight continues, and we currently are down to only four ducks in our pond.

Monday 24 December 2012

seven

Only seven ducks returned this evening.

They spent some time splashing around, zooming up and down our pond, practising flying (above and below water).

flying underwater
They are still very much behaving as a flock, all splashing, swimming, or preening together.

a more contemplative moment
And we're now convinced the missing members have merely flown off on their own.  The zooming across the pond resulted in some definite flight-like moments, and one of the ducks actually did fly, albeit awkwardly, up out of the pond.

getting ready for bed

Sunday 23 December 2012

and then there were nine...

Last week I discovered why the ducks may have survived so long. As I was coming home one day I saw a neighbour sitting on his front doorstep, surrounded by ducks, feeding them.

Despite that, this evening there were only nine ducks in the pond (it was too dark to photograph them, but we counted carefully).

Maybe two have learned to fly, and gone elsewhere?  Maybe a cat, or a car?  Maybe an early Christmas lunch being prepared?  Who knows?

Friday 21 December 2012

still here

Guardian item on Mayan apocalypse
I see the world didn't end after all, only the Mayan calendar did.

I suppose that means I still have to do my Christmas shopping, and mark all those exam scripts....

Ah, well.

So, of course, the next end of the world is Monday 31 December 2012, when the Western calendar ends.

What do you mean, that calendar starts again on Tuesday 1 January 2013?


Tuesday 18 December 2012

"there's a legal issue with your ice cream"

Yesterday, while doing a routine grocery shop, I decided to be a bit organised, and buy some Christmas food in advance of the usual last minute mad dash.

Ice cream.  Yum.  Let's see what they've got.  Oooh, these look like a nice treat:
  • Belgian Chocolate Salted Caramel and Hazelnut Ice Cream
  • Belgian Chocolate Orange Blossom Honey and Almond
Not only did they look good, but they were on special offer, encouraging me to get two.  After all, Belgian chocolate.

So, we get to the checkout.  The Belgian Chocolate Salted Caramel and Hazelnut Ice Cream gets scanned, and then the assistant says "I'm sorry, there's a legal issue with your ice cream".  What?  She continues, "it's been recalled".  She put it to one side, then scanned the Belgian Chocolate Orange Blossom Honey and Almond.  "Sorry, that's also been recalled".  Oh.

Well, that's saved me a few pounds -- they are still in my purse, rather than going on my waistline!
A quick Google, and I discover that:
Tesco is taking the precautionary measure of recalling the above code of Tesco Finest Belgian Chocolate Salted Caramel & Hazelnut Ice Cream due a small number of tubs being incorrectly filled with the Orange Blossom Honey & Almond variant (the nut allergy warning is therefore incorrect).   
For identification, the incorrectly filled tubs have the Orange Blossom Honey and Almond lid/top.
Okay.  Several things of interest here:
  1. Why were the items not removed from the shelves?
  2. If the items can be identified from the incorrect tub/correct top combination, why weren't these removed and the others allowed through?
  3. Why was the Orange Blossom Honey and Almond tub also removed, since it had the correct almond warning?
  4. I didn't know nut allergies are specific to the kind of nut -- that someone allergic to almonds could nevertheless eat hazelnuts.  (Well, technically, I still don't actually know if that's the case.)
So tonight, I tried to buy the ice cream again, assuming they would have cleared the shelves and replaced with new goods.  I checked: the tub had a matching hazelnut lid, so was not part of the bad batch.  But the same thing happened at the checkout.  No Belgian Chocolate ice cream for me this Christmas.

Monday 17 December 2012

cue spooky music

I've written about coincidences before, and I said: "things like this happen all the time".  Just to demonstrate this a bit further, here's another one (or maybe two, or even three).

This summer we holidayed in Northumbria, and had a day on Lindisfarne.  A colleague from Scotland commented that he'd been there at exactly the same time. The final photo in the post had a couple of birds in the background; I asked a bird-savvy friend to help identify them.  When they replied, the mentioned they had been on a cycling holiday in Northumbria, and close to Lindisfarne at this time!

Last week at work we had a Christmas quiz.  One of the questions was "what element is named after a Scottish village?"  I'd never heard of this one (if they'd said Sweden instead of Scotland, I could have done better), but one of our team-mates said "Strontium".

I'd forgotten about the Lindisfarne coincidence until I received the bird friend's Christmas letter, where they mentioned their Northumbria cycling holiday. They also mentioned an earlier holiday in Scotland, where they had spent a week "in a village called Strontian".

Cue spooky music.

Saturday 15 December 2012

11 ducks a-swimming

Although the ducks look full-grown, they can't yet fly.  They are practising, by zooming back-and-forth across our pond, wings flapping wildly, but not quite effectively.

a tranquil moment
They roost beside our pond each night.  The "dawn chorus" of loud quacking, right under our bedroom window, is not so much fun...

Friday 14 December 2012

oh, I do so hope not

40 years ago today, 14 December 1972, Eugene Cernan was the last man to walk on the Moon.


Sunday 9 December 2012

Sir Patrick Moore, 1923 - 2012

Sir Patrick Moore, astronomer, presenter of The Sky At Night since 1957, author of many popular astronomy books, inspiration to several generations of astronomers, myself included, has died. Still sitting on our TV's hard disc recorder is last Monday's episode of The Sky At Night, not yet watched.  Goodbye, Patrick.

Patrick Moore

The Sky At Night, "A Night to Remember".
 The BBC's 1969 moon landing team: Patrick Moore, Cliff Michelmore, James Burke
(but why is this picture reversed?)

Patrick Moore (photo credit: Paul Grover, from Telegraph article in 2010)


Saturday 8 December 2012

put the cat among the ducklings

The eleven ducks returned to our pond this evening.

The neighbours' cat was fascinated.

"How do I get dinner without getting my paws wet?"

But once it realised it was out of luck, it pretended indifference in a very cat-like way.

"I'm just sitting here."

The ducks, meanwhile, enjoyed their splashing about, practising for when they can fly.

wheeee!

Then they settled down to preen, and then roost for the evening.  Here you can clearly see there are still eleven.  (Mother has now forsaken them completely, it seems.)

time for bed

Sunday 2 December 2012

Evernote as a laboratory daybook

I started using Evernote three weeks ago.  I've been trialling it as my "daybook" at work, where I keep my notes of all meetings, projects, and any work-related items.  It's been very successful, so now I've switched over to it in entirety, and retired my hardbound logbooks.

One of my Evernote "notebooks" is my daybook.  For each day I keep a single note that's the "miscellaneous" stuff, plus a separate note for each scheduled event (lecture, practical, seminar, student supervision, project meeting, committee meeting, whatever).  I put a little thumbnail picture -- of the person, or something iconic for the meeting, in the note, which then shows up in the snippets window.  I've also made a set of "day" icons for the single "miscellaneous" note, that show the day, date, year, and week of term/vacation.  These thumbnails allow me to scan the snippets and usually find the correct note rapidly, without needing a search.

the end of last week
At the beginning of each day I add new notes for the meetings from my diary, and edit the "create time" to be the start time of the meeting.

I use templates for each of my semi-regular meetings.  When it's the day of the meeting, I copy the note from the template notebook, where it already has the right date and time.  When I know the time of the next occurrence (known in advance for regular meetings, sometimes agreed in the meeting, sometimes not agreed until after the meeting), I edit the template accordingly.  This means my template notebook also acts as a mini calendar of future appointments.  I found this useful within the first couple of weeks. I had forgotten to set the time of my next meeting with a student; still with the date of our previous meeting, their template was noticeably languishing at the bottom of the list, reminding me to do something about it.

At the beginning of a meeting, I select the relevant note, and can start typing straight away.  Also, I can "search" for the name of the meeting, and then the snippet window shows just these.  So I can quickly go back to an earlier meeting (eg, to look up what we agreed to do for this meeting).

Each meeting note has three sections:

  • pre-meeting notes: preparation for to the meeting (for a committee meeting this might be reports on any actions I've discharged; for a seminar it will be the speaker's abstract, etc; I also add links to relevant documents)
  • meeting notes: I have a 7" Netbook with a useable keyboard -- I've found I can type notes fast enough if it's on a table, or perched on my lap (although this is a bit uncomfortable on some chairs)
  • post-meeting notes: for example, any clarifications or further information I've looked up after a talk -- I find it useful to clip a few sentences from a relevant website to help illuminate some point a speaker has made

Rather than keep big pdfs in Evernote, I keep them in my Dropbox, and just put a link in the note.  Also, I can link to specific gmail conversations, for example, the one containing the agenda and minutes of the meeting.  This is a great aid to going paperless.

I use Evernote on my netbook for taking meeting notes, and on my main machine for making notes while I'm working at my desk.  A couple of times I've closed the netbook, sat at my desk, and started updating the meeting note, only to discover I haven't given it time to synchronise.  I now manually synchronise before I close the netbook.  However, I haven't lost anything, since Evernote keeps both versions, and puts them in a "conflicting changes" notebook.

One issue I have is with the automatic choice of image to use as the thumbnail in the snippet view. It automatically chooses "the image with the largest smallest dimension" (btw, it took me essentially no time at all to find that link, as I'd clipped it into Evernote when I was looking for it originally).  That's almost always the wrong choice for me: I want a thumbnail icon, such as a small photo of the person involved, which nearly always has the smallest largest dimension.  Since I often take whiteboard photos to accompany technical meeting notes, I can end up with a bunch of identical-looking whiteboard thumbnails!  I would much prefer being able to override the default.

But apart from that v minor niggle (and the printing issue noted below), I'm finding this almost perfect as a daybook.

Caveat: if you need to keep a formal logbook, with date stamps and signatures, you will need to find a way to print out your notes -- which is easy for a single note, but non-trivial as a batch exercise.

Saturday 1 December 2012

all the ducks on a row

Well, not all of them: here's just four of the nearly fully grown ducks, preening on our patio after an energetic swim.


Don't worry that there are only four shown; all eleven are still going strong:


This was the view after a lot of energetic swimming, splashing, and diving.  First, however, they needed a bit of an ice-breaker, as the pond was still frozen in places.

Mother arrived afterwards, paying a flying visit.