Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

Lognormal random distribution generator outputs nonsense numbers

$
0
0

The code below is in C#; All three random distribution generators should provide a set of numbers centered around value 20; all of them report success.  Gaussian and Weibull distribution generators output expected data stream centered around 20.  Lognormal distribution, however outputs numbers that are mostly between 1e9 and 1e8.  The four last parameters in the call should be: the average(a), the std.deviation (sigma), the displacement (b) and scaling (beta).  Double precision lognormal and other RNG methods result in exactly the same behavior.  The wrappers below, show how I have declared calls' parameters. 

Could anyone point to the error of mine?  Could it be a bug in MKL?  Happy to provide full code upon request.

        private void button_Click(object sender, EventArgs e)
        {
            IntPtr stream = new IntPtr();
            var rnd = new float[len];
            status = VSL.vslNewStream(ref stream, VSL.BRNG.MT19937, seed);
            status = VSL.vsRngGaussian(VSL.RNG_METHOD.GAUSSIAN_BOXMULLER, stream, len, rnd, 20f, 1f);
            status = VSL.vsRngWeibull(VSL.RNG_METHOD.WEIBULL_ICDF, stream, len, rnd, 3f, 0f, 20f);
            status = VSL.vsRngLognormal(VSL.RNG_METHOD.LOGNORMAL_ICDF, stream, len, rnd, 20f, 0.8f, 0f, 1f);
            VSL.vslDeleteStream(ref stream);
        }
        const string libName = "mkl_rt.dll";
        [DllImport(libName, EntryPoint = "vslNewStream", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
        public static extern int vslNewStream(ref IntPtr stream, int brng, uint seed);
        [DllImport(libName, EntryPoint = "vslDeleteStream", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
        public static extern int vslDeleteStream(ref IntPtr stream);
        [DllImport(libName, EntryPoint = "vsRngGaussian", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
        public static extern int vsRngGaussian(int method, IntPtr stream, int count, [Out]float[] r, float mean, float stdev);

        [DllImport(libName, EntryPoint = "vsRngWeibull", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
        public static extern int vsRngWeibull(int method, IntPtr stream, int count, [Out]float[] r, float alpha, float a, float beta);

        [DllImport(libName, EntryPoint = "vsRngLognormal", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = true)]
        public static extern int vsRngLognormal(int method, IntPtr stream, int count, [Out]float[] r, float a, float sigma, float b, float beta);

Windows 7;  VS 2017, VS 2019; C#;  Error appears in Intel MKL 2020 1, and in Intel MKL 2017 2.


Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>