Friday, September 21, 2007

Il piacere e mio

Given how much I have worked with Italians over the last 5 years or so you'd think I'd have learned a little Italian. But my experiences there have been too disjointed and, frankly, Paolo's English is too good, for it to have ever been really necessary.

Anyway I just went through lesson Italian#1 at Mango Languages site (found via LifeHacker).

The form of learning is based upon repetition and speaking the phrases presented to you going from English to Italian or vice verca. At over 100 slides (it's in the form of a Flash presentation) I found the lesson a little bit too long (I think this may say more about my attention span than anything else) but I guess you end up repeating everything quite a few times.

Mi chiamo Matt. See? Something stuck.

21/09/2007 09:21 by Matt Mower | Permalink | comments:

When random is normal

Okay this is one for the lazyweb mathnerds.

Problem: Generate a pseudo-random number distributed across the range 0 to 1.

To see the difference between uniform and normally distributed numbers take a look at the charts on this page. Essentially it means that while numbers are still pseudo-randomly they, according to the distribution, more likely to cluster around the mean.

I've been looking at approaches based upon the polar form of the Box-Mueller transform as outlined by Dr. Everett (Skip) F. Carter Jr and converted to Ruby as:

def box_mueller( mean = 0.0, stddev = 1.0 )
  x1 = 0.0, x2 = 0.0, w = 0.0

  until w > 0.0 && w < 1.0
    x1 = 2.0 * rand - 1.0
    x2 = 2.0 * rand - 1.0
    w = ( x1 * x2 ) + ( x2 * x2 )
  end

  w = Math.sqrt( -2.0 * Math.log( w ) / w )
  r = x1 * w

  mean + r * stddev
end

calling this with (for example) mean=0.5 and sttdev=0.1 generates a lot of numbers in the correct range but does not preclude generating numbers outside of the range. I could reduce the probability still further by narrowing the stddev but this will not actually eliminate numbers outside the desired range.

It seems to me that the transform I want should be possible, but I cannot envisage how to do it.

21/09/2007 15:48 by Matt Mower | Permalink | comments:
More about: