Esempio n. 1
0
double rnorm(double mean, double sd,double lim, bool inferior) {
	double rn01 = sd * rnormal() + mean;
	if(inferior)
	{
		while(rn01<lim && lim<mean)
			rn01 = sd * rnormal() + mean;
	}else{
		while(rn01>lim && lim>mean)
			rn01 = sd * rnormal() + mean;
	}
	return rn01;
}
Esempio n. 2
0
void newChain_kernel2(Chain *a){ /* kernel <<<G, 1>>> */
  int n, g, G = a->G;
  num_t u;

  for(g = 0; g < a->G; ++g){
    a->tmp1[g] = 0;
    a->tmp2[g] = 0;
  
    a->dex[g] = 0;
    a->hph[g] = 0;
    a->lph[g] = 0;
    a->mph[g] = 0;

    a->phi[g] = rnormal(a->thePhi, a->sigPhi);
    a->eta[g] = 1/sqrt(rgamma(a->d / 2, 
                   a->d * a->tau * a->tau / 2, 0));

    a->accPhi[g] = 0;
    a->accAlp[g] = 0;
    a->accDel[g] = 0;

    a->tunePhi[g] = 1;

    a->meanPhi[g] = 0;
    a->meanAlp[g] = 0;
    a->meanDel[g] = 0;

    for(n = 0; n < a->N; ++n){
      a->eps[iG(n, g)] = rnormal(0, a->eta[g]);
      a->meanEps[iG(n, g)] = 0;
      a->accEps[iG(n, g)] = 0;
      a->tuneEps[iG(n, g)] = 1;
    }
    
    u = runiform(0, 1);
    if(u < a->piAlp){
      a->alp[g] = 0;
    } else {
      a->alp[g] = rnormal(a->theAlp, a->sigAlp);
    }
    
    u = runiform(0, 1);
    if(u < a->piDel){
      a->del[g] = 0;
    } else {
      a->del[g] = rnormal(a->theDel, a->sigDel);
    }
  }
}
Esempio n. 3
0
double rpnormal(double m, double sd)
{
  double x, pm, psd;
  /* force the mean and std.dev. to be positive */
  /* WE REALLY SHOULD THROW AN EXCEPTION... */
  pm = fabs(m);
  psd = fabs(sd);
  for (;;)
    if ((x = rnormal(pm, psd)) > 0.0) return x;
}
/*************************************************************************
Random point from sphere
*************************************************************************/
static double rsphere(ap::real_2d_array& xy, int n, int i)
{
    double result;
    int j;
    double v;

    for(j = 0; j <= n-1; j++)
    {
        xy(i,j) = rnormal();
    }
    v = ap::vdotproduct(&xy(i, 0), &xy(i, 0), ap::vlen(0,n-1));
    v = ap::randomreal()/sqrt(v);
    ap::vmul(&xy(i, 0), ap::vlen(0,n-1), v);
    return result;
}
Esempio n. 5
0
/* codes                                         */
void gaussian_volume_source(spinor * const P, spinor * const Q,
			    const int sample, const int nstore, const int f) 
{
  int x, y, z, t, i, reset = 0, seed; 
  int rlxd_state[105];
  spinor * p;

  /* save the ranlxd_state if neccessary */
  if(ranlxd_init == 1) {
    rlxd_get(rlxd_state);
    reset = 1;
  }

  /* Compute the seed */
  seed =(int) abs(1 + sample + f*10*97 + nstore*100*53 + g_cart_id*13);

  rlxd_init(1, seed);

  for(t = 0; t < T; t++) {
    for(x = 0; x < LX; x++) {
      for(y =0; y < LY; y++) {
	for(z = 0; z < LZ; z++) {
	  i = g_lexic2eosub[ g_ipt[t][x][y][z] ];
	  if((t+x+y+z+g_proc_coords[3]*LZ+g_proc_coords[2]*LY 
	      + g_proc_coords[0]*T+g_proc_coords[1]*LX)%2 == 0) {
	    p = (P + i);
	  }
	  else {
	    p = (Q + i);
	  }
	  rnormal((double*)p, 24);
	}
      }
    }
  }

  /* reset the ranlxd if neccessary */
  if(reset) {
    rlxd_reset(rlxd_state);
  }
  return;
}
Esempio n. 6
0
void newChain_kernel1(Chain *a){ /* kernel <<<1, 1>>> */
  int n;

  a->m = 1; 
  a->accD = 0;
  a->tuneD = 400;
  
  a->meanLogLik = 0;
  a->logLikMean = 0;
  a->dic = 0;
  
  for(n = 0; n < a->N; ++n){
    a->meanC[n] = 0;
    a->c[n] = 0;
    a->accC[n] = 0;
    a->tuneC[n] = 1;
  }
  
  if(!a->constTau)
    a->tau = sqrt(rgamma(a->aTau, a->bTau, 0));
 
  if(!a->constPiAlp)
    a->piAlp = rbeta(a->aAlp, a->bAlp);
  
  if(!a->constPiDel)
    a->piDel = rbeta(a->aDel, a->bDel);

  if(!a->constD)
    a->d = runiform(0, a->d0);
 
  if(!a->constThePhi)
    a->thePhi = rnormal(0, a->gamPhi);

  if(!a->constTheAlp)
    a->theAlp = rnormal(0, a->gamAlp);

  if(!a->constTheDel)
    a->theDel = rnormal(0, a->gamDel);
 
  if(!a->constSigC)
    a->sigC = runiform(0, a->sigC0);
   
  if(!a->constSigPhi)
    a->sigPhi = runiform(0, a->sigPhi0);

  if(!a->constSigAlp)
    a->sigAlp = runiform(0, a->sigAlp0);
 
  if(!a->constSigDel)
    a->sigDel = runiform(0, a->sigDel0);  
    
  a->s1 = 0;
  a->s2 = 0;
  
  for(n = 0; n < a->N; ++n){
    a->Old[n] = 0;
    a->New[n] = 0;
    a->lOld[n] = 0;
    a->lNew[n] = 0;
  }
}
Esempio n. 7
0
double rnorm(double mean, double sd,double liminf ,double limsup) {
	double rn01 = sd * rnormal() + mean;
	while((rn01<liminf || rn01>limsup ) && (liminf<limsup && liminf<mean && limsup>mean))
		rn01 = sd * rnormal() + mean;
	return rn01;
}
Esempio n. 8
0
double rnorm(double mean, double sd) {
	double rn01 = rnormal();
	return (sd * rn01 + mean);
}