Forever Learning

Forever learning and helping machines do the same.

More Pi

with 2 comments

Hmmm. Pie.

Hmmm. Pie.

In a previous post I’ve explained how we can estimate the number Pi using Monte Carlo Methods (basically throwing darts at a circle). I personally think this method is quite elegant, but it is not particularly efficient. It might take a very, very, very long time for it to converge to anything close to the actual number. Still, pretty awesome.

This week I’ve compiled a simple, interactive and more visual example using the jQuery library and SVG graphics. You can find it here. Let me know what you think.

Update (april 2nd 2011): Code for this project is now available on Github.

Written by Lukas Vermeer

November 6, 2010 at 11:58

2 Responses

Subscribe to comments with RSS.

  1. I suppose one way to make this more efficient is to use symmetry. Dividing the image in four quarters makes it 4 times faster. You can also exclude the inner half of a quadrant, saving another factor 2. Etc.

    After that, you need some sort of way to avoid putting dots in a place that you already know is inside the circle. Or some other way to get closer and closer to the interesting area.

    Sjors Provoost

    November 7, 2010 at 21:30

    • Symmetry will not do you any good. Remember that we are interested in the ratio of the surface areas; dividing the image in four parts is similar to multiplying both the numerator and the denominator by four. It won’t increase the speed of convergence.

      Excluding some parts of the image might help, but only if you know the exact fraction of both bodies you are excluding and come up with an efficient way to select random points uniformly distributed over the area you are including. I’m guessing just selecting random points in a square is faster. (certainly easier to implement…)

      Thanks for your input! If you come up with a more efficient strategy be sure to let me know; I’ll implement it if I can.


      November 8, 2010 at 20:16

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: