User:TheLarry/Notebook/Larrys Notebook/2010/02/28

From OpenWetWare
Jump to navigationJump to search
Tracking Main project page
Previous entry      Next entry

Monte Carlo Integration

I wanted to have some fun today since yesterday all i did was look for data that i should have saved in a better place in the past. so i decided to take another whack at monte carlo integration after i had some inspiration this morning. so here is the code. I remote desktopped so it isn't my cleanest program (a lot of wires all around and not easy to follow).

Here is the code.

I don't do a good job of getting my random numbers to go from min to max. the random number dice go from 0 to 1 but i want it to go from -50 to 50 (or something like that). I don't have a good method. in this code i just randomly select half the times to from -50 to 0 and the other half 0 to 50 and double check that it is within the range. but there has to be a better way to map 0 to 1 to be -50 to 50.

also i don't know if it is a good idea but i change the fractional index to integers and use those to index the intensity (z 2-d array). not sure if that is the best idea. then i check to make sure the corresponding z value to those random x and y is less than the random z value. if it is then i add 1 to keep track of how many times the random numbers is within the surface.

anyways i ran this on the airy disk. the integration from straight up doing it gave me an answer of 296.0481 and through monte carlo with N = 100000 gave me an answer of 294.713. i also ran this on a normalized Gaussian and got a monte carlo integration of 1.03666. I am about to figure out theoretically what the variance should be. i'll be right back.

I'll come back with the variance later. Anyways there are a lot of interesting methods to make the program faster and more efficient. However I am not in a rush to write this since it isn't necessary (yet).

Monte Carlo Airy Disk

Now that i started to feel a bit better about the normalized Airy Disk i decided to randomly choose which pixels light up. i think this is what koch and i will have to do to create a microtubule. anyways here is the image

I ran 10000 random numbers to find each pixels. Each time it found a pixel it added 10 intensity to each pixel. I know i am not doing a good job explaining.

I am thinking how this opens up to a Poisson Noise in the end. Not sure, it might come up in the end though. I am still not sure where this is going to go.

Steve Koch 01:14, 1 March 2010 (EST): The image is sweet. Looking at it, looks like what we want, regarding random photon landings. We can talk in person tomorrow (afternoon probably). Also, the code above is Richard Yeh-esque. I didn't look at all of it, but isn't your problem easily solved by multiplying random # by 100 and then subtracting 50? Even if so, that's just a factor of 2, so doesn't matter too much. You'll have to explain the method to me, I don't think I'm familiar. OK, cool image!