montecarlo

Is there a C# library that will perform the Excel NORMINV function?

不羁的心 提交于 2019-11-30 01:41:58
问题 I'm running some Monte Carlo simulations and making extensive use of the Excel function NORM.INV using Office Interrop. This functions takes three arguments (probability, average, standard deviation) and returns the inverse of the cumulative distribution. I'd like to move my code into a web app, but that will require installing Excel on the server. Does anybody know of a C# statistics library that has an equivalent function to NORM.INV? 回答1: Meta.Numerics has exactly what you are looking for.

Computing a mean confidence interval without storing all the data points

醉酒当歌 提交于 2019-11-29 23:22:11
For large n (see below for how to determine what's large enough), it's safe to treat, by the central limit theorem, the distribution of the sample mean as normal (gaussian) but I'd like a procedure that gives a confidence interval for any n . The way to do that is to use a Student T distribution with n-1 degrees of freedom. So the question is, given a stream of data points that you collect or encounter one at a time, how do you compute a c (eg, c=.95 ) confidence interval on the mean of the data points (without storing all of the previously encountered data)? Another way to ask this is: How do

Monte Carlo calculation of Pi in Scala

天涯浪子 提交于 2019-11-29 03:59:37
Suppose I would like to calculate Pi with Monte Carlo simulation as an exercise. I am writing a function, which picks a point in a square (0, 1), (1, 0) at random and tests if the point is inside the circle. import scala.math._ import scala.util.Random def circleTest() = { val (x, y) = (Random.nextDouble, Random.nextDouble) sqrt(x*x + y*y) <= 1 } Then I am writing a function, which takes as arguments the test function and the number of trials and returns the fraction of the trials in which the test was found to be true. def monteCarlo(trials: Int, test: () => Boolean) = (1 to trials).map(_ =>

Is Excel VBA's Rnd() really this bad?

让人想犯罪 __ 提交于 2019-11-29 03:42:59
I need a pseudo random number generator for 2D Monte Carlo simulation that doesn't have the characteristic hyperplanes that you get with simple LCGs. I tested the random number generator Rnd() in Excel 2013 using the following code (takes about 5 secs to run): Sub ZoomRNG() Randomize For i = 1 To 1000 Found = False Do x = Rnd() ' 2 random numbers between 0.0 and 1.0 y = Rnd() If ((x > 0.5) And (x < 0.51)) Then If ((y > 0.5) And (y < 0.51)) Then ' Write if both x & y in a narrow range Cells(i, 1) = i Cells(i, 2) = x Cells(i, 3) = y Found = True End If End If Loop While (Not Found) Next i End

Fixing set.seed for an entire session

我怕爱的太早我们不能终老 提交于 2019-11-29 01:10:28
I am using R to construct an agent based model with a monte carlo process. This means I got many functions that use a random engine of some kind. In order to get reproducible results, I must fix the seed. But, as far as I understand, I must set the seed before every random draw or sample. This is a real pain in the neck. Is there a way to fix the seed? set.seed(123) print(sample(1:10,3)) # [1] 3 8 4 print(sample(1:10,3)) # [1] 9 10 1 set.seed(123) print(sample(1:10,3)) # [1] 3 8 4 There are several options, depending on your exact needs. I suspect the first option, the simplest is not

Computing a mean confidence interval without storing all the data points

不打扰是莪最后的温柔 提交于 2019-11-28 20:44:03
问题 For large n (see below for how to determine what's large enough), it's safe to treat, by the central limit theorem, the distribution of the sample mean as normal (gaussian) but I'd like a procedure that gives a confidence interval for any n . The way to do that is to use a Student T distribution with n-1 degrees of freedom. So the question is, given a stream of data points that you collect or encounter one at a time, how do you compute a c (eg, c=.95 ) confidence interval on the mean of the

Speed up sampling of kernel estimate

倖福魔咒の 提交于 2019-11-28 12:11:36
Here's a MWE of a much larger code I'm using. Basically, it performs a Monte Carlo integration over a KDE ( kernel density estimate ) for all values located below a certain threshold (the integration method was suggested over at this question BTW: Integrate 2D kernel density estimate ). import numpy as np from scipy import stats import time # Generate some random two-dimensional data: def measure(n): "Measurement model, return two coupled measurements." m1 = np.random.normal(size=n) m2 = np.random.normal(scale=0.5, size=n) return m1+m2, m1-m2 # Get data. m1, m2 = measure(20000) # Define limits

Parallel MonteCarlo: reproducibility or real randomness?

时光毁灭记忆、已成空白 提交于 2019-11-28 11:19:25
问题 I'm preparing a college exam in parallel computing. The main purpose is to speedup as much as possible a Montecarlo simulation about electron drift in earth magnetic field. I've already developed something with two layers of parallelization: MPI used to make te code run on several machines OpenMP to run parallel simulation inside the single computer Now comes the question: I would like to keep on-demand the task execution. The fastest computer must be able to execute more work the the slower

Monte Carlo calculation of Pi in Scala

给你一囗甜甜゛ 提交于 2019-11-27 22:14:54
问题 Suppose I would like to calculate Pi with Monte Carlo simulation as an exercise. I am writing a function, which picks a point in a square (0, 1), (1, 0) at random and tests if the point is inside the circle. import scala.math._ import scala.util.Random def circleTest() = { val (x, y) = (Random.nextDouble, Random.nextDouble) sqrt(x*x + y*y) <= 1 } Then I am writing a function, which takes as arguments the test function and the number of trials and returns the fraction of the trials in which

Is Excel VBA's Rnd() really this bad?

亡梦爱人 提交于 2019-11-27 17:44:03
问题 I need a pseudo random number generator for 2D Monte Carlo simulation that doesn't have the characteristic hyperplanes that you get with simple LCGs. I tested the random number generator Rnd() in Excel 2013 using the following code (takes about 5 secs to run): Sub ZoomRNG() Randomize For i = 1 To 1000 Found = False Do x = Rnd() ' 2 random numbers between 0.0 and 1.0 y = Rnd() If ((x > 0.5) And (x < 0.51)) Then If ((y > 0.5) And (y < 0.51)) Then ' Write if both x & y in a narrow range Cells(i,