Friday, 17 December 2010

html5 test (won't work in IE)

Hello World!

This is a quick test page to see if I can persuade HTML5 to work with blogger. If it does then it might save me running up a server.
Click to test

Your browser doesn't support canvas.

Smiley code borrowed from Ryan Carson

Thursday, 9 December 2010

Making Yoghurt

How easy is this! 

Recipe :
1 pt milk (I use semi-skimmed)
1 tbsp milk powder
1 tbsp yoghurt (Natural yoghurt either saved from the last batch or bought new. Must be 'live')

Put milk into a pan, stir in milk powder, bring to boil. Once it has come to the boil let the milk cool down to body temperature (it should feel slightly warm) and stir in the yoghurt. Leave in a warm place overnight and it should be set in the morning.

I have been using the piece of culinary archaeology above, you can put warm water in the base to help things along, but you can just use a jug or get a fancy yoghurt maker. Since it's been really cold I have been thinking of using a plant propagator, as even our airing cupboard doesn't get warm enough.

Tuesday, 7 December 2010

Experiments With A Simple Evolutionary Algorithm (1)

In Richard Dawkin's 'The Blind Watchmaker'he describes a program that he built to mutate a random string into a given target string ('Methinks it is like a Weasel'), so I thought I'd try and build one myself. In version one I have three core functions fit(), breed() and make_child().  In each generation one breeds by making a number of children, the fittest of which is returned to be the parent of the next generation. Here are the guts of the functions :

fit(string1, string2)
compare the strings and return the difference between them as a number. 0 is a perfect fit. In version 1 the difference is the alphabetic distance between each individual character in each string :
        for i in range(len(t)):
                f = f + abs(t[i] - s[i])

randomly changes some of the characters in the parent string and returns the new string as the child :
.         for i in range(len(parent)):
                if(random.random() > 0.9):
                        child.append(random.choice('abcdefghijklmnopqrstuvwxyz '))
                else :

create a number of children, compare them with each other and the parent for fitness and return the best to be used as the parent for the next generation. You don't need code for this -it's trivial.

How does it do?
It works! See update.

Questions and Improvements
  •  How good is the measure of fitness?
  • How good is make_child?
  • Is there an ideal combination of generations, offspring and 'variation'
  • Is only having 1 parent OK?
Based on nothing at all, I think that make_child has the most fundamental problem, I think that it should be tweaked to take into account current fitness of the parent. As the fit gets better then the changes should get smaller, as any organism that changed a lot between generations is quite likely to 'evolve' right out of its niche.


Well, I was right, make child did have a fundamental problem. I thougth I was calling a random() function but instead seemed to be instantiating (or perhaps defining) some sort of random object -at least the Python interpreter wasn't complaining, this meant that all the strings were randomized every time and there was no generational inheritance. Fixed this and it worked.  

Python : Very First Impressions

Currently I'm reading Richard Dawkin's 'The Blind Watchmaker' and I'm going to have a go at writing programs -at least for the first problem of evolving one string to match another. I have decided to use Python, partly because, of the main scripting languages, I have already tried PHP, Perl and Ruby -hell people have actually paid me to write code in all of  them! Partly because it seems to be having a bit of a renaissance at the moment (and, who knows, someone might pay me to code in Python).

After one morning, I'm feeling OK. Fortunately I'm old enough to have used ten or fifteen different languages from the original BASIC (seventeen reserved words, all variables are one letter and maybe one number) , via Occam to Prolog.

So far the main differences from PHP are ones of syntactic suger :
  • Indenting rather than bracketing for loops and funtion definitions.
  • You don't need ';' at the end of a statement.
  • 'def' rather than 'function' to define a function.
  • richer and stricter typing -I'm not sure how I'll get on with this.
I have lots more to look at -I haven't got near the object model yet- so I'll post more later, either on this post or on a new one.

Monday, 6 December 2010

Khan Academy -learning for all.

What a great idea! The Khan Academy is a teaching site based around videos hosted on youtube and interactive exercises. There are 1800 plus videos, mainly secondary school maths and science at the moment, but Sal Khan hopes to push it out to other areas with time. The exercises are pretty much all maths -except for some on projectile motion.

I have been cracking through the maths exercises trying to find my level -probably around the third year -or year ten in new money. With the school shut for snow I put my 11 year old in front of the site, and she didn't run away screaming. I think that's partly due to the points system, competititive little begger wants a high score.

The maths videos range from simple addition up to moderate calculus so I'd recommend it to anyone looking to brush up their skills or who needs to supplement what their kids are learning in school. Sal is an engaging lecturer, who doesn't force the pace, and he is endearingly bad at using the drawing tools. His explanations are pretty clear and timed well to fit in with the ten minute maximum time for youtube.

There is an exercise map (now in Google Maps -interesting idea), showing how the topics join up, and you are suggested new exercises as you complete old ones. Success here means getting ten answers right in a row, for me this led to me finding my old scientific calculator and checking answers before submitting them, as getting number 9 wrong can lead to the computer hitting the wall. There is also a hints mechanism that works the question through with you -but using it means that you break your streak (or run of right answers), so if you are unsure you may be better off going to the linked video for an explanation.

Probability and Stats for me next I think.

The End of Time

Julian Barbour

I read this book after a discussion about ‘Continuous Creation’ at work -not the Fred Hoyle version, but the older one by (Locke or Hume?). This says that there is no cause and effect, god creates each instant anew and all memories are illusions.

Barbour’s position is similar, except that by getting rid of time he also gets rid of god. If I understand it correctly he proposes that all possible arrangements of everything just are, all at once, in a place he calls Platonia.  There’s a lot of descriptive (no maths), and interesting physics to justify this, which I think I managed to follow pretty well through special relativity until I got lost in Minkowski space. After that I was like a frog looking at a light from a great distance, the occasional photon would hit providing illumination, but it was a flicker or a flash now and then. Did you know that a frog can see individual photons, nor me.

It’s an interesting idea, formulated partly to get around the problem of specifying an initial state that bedevils mainstream physics. If things never start, or evolve then there is no initial state, just a set of configurations and what looks like time, as we experience it, is just a path through some of these configurations.

I think that the book is well worth reading, I like the concepts, the style and the explanations and it has inspired me to read more -and even to start relearning maths at Khan Academy. I’m not wholly convinced by the central idea, I can’t see how consciousness would exist in Platonia -but then I’m still nostalgically attached to cosmic aether.

More at Julian Barbour’s website :