Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.
Is being called like this millions of times for example:
IDistribution dist = new DiscreteNormalDistribution(1048576);
...
SimMat[i, j] = dist.ICDF(rnd.nextUniform());
class DiscreteNormalDistribution : IDistribution
{
private long msize;
private double[] vals;
public DiscreteNormalDistribution(long size)
{
NormalDistribution dist = new NormalDistribution();
msize = size;
vals = new double[size+1];
double z;
for (long i = 1; i < size-1; i++)
{
z = (1.0/size)*i;
vals[i] = dist.ICDF(z);
}
vals[0] = vals[1];
vals[size] = vals[size - 1];
}
public double PDF(double q)
{
return 0;
}
public double CDF(double q)
{
return 0;
}
public double ICDF(double q)
{
long z = Convert.ToInt64(q * (msize));
if (z < 0 || z > msize)
{
return 0;
}
else return vals[z];
}
public double Generate(IRandomGenerator x)
{
return ICDF(x.nextUniform());
}
}
class NormalDistribution: IDistribution
{
public double PDF(double q)
{
return 0;
}
public double CDF(double q)
{
return 0;
}
public double ICDF(double q)
{
if (q == .5)
return 0;
q = 1.0 - q;
double p = (q > 0.0 && q < 0.5) ? q : (1.0 - q);
double t = Math.Sqrt(Math.Log(1.0 / Math.Pow(p, 2.0)));
double c0 = 2.515517;
double c1 = 0.802853;
double c2 = 0.010328;
double d1 = 1.432788;
double d2 = 0.189269;
double d3 = 0.001308;
// double x = t - (c0 + c1 * t + c2 * Math.Pow(t, 2.0)) /
// (1.0 + d1 * t + d2 * Math.Pow(t, 2.0) + d3 * Math.Pow(t, 3.0));
double x = t - (c0 + c1 * t + c2 *(t*t)) /
(1.0 + d1 * t + d2 * (t*t) + d3 * (t*t*t));
if (q > .5)
x *= -1.0;
return x;
}
public double Generate(IRandomGenerator x)
{
return ICDF(x.nextUniform());
}
}
If you want to consider a hardware/software solution, there is the CUDA language (http://www.nvidia.com/object/cuda_ho ) designed to work with stream computation engines in nVidia video cards (8800GT and above). It is already in use in some financial institutions that need parallel processing in existing servers (you install a dedicated computation card). 10x speed increases are not unheard of.me.html#
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
WKHTMLTOPDF - --disable-smart-shrinking not working | 10 | 77 | |
System.Speech | 2 | 26 | |
VB: Convert 2 dates to specific format | 24 | 48 | |
How come this regular expression allows "e"? | 14 | 33 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
13 Experts available now in Live!