From 5fd49349f6fa4717b81603f67bf243ae97babcc8 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sun, 19 Dec 2010 11:05:03 +0000 Subject: [PATCH] update to RTS noise --- ChangeLog | 5 ++ src/main.c | 1 - src/maths/misc/Makefile.am | 3 +- src/maths/misc/randnumb.c | 10 ++- src/maths/misc/rnorrexp.c | 133 ------------------------------------- visualc/vngspice.vcproj | 12 ++-- 6 files changed, 19 insertions(+), 145 deletions(-) delete mode 100644 src/maths/misc/rnorrexp.c diff --git a/ChangeLog b/ChangeLog index a4c1039dc..da4798ff4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-19 Holger Vogt + * simplify exp variate generation for RTS noise: + rnorrexp.c removed, + update to randnumb.c, main.c, /maths/misc/makefile.am, visualc/vngspice.vcproj + 2010-12-18 Dietmar Warning * devices/bsim*/*ask.c: correct multiplier m for certain currents, conductances, charges and capacitances if they are requested by plotting and printing, e.g. @m1[gds] diff --git a/src/main.c b/src/main.c index 15463a521..d0c43df91 100644 --- a/src/main.c +++ b/src/main.c @@ -849,7 +849,6 @@ main(int argc, char **argv) cp_program = ft_sim->simulator; srand(getpid()); - zigset(getpid()); TausSeed(); /* --- Process command line options --- */ diff --git a/src/maths/misc/Makefile.am b/src/maths/misc/Makefile.am index 588669247..b5ff770fc 100644 --- a/src/maths/misc/Makefile.am +++ b/src/maths/misc/Makefile.am @@ -15,8 +15,7 @@ libmathmisc_la_SOURCES = \ scalb.c \ norm.h \ norm.c \ - randnumb.c \ - rnorrexp.c + randnumb.c EXTRA_DIST = test_accuracy.c test_erfc.c diff --git a/src/maths/misc/randnumb.c b/src/maths/misc/randnumb.c index 991ac1f00..9e06b66a8 100644 --- a/src/maths/misc/randnumb.c +++ b/src/maths/misc/randnumb.c @@ -65,6 +65,7 @@ double CombLCGTaus(void); float CombLCGTaus2(void); unsigned int CombLCGTausInt(void); unsigned int CombLCGTausInt2(void); +double exprand(double); void checkseed(void); double drand(void); @@ -84,7 +85,6 @@ void checkseed(void) if (cp_getvar("rndseed", CP_NUM, &newseed)) { if ((newseed > 0) && (oldseed != newseed)) { srand(newseed); //srandom(newseed); - zigset(newseed); TausSeed(); oldseed = newseed; printf("Seed value for random number generator is set to %d\n", newseed); @@ -241,3 +241,11 @@ void rgauss(double* py1, double* py2) } +/* return an exponentially distributed random number */ +double exprand(double mean) +{ + double expval; + checkseed(); + expval = -log(CombLCGTaus()) * mean; + return expval; +} diff --git a/src/maths/misc/rnorrexp.c b/src/maths/misc/rnorrexp.c deleted file mode 100644 index 0d7dd56e6..000000000 --- a/src/maths/misc/rnorrexp.c +++ /dev/null @@ -1,133 +0,0 @@ -/* The ziggurat method for RNOR and REXP -Combine the code below with the main program in which you want -normal or exponential variates. Then use of RNOR in any expression -will provide a standard normal variate with mean zero, variance 1, -while use of REXP in any expression will provide an exponential variate -with density exp(-x),x>0. -Before using RNOR or REXP in your main, insert a command such as -zigset(86947731 ); -with your own choice of seed value>0, rather than 86947731. -(If you do not invoke zigset(...) you will get all zeros for RNOR and REXP.) -For details of the method, see Marsaglia and Tsang, "The ziggurat method -for generating random variables", Journ. Statistical Software. - -http://www.jstatsoft.org/v05/i08/supp/1 -download 2010-12-18 -*/ - -#include -static unsigned long jz,jsr=123456789; - -#define SHR3 (jz=jsr, jsr^=(jsr<<13), jsr^=(jsr>>17), jsr^=(jsr<<5),jz+jsr) -#define UNI (.5f + (signed) SHR3*.2328306e-9f) -#define IUNI SHR3 - -static long hz; -static unsigned long iz, kn[128], ke[256]; -static float wn[128],fn[128], we[256],fe[256]; - -#define RNOR (hz=SHR3, iz=hz&127, (fabs(hz)0)? r+x : -r-x; - } - /* iz>0, handle the wedges of other strips */ - if( fn[iz]+UNI*(fn[iz-1]-fn[iz]) < exp(-.5*x*x) ) return x; - - /* initiate, try to exit for(;;) for loop*/ - hz=SHR3; - iz=hz&127; - if(fabs(hz)=1;i--) - {dn=sqrt(-2.*log(vn/dn+exp(-.5*dn*dn))); - kn[i+1]=(dn/tn)*m1; - tn=dn; - fn[i]=exp(-.5*dn*dn); - wn[i]=dn/m1; - } - -/* Set up tables for REXP */ - q = ve/exp(-de); - ke[0]=(de/q)*m2; - ke[1]=0; - - we[0]=q/m2; - we[255]=de/m2; - - fe[0]=1.; - fe[255]=exp(-de); - - for(i=254;i>=1;i--) - {de=-log(ve/de+exp(-de)); - ke[i+1]= (de/te)*m2; - te=de; - fe[i]=exp(-de); - we[i]=de/m2; - } -} - - - - - diff --git a/visualc/vngspice.vcproj b/visualc/vngspice.vcproj index 348a7a7f1..479b20f2d 100644 --- a/visualc/vngspice.vcproj +++ b/visualc/vngspice.vcproj @@ -1891,11 +1891,11 @@ > - -