<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Question for vdRngGaussian and vdRngUniform. in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Question-for-vdRngGaussian-and-vdRngUniform/m-p/1051855#M21211</link>
    <description>&lt;P abp="1457"&gt;Hi!&lt;BR abp="1458" /&gt;
	I want to write the following algorithm using the functions vdRngGaussian and vdRngUniform.&lt;/P&gt;

&lt;PRE class="brush:plain;" abp="1459"&gt;Let X be a vector of n Bernoulli(phi) random variables.
sumx = sum(X);
accept&amp;lt;--aceept


for I=1:nN


1. Propose thetacan ~ Normal(theta, sigma2), wher theta = log(1 + phi) - log(1 -phi);


2.&amp;nbsp; phican = (exp(thetacan)-1)/(exp(thetacan)+1);


3.&amp;nbsp; Compute
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logcan = sumx*log(phican) + (n -sumx)*log(1-phican) + thetacan -2*log(1 +exp(thetacan));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logold =&amp;nbsp; sumx*log(phi) + (n -sumx)*log(1-phi)+ theta-2*log(1 +exp(theta));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logf = logcan - logold;

4. Propose u ~ Uniform(0, 1)

5. if log(u)&amp;lt;logf
&amp;nbsp;&amp;nbsp;&amp;nbsp; phi &amp;lt;--- phican;
&amp;nbsp;&amp;nbsp;&amp;nbsp; accept &amp;lt;-- accept&amp;nbsp; + 1
end

end of iterations
&lt;/PRE&gt;

&lt;P abp="1460"&gt;&amp;nbsp;&lt;/P&gt;

&lt;P abp="1462"&gt;The criterion in order to choose sigma2 is the acceptance rate (accept/N) to range between 30%-50%.&lt;BR abp="1463" /&gt;
	If acceptance rate&amp;lt;30%, increase sigma2.&lt;BR abp="1464" /&gt;
	If acceptance/rata&amp;gt;30%, decrease sigma2.&lt;/P&gt;

&lt;P abp="1465"&gt;I simulated n=5000 observations from Bernoulli(0.9). Using Matlab, I chose sigma2 to be&amp;nbsp; 0.01. I run for&lt;BR abp="1466" /&gt;
	this dataset my matlab-code many times and the acceptance rate was around to 45%. The problem I face is that I can't specify sigma2&lt;BR abp="1467" /&gt;
	for the C-code. For example, I chose sigma2 to be 0.00001 and for 5 different iterations of the algorithm the rate was&lt;BR abp="1468" /&gt;
	&amp;nbsp;{1, 0.2290, 0.0206, 0.3550, 0.3550}.&lt;BR abp="1469" /&gt;
	This is a weird result because from theory it is known than for a value of sigma2, the rate should be equal to a number (for example 0.2290)&lt;BR abp="1470" /&gt;
	and not to range from 0.0206 to 1.&lt;/P&gt;

&lt;P abp="1471"&gt;I attached my C-code, Matlab-code and the dataset.&lt;/P&gt;

&lt;P abp="1472"&gt;Could you please tell me if I haven't use the functions properly.&lt;/P&gt;

&lt;P abp="1473"&gt;Thank you very much.&lt;/P&gt;

&lt;P abp="1474"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Nov 2015 15:43:14 GMT</pubDate>
    <dc:creator>Fiori</dc:creator>
    <dc:date>2015-11-06T15:43:14Z</dc:date>
    <item>
      <title>Question for vdRngGaussian and vdRngUniform.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Question-for-vdRngGaussian-and-vdRngUniform/m-p/1051855#M21211</link>
      <description>&lt;P abp="1457"&gt;Hi!&lt;BR abp="1458" /&gt;
	I want to write the following algorithm using the functions vdRngGaussian and vdRngUniform.&lt;/P&gt;

&lt;PRE class="brush:plain;" abp="1459"&gt;Let X be a vector of n Bernoulli(phi) random variables.
sumx = sum(X);
accept&amp;lt;--aceept


for I=1:nN


1. Propose thetacan ~ Normal(theta, sigma2), wher theta = log(1 + phi) - log(1 -phi);


2.&amp;nbsp; phican = (exp(thetacan)-1)/(exp(thetacan)+1);


3.&amp;nbsp; Compute
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logcan = sumx*log(phican) + (n -sumx)*log(1-phican) + thetacan -2*log(1 +exp(thetacan));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logold =&amp;nbsp; sumx*log(phi) + (n -sumx)*log(1-phi)+ theta-2*log(1 +exp(theta));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logf = logcan - logold;

4. Propose u ~ Uniform(0, 1)

5. if log(u)&amp;lt;logf
&amp;nbsp;&amp;nbsp;&amp;nbsp; phi &amp;lt;--- phican;
&amp;nbsp;&amp;nbsp;&amp;nbsp; accept &amp;lt;-- accept&amp;nbsp; + 1
end

end of iterations
&lt;/PRE&gt;

&lt;P abp="1460"&gt;&amp;nbsp;&lt;/P&gt;

&lt;P abp="1462"&gt;The criterion in order to choose sigma2 is the acceptance rate (accept/N) to range between 30%-50%.&lt;BR abp="1463" /&gt;
	If acceptance rate&amp;lt;30%, increase sigma2.&lt;BR abp="1464" /&gt;
	If acceptance/rata&amp;gt;30%, decrease sigma2.&lt;/P&gt;

&lt;P abp="1465"&gt;I simulated n=5000 observations from Bernoulli(0.9). Using Matlab, I chose sigma2 to be&amp;nbsp; 0.01. I run for&lt;BR abp="1466" /&gt;
	this dataset my matlab-code many times and the acceptance rate was around to 45%. The problem I face is that I can't specify sigma2&lt;BR abp="1467" /&gt;
	for the C-code. For example, I chose sigma2 to be 0.00001 and for 5 different iterations of the algorithm the rate was&lt;BR abp="1468" /&gt;
	&amp;nbsp;{1, 0.2290, 0.0206, 0.3550, 0.3550}.&lt;BR abp="1469" /&gt;
	This is a weird result because from theory it is known than for a value of sigma2, the rate should be equal to a number (for example 0.2290)&lt;BR abp="1470" /&gt;
	and not to range from 0.0206 to 1.&lt;/P&gt;

&lt;P abp="1471"&gt;I attached my C-code, Matlab-code and the dataset.&lt;/P&gt;

&lt;P abp="1472"&gt;Could you please tell me if I haven't use the functions properly.&lt;/P&gt;

&lt;P abp="1473"&gt;Thank you very much.&lt;/P&gt;

&lt;P abp="1474"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 15:43:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Question-for-vdRngGaussian-and-vdRngUniform/m-p/1051855#M21211</guid>
      <dc:creator>Fiori</dc:creator>
      <dc:date>2015-11-06T15:43:14Z</dc:date>
    </item>
    <item>
      <title>Hello,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Question-for-vdRngGaussian-and-vdRngUniform/m-p/1051856#M21212</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;In&amp;nbsp;the loop&amp;nbsp;below&amp;nbsp;you call a codec() routine multiple times. Inside of the routine&amp;nbsp;you use the&amp;nbsp;same MT19937 BRNG initialized with&amp;nbsp;time() output.&amp;nbsp;Can you check how the value of seed&amp;nbsp;varies between calls of the codec()? Alternatively,&amp;nbsp;for experimental purposes can you pass the index of the iteration (or whatever you want but different for each iteration)&amp;nbsp;into codec() and use it as the seed? Please, let me know, the results of the experiment.&lt;/P&gt;

&lt;P&gt;% % C&lt;BR /&gt;
	sigma2c = 0.0001;&lt;BR /&gt;
	phi = phitrue;&lt;BR /&gt;
	drawsc = nan(1, numits);&lt;BR /&gt;
	for i=1:numits&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; out = codec(n, x, phi, sigma2c, acceptc);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; acceptc = out(1, 3); % update accept&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; phi = out(1, 2); % update phi&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; drawsc(1, i) = phi;&lt;BR /&gt;
	end&lt;BR /&gt;
	acceptc/numits&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Aside&amp;nbsp;observation - use of Intel MKL RNGs on vector length 1 is not effective from performance perspective.&lt;/P&gt;

&lt;P&gt;Also, just curious:&amp;nbsp;you generate the array of Bernoulli distributed random numbers using Binomial RNG with ntrials=1 and&amp;nbsp;then calculate the sum of the array entries, thus, get Binomial distribution again. Why not to generate the value using one call to Binomial RNG with the same success probability and number of trials 5000? If this case you will not need summation operation.&amp;nbsp;Please, let me know if that makes sense to you.&lt;/P&gt;

&lt;P&gt;Andrey&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2015 12:17:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Question-for-vdRngGaussian-and-vdRngUniform/m-p/1051856#M21212</guid>
      <dc:creator>Andrey_N_Intel</dc:creator>
      <dc:date>2015-11-07T12:17:56Z</dc:date>
    </item>
  </channel>
</rss>

