|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).
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 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.