by Richard Dawkins
The book that describes the biomorphs. It is much more than that, it aims to explain how a complex world can arise from blind chance and natural selection with no need for an 'Intelligent Designer'. I think that this is an excellent book, whether or not you believe in evolution it explains concepts that are key in several areas. A prime example is complexity and how it can arise from simplicity in small steps. The relationship with probability is explored too -together with some estimates of how likely some out comes, ssuch as life in the universe, are.
Dawkins is a good writer with a clear style who uses good examples to illustrate his points. From bats, to crocodiles; from ants to eyes; he takes examples from across the natural world. Consider the eye, one of the claims of intelligent design is that something as complex as an eye couldn't have arisen from natural selection and an 'incomplete' eye is no good. This is patent rubbish, at some point in evolutionary history there were no eyes and then the ability to tell light from dark evolved -that's a useful thing to have, if you're a worm you don't really need any more than that. In addition there are eyes at different stages of completeness within nature -the nautilus has an eye like ours, but with no lens; our eye is wired up backwards - that of the octopus is wired forwards; the point is that you don't need a perfect eye, just one that is good enough and better than your competitors.
Which reminds me of the joke about the wildlife film makers who are watching a cheetah when it spots them and puts the team at the head of the menu. As it charges towards them , the sound recordist starts swapping his boots for trainers, when the camera man points out that he still won't be able to out run a cheetah simply because he's wearing Reeboks. 'Mate' replies the recordist, 'I don't have to run fatster than the cheetah -I just have to run faster than you'.
There is lots of other good stuff in here, genetic algorithms, cooperating genes, discussions around Lamarkism and Punctured Equilibrium, genetic explosions and spirals, the tail of the peacock and convergent evolution. All in all very highly recommended.
'A Bucket of Sparks', 'Tartan Paint' or 'A Long Weight' all things that the innocent gets sent for to waste his time -seemed apt.
Tuesday, 15 February 2011
Thursday, 10 February 2011
First Fix
| A bicycle crash is only a matter of time. |
First Impressions - I like it, it's like being a kid again, the pedals go round all the time, whack you on the back of the leg if you're pushing the bike and you lose them going down steep hills. The bicycle itself needed some setting up of the saddle, seat post and handle bars, but now that is done it feels pretty comfortable. Compared to my tourer the Atlantis is quite wobble and twitchy, I think that this is because the frame is a bit shorter.
The main difference to a normal bicycle is that you can't coast, even when you've just got on you have to keep the feet moving. Secondly, you can slow yourself down by resisting the pedals as they go round, sort of back-pedalling but your legs still go forwards. Then there's the gears or rather gear, being unable to change gears, or coast, means the pedals spin like the fabled dervish going downhill and that you have to get out of the saddle and stand on the pedals to go up. Once you trust the bike, up is easier than down. So long as it doesn't go on too long.
This should be good for getting the legs into shape -there a plan, okay vague idea, to do the c2c this summer, and up north they have hills! And it is fartlek training for free.
My longest run so far is only 8 miles, I'd like to get to double this at some point, but any longer than that and gears are the way to go.
Overall it's a more physical ride and also a smoother one as there's not the clunking gear change, probably especially noticeable on my tourer with its down tube shifters and mongrel drive train. Since your legs are always turning you are always thinking about pace, whether it's recovery, a sprint downhill to get you up the other side, or resistance to stop the bike running away with you. Cycling becomes more involving, and thus more fun.
Monday, 7 February 2011
Biomorphs and Javascript - a marriage made in purgatory.
Well it definitely isn't heaven, and it's not really hell (6502 assembly programming on a machine with no permanent memory and a dodgy power supply comes close).
I'm not sure I'm ready to devote a whole post to how crap Javascript is, I imagine that there are probably whole sites, probably complete universes, devoted to just that topic. But here's a handy hint -your variable isn't locally initialised unless you stick var in front of it, but your program will run anyway, perhaps almost correctly. Having been corrupted by languages where you don't declare variables, just use them, I got some unexpected side effects with the Biomorphs and the variables became global -even though they had been declared locally, inside a function scope. Enough, I've got to go and fill in the hole in the plaster where I was banging my head on the wall.
The biomorph program has had an overhaul and now produces, occasionally, things that look like biomorphs. The main changes have been to switch from polar to Cartesian coordinates and to introduce randomness. The coordinate switch allows the introduction of a 'gene' as a string of x and y coordinates, and having this gene means that it can be populated randomly and thus gives us the potential for 'evolution'. Here's the guts :
function bio_morph()
{
this.gene = new Array(9);
//Generate a random gene 7 is the number of generations and gene 8 is the stem length
for(var i = 0; i<7; i++) {
this.gene[i] = Math.round((Math.random() * 20) -10);
}
this.gene[7] = Math.random() * 10;
this.gene[8] = Math.round(Math.random() * 10);
}
Multiplying by 20 and taking away 10 allows us to have negative numbers in our random sequence, so the creatures can gro up and down, left and right.
All that remains is to produce an array of the critters and allow you to choose the one start new generations from.
As always take a look at the main biomorph page.
I'm not sure I'm ready to devote a whole post to how crap Javascript is, I imagine that there are probably whole sites, probably complete universes, devoted to just that topic. But here's a handy hint -your variable isn't locally initialised unless you stick var in front of it, but your program will run anyway, perhaps almost correctly. Having been corrupted by languages where you don't declare variables, just use them, I got some unexpected side effects with the Biomorphs and the variables became global -even though they had been declared locally, inside a function scope. Enough, I've got to go and fill in the hole in the plaster where I was banging my head on the wall.
The biomorph program has had an overhaul and now produces, occasionally, things that look like biomorphs. The main changes have been to switch from polar to Cartesian coordinates and to introduce randomness. The coordinate switch allows the introduction of a 'gene' as a string of x and y coordinates, and having this gene means that it can be populated randomly and thus gives us the potential for 'evolution'. Here's the guts :
function bio_morph()
{
this.gene = new Array(9);
//Generate a random gene 7 is the number of generations and gene 8 is the stem length
for(var i = 0; i<7; i++) {
this.gene[i] = Math.round((Math.random() * 20) -10);
}
this.gene[7] = Math.random() * 10;
this.gene[8] = Math.round(Math.random() * 10);
}
Multiplying by 20 and taking away 10 allows us to have negative numbers in our random sequence, so the creatures can gro up and down, left and right.
All that remains is to produce an array of the critters and allow you to choose the one start new generations from.
As always take a look at the main biomorph page.
Thursday, 3 February 2011
KISS My Cog. Fixie Bicycle Conversion.
![]() |
| Atlantis Rising |
The main selling point for fixed gear bikes is simplicity. Only one gear, so no deraillieur, shifters and associated nastiness, arguably you don't even need brakes (although this would not be legal in the U.K.) -so you get a simpler and lighter bike. Secondary points are that it makes you a better cyclist, you don't have to think about gear changes, your pedalling style is improved; and your legs get stronger. Since I have the family sparrow legs this can only be good.
![]() |
| KISS in action |
Firstly some research, I can recommend the late, lamented Sheldon Brown and also Charlie the Bike Monger he's more single-speed but some good advice and a good source of parts.
The original rear wheel on the Dawes had a floppy axle and an obsolete SunTour cassette, so I decided to take the line of least resistance and buy a new wheel with a flip-flop hub from Charlie. A flip -flop hub takes a track cog on one side, which is screwed directly to the hub with a counter threaded lock ring (both supplied with the wheel), the other side takes a BMX style cog with an integral freewheel. The idea, from Sheldon, is to have an easier cog on the freewheel side and use this to get you home when the going gets a bit too tough. Since the wheel came with a 16 tooth cog I got a cheapo 18 tooth freewheel. Aside from being tight, I might need to find the right cog and chainring (that's the big cog attached to the pedals)combination by experimentation, so chaep cogs first. You also need rim tape for the wheel, I forgot this and live nowhere near a bike shop, last pair of wheels I bought came with the tape installed -so put a note on your page Charlie, some of us are thick!
Whilst waiting for the bits to arrive I sorted out the brake cables -using a funnel of insulation tape to get oil down them, start off wrapping the tape tightly around the cable outer then looser as you get to the end.
When the wheel arrived cog installation was simple- just screw on, lock ring similar but the wrong way. Next the chain, it is important that this is taut but not tight, there's no deraillieur to take up the slack, and that the run between chainring and cog is straight. Luckily it seems to be straight on the inner ring of the Dawes, so all good. Measure up the chain for both cogs, by offering it up, and remove any surplus links, I bought a half link to get the length just right. Then get the chain taught and nip up the chain side nut first, straighten the wheel, then the other side. Make sure that the wheel nuts are bastard tight, unfortunate things can happen to ones manhood if the chain comes off the cog.
Then it was on with new Aztec brake blocks (twice the braking area of the '50s clone on there), adjust the saddle -which was at a rather alarming angle, and off we go for a spin around the block. And spin you do, no freewheel, no coasting, your legs turn all the time, you can even slow yourself down by back pedalling. Strange but fun, as the actress said to the lady-boy bishop.
I'll let you know how I get on.
Sunday, 30 January 2011
Watching the English by Kate Fox
Subtitled 'The Hidden Rules of English Behaviour' this book purports to tell us why we are like we are -if you're English that is, sorry I shouldn't have assumed that. We do apologise a lot, something to do with our social dis-ease and hypocrisy -see, it's true, I wasn't really sorry.
The main fun that comes from the book is compare your own behaviour -and that of your friends, significant others and work colleagues with the behavioral rules laid out in the book. Kate has cunningly played to the English preoccupation with class by giving codes of behaviour for the various classes under each section. The other half lets herself down with a liking for napkin rings and coasters.
She also attempts to put us into context by comparing us to other nations, for instance picking on our dislike (unless we're from Yorkshire -but the north is another country) of talking about money and our ubiquitous use of humour.
The book is engagingly and amusingly written, but the style can pall and one can get fed up with being called a hypocrite and social autistic, so it is probably best kept as a 'toilet book' -oops 'lavatory book' my lower-middle class slip is showing.
The main fun that comes from the book is compare your own behaviour -and that of your friends, significant others and work colleagues with the behavioral rules laid out in the book. Kate has cunningly played to the English preoccupation with class by giving codes of behaviour for the various classes under each section. The other half lets herself down with a liking for napkin rings and coasters.
She also attempts to put us into context by comparing us to other nations, for instance picking on our dislike (unless we're from Yorkshire -but the north is another country) of talking about money and our ubiquitous use of humour.
The book is engagingly and amusingly written, but the style can pall and one can get fed up with being called a hypocrite and social autistic, so it is probably best kept as a 'toilet book' -oops 'lavatory book' my lower-middle class slip is showing.
Tuesday, 25 January 2011
Recusrsion -tree walkers
There was these tree walkers fell off a cliff. Boom, boom -splat! I'll get my coat.
Much data in computers (including this web page) is stored in tree (or graph, a tree is a particular kind of graph) structures.
In the diagram above the <html> element is the parent of the <head> element and the <title> element is one of the children of that <head> element.
So how do you find elements in a tree? Say I want to do something to all the <p> paragraph tags (which are at different levels) , the only way I can manipulate them is to check every element and see if it's a <p> tag and then do what I want to do.
Recursion is a classic method of walking a tree elegantly and with a minimal knowledge of the size and configuration of that tree. Recursive functions are ones that call themselves again and again to process data -but (and it'd a big but, bigger than Mr Creosote's) they know when to stop. A simple algorithm to process <p> elements might look like :
func find_p($element) {
if($element->name == 'p') {
do_stuff()
}
while($child = $element->get_child()) {
find_p($child);
}
}
You would kick this off by calling it with the <html> element, it's not a <p> so it won't do any processing, just get all of <html> element's children in turn and call itself for each of them.for each of those children it will check if they are a <p> and then get each of their children....
If an element has no children then the function just returns, effectively going back up a level.
Hopefully you can see that the function will go down the tree left side first, so <html> -> <head>-><title>, <title> has no children so the function returns to the calling while loop and <head>s next child <link> ...
At no point in the program have I had to know how many children an element has or how wide or deep the tree is.
You can see recursion in action in the Biomorph program where the method draw_morph() calls itself recursively to create the branching morphs.
NB in the real XML/HTML world you will probably find that the hard work is done for you, if I wanted to process all the <p> tags in a document I'd perhaps use XPath . If you do need to parse an XML document element by element (and I've had to) then recursion would be the way to go.
A word of warning, recursion can be resource heavy, all those function call will reserve resources that won't be freed up until the function returns, if you have a lot of depth and are passing around a lot of data the effect can be significant and your computer could freeze.
Much data in computers (including this web page) is stored in tree (or graph, a tree is a particular kind of graph) structures.
| Tree Structure of an HTML Page |
In the diagram above the <html> element is the parent of the <head> element and the <title> element is one of the children of that <head> element.
So how do you find elements in a tree? Say I want to do something to all the <p> paragraph tags (which are at different levels) , the only way I can manipulate them is to check every element and see if it's a <p> tag and then do what I want to do.
Recursion is a classic method of walking a tree elegantly and with a minimal knowledge of the size and configuration of that tree. Recursive functions are ones that call themselves again and again to process data -but (and it'd a big but, bigger than Mr Creosote's) they know when to stop. A simple algorithm to process <p> elements might look like :
func find_p($element) {
if($element->name == 'p') {
do_stuff()
}
while($child = $element->get_child()) {
find_p($child);
}
}
You would kick this off by calling it with the <html> element, it's not a <p> so it won't do any processing, just get all of <html> element's children in turn and call itself for each of them.for each of those children it will check if they are a <p> and then get each of their children....
If an element has no children then the function just returns, effectively going back up a level.
Hopefully you can see that the function will go down the tree left side first, so <html> -> <head>-><title>, <title> has no children so the function returns to the calling while loop and <head>s next child <link> ...
At no point in the program have I had to know how many children an element has or how wide or deep the tree is.
You can see recursion in action in the Biomorph program where the method draw_morph() calls itself recursively to create the branching morphs.
NB in the real XML/HTML world you will probably find that the hard work is done for you, if I wanted to process all the <p> tags in a document I'd perhaps use XPath . If you do need to parse an XML document element by element (and I've had to) then recursion would be the way to go.
A word of warning, recursion can be resource heavy, all those function call will reserve resources that won't be freed up until the function returns, if you have a lot of depth and are passing around a lot of data the effect can be significant and your computer could freeze.
Sunday, 23 January 2011
Biomorphs - software genetics in HTML5 and Javascript.
'Pull the switch Igor -we're frying tonight!' Today we're going to create artificial life MWHAHAHA! Well not really, but we are going to have a play with genetics and software development, less fun than lightning and a methane atmosphere -but quicker and easier to arrange than a suitable planet.
Richard Dawkins describes biomorphs in his book The Blind Watchmaker (chapter 3). Biomorphs are shapes that change by mutation and it is possible to build up creatures by selecting from the generated shapes. Pretty much a game really, although the book does carry a good description of n-dimensional spaces (9 in this instance) -maybe I finally get it.
As an exercise in brushing up my Javascript -and playing with HTML5 I am going to have a go at creating a version of his concept. The reason for Javascript and HTML5 is that I can host a page with the program on this blog and not have to set up a server somewhere.
In Dawkins original a biomorph is a tree structure that has 9 genes controlling its growth, these genes control things like stem length, branch angle, number of iterations of breeding &c.. There isn't an algorithm as such in the book so this will be an 'Agile' (or suck it and see) development and I'll basically solve small problems and hope that I can bolt them all together for an overall solution.
Finally, as Biomorphs are tree structures the natural algorithm to draw them will be recursive, it'll be interesting to see if Javascript and the browsers can handle that.
The program will appear on a separate page available from the top menu, our first design decision!
![]() |
| Example Biomorphs |
Richard Dawkins describes biomorphs in his book The Blind Watchmaker (chapter 3). Biomorphs are shapes that change by mutation and it is possible to build up creatures by selecting from the generated shapes. Pretty much a game really, although the book does carry a good description of n-dimensional spaces (9 in this instance) -maybe I finally get it.
As an exercise in brushing up my Javascript -and playing with HTML5 I am going to have a go at creating a version of his concept. The reason for Javascript and HTML5 is that I can host a page with the program on this blog and not have to set up a server somewhere.
In Dawkins original a biomorph is a tree structure that has 9 genes controlling its growth, these genes control things like stem length, branch angle, number of iterations of breeding &c.. There isn't an algorithm as such in the book so this will be an 'Agile' (or suck it and see) development and I'll basically solve small problems and hope that I can bolt them all together for an overall solution.
Finally, as Biomorphs are tree structures the natural algorithm to draw them will be recursive, it'll be interesting to see if Javascript and the browsers can handle that.
The program will appear on a separate page available from the top menu, our first design decision!
Subscribe to:
Posts (Atom)


