亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? random.h

?? 矩陣運算的模板類
?? H
字號:
// -*- c++ -*-///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 Oh-Wook Kwon, all rights reserved. ohwook@yahoo.com
//
//                          Easy Matrix Template Library
// 
// This Easy Matrix Template Library is provided "as is" without any express 
// or implied warranty of any kind with respect to this software. 
// In particular the authors shall not be liable for any direct, 
// indirect, special, incidental or consequential damages arising 
// in any way from use of the software.
// 
// Everyone is granted permission to copy, modify and redistribute this
// Easy Matrix Template Library, provided:
//  1.  All copies contain this copyright notice.
//  2.  All modified copies shall carry a notice stating who
//      made the last modification and the date of such modification.
//  3.  No charge is made for this software or works derived from it.  
//      This clause shall not be construed as constraining other software
//      distributed on the same medium as this software, nor is a
//      distribution fee considered a charge.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Filename: Random.h
//
// Note:
//  1. Distributions other than uniform and Gaussian were not tested.
//     You need to test the resulting distribution before use.
//     In particular, the Gamma distribution has a poor pdf when a<=1.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _RANDOM_H_#define _RANDOM_H_
// Undefine rand and srand to avoid name collisions
// Use RANDF and SRAND instead.
#ifdef USE_LOCAL_RAND
#ifdef rand
#undef rand
#endif
#ifdef srand
#undef srand
#endif
#else
#include <stdlib.h>
#endif


// RANDF() returns a uniform random number [0,1).
#if defined(USE_LOCAL_RAND)
#define RANDF() UniformRandom()
#define SRAND(x) SRand(x)
#define SRANDN(x) SRandn(x)
double Rand();
void SRand(unsigned int seed);
#elif defined(__unix)// Prototype for C Library functions deand48 and srand48.double drand48();void srand48(long);
#define RANDF() drand48()#define SRAND(x) srand48(x)
#define SRANDN(x) SRandn(x)#elif defined(WIN32)// If not unix use ANSI C defaults.#define __rand() ((double)rand()/RAND_MAX)#define RANDF() __rand()
#define SRAND(x) srand(x)
#define SRANDN(x) SRandn(x)
#else
#pragma message ( "Your system does not have random number generators " __FILE__ )
#pragma message ( "Define __unix or WIN32 " )
!!error!! // to stop compiling#endif


double UniformRandom();
double GaussianRandom();
void SRandn(unsigned int seed);


template <typename T> class UniformDist;
template <typename T> class GaussianDist;
template <typename T> class MiscellaneousDist;

///////////////////////////////////////////////////////////////////////////////
// Exported routines
///////////////////////////////////////////////////////////////////////////////

// continuous distributions
#ifdef USE_LOCAL_RAND
inline double UniformRandom();
inline void SRand(unsigned int seed);
#endif
inline double GaussianRandom();
inline void SRandn(unsigned int seed);
inline double ExponentialRandom(double lambda);
inline double TRandom(double n); // Student's t-distribution with n degree of freedom
inline double GammaRandom(double a, double b);
inline double BetaRandom(double a, double b);
inline double FisherRandom(double m, double n); // m degrees of freedom in the numerator and n degrees of freedom in the denominator
inline double ChiSquareRandom(double n); // n degree of freedom
inline double CauchyRandom();

// discrete distributions
inline int BernoulliRandom(double p);
inline int BinomialRandom(int n,double p);
inline int PossionRandom(double lambda);


///////////////////////////////////////////////////////////////////////////////
// Implementation of random number generation
///////////////////////////////////////////////////////////////////////////////

#ifdef USE_LOCAL_RAND
struct Int32__ {
	unsigned short high;
	unsigned short low;
};


///////////////////////////////////////////////////////////////////////////////
// There must exist only one uniform random number generator in the whole system.
// I had to implement a singleton object using a static member function and 
// a static object defined within the static member function.
///////////////////////////////////////////////////////////////////////////////
template <typename T>
class UniformDist {
public:
	UniformDist() {}
	virtual ~UniformDist() {}
	static UniformDist<double>* GetUniformDist();
	static void SRand_(unsigned int seed);
	static double Rand_();
private:
	unsigned int rand_seed;
	Int32__ rand_value;
};

template <typename T> UniformDist<double>* UniformDist<T>::GetUniformDist(){
	static UniformDist<double> uniformDist;
	return &uniformDist;
}


template <typename T> void UniformDist<T>::SRand_(unsigned int seed){
	UniformDist* p=UniformDist::GetUniformDist();
	p->rand_seed=seed;
	p->rand_value.high=seed/65536;
	p->rand_value.low=seed%65536;
}


///////////////////////////////////////////////////////////////////////////////
// Uniform distribution [0,1)
//   x = (69069*x+1)%pow(2,32);
//   u = x/pow(2,32)
// Reference: C.P. Robert, The Bayesian Choice, 2nd ed., Springer, 2001.
///////////////////////////////////////////////////////////////////////////////
template <typename T> double UniformDist<T>::Rand_()
{
	UniformDist* p=UniformDist::GetUniformDist();
	static Int32__ c={1,3533}; // 69069
	static double rand_max=pow((double)2.0,(double)32);

	unsigned int x1=c.low*p->rand_value.low+1;
	unsigned int x2=c.low*p->rand_value.high;
	unsigned int x3=c.high*p->rand_value.low;
	unsigned int x4=c.high*p->rand_value.high;
	p->rand_value.low=x1 & 0xffff;
	unsigned int x1h=(unsigned int)(0xffff & ((x1&0xffff0000)>>16));
	unsigned int x2l=(unsigned int)(x2&0xffff);
	unsigned int x3l=(unsigned int)(x3&0xffff);
	p->rand_value.high=(unsigned int)(x1h+x2l+x3l);
	double u=(unsigned int)(65536*p->rand_value.high+p->rand_value.low)/rand_max;
	return u;
}

#endif


///////////////////////////////////////////////////////////////////////////////
// Gaussian distribution
///////////////////////////////////////////////////////////////////////////////
template <typename T>
class GaussianDist {
public:
	GaussianDist() { gaussSaved=0; }
	virtual ~GaussianDist() {}
	static GaussianDist<double>* GetGaussianDist();
	static void SRandn_(unsigned int seed);
	static double Randn_();
private:
	int gaussSaved; // GaussDeviate generates numbers in pairs
    double gaussSave; // 2nd of pair is remembered here
#ifdef USE_LOCAL_RAND
	unsigned int rand_seed;
	Int32__ rand_value;
#endif

};


template <typename T> GaussianDist<double>* GaussianDist<T>::GetGaussianDist(){
	static GaussianDist<double> gaussianDist;
	return &gaussianDist;
}


template <typename T> void GaussianDist<T>::SRandn_(unsigned int seed){
	GaussianDist* p=GaussianDist<double>::GetGaussianDist();
#ifdef USE_LOCAL_RAND
	p->rand_seed=seed;
	p->rand_value.high=seed/65536;
	p->rand_value.low=seed%65536;
#endif
	p->gaussSaved=0;
	p->gaussSave=0;
}


// random number with a N(0,1) distribution
template <typename T> double GaussianDist<T>::Randn_()
{
	GaussianDist* p=GaussianDist<double>::GetGaussianDist();
   double fac,r,v1,v2,x;
   if (p->gaussSaved) {
      x = p->gaussSave; p->gaussSaved = 0;
   }
   else {
      do {
#ifdef USE_LOCAL_RAND
         v1 = 2.0*UniformRandom() - 1.0;
         v2 = 2.0*UniformRandom() - 1.0;
#else
		 v1 = 2.0*RANDF() - 1.0;
         v2 = 2.0*RANDF() - 1.0;
#endif
         r = v1*v1 + v2*v2;
      }
      while (r>=1.0);
      fac = sqrt(-2.0*log(r)/r);
      p->gaussSaved = 1;
      p->gaussSave = v1*fac;
      x = v2*fac;
   }
   return x;
}


///////////////////////////////////////////////////////////////////////////////
// Other distributions
///////////////////////////////////////////////////////////////////////////////
template <typename T> 
class MiscellaneousDist {
public:
	// continuous distributions
	static double ExponentialRandom_(double lambda=1);
	static double TRandom_(double n);
	static double GammaRandom_(double a, double b=1);
	static double BetaRandom_(double a, double b);
	static double FisherRandom_(double m, double n);
	static double ChiSquareRandom_(double lambda);
	static double CauchyRandom_();

	// discrete distributions
	static int BernoulliRandom_(double p);
	static int BinomialRandom_(int n,double p);
	static int NegativeBinomialRandom_(int n,double p);
	static int PossionRandom_(double lambda);
	static int HyperGeometricalbRandom_(int N,int n,double p);

};


template <typename T> double MiscellaneousDist<T>::ExponentialRandom_(double lambda){
	double u;
	while(1){
		u=UniformRandom();
		if(u!=0) break;
	}
	return -log(u)/lambda;
}


// n degree of freedom
template <typename T> double MiscellaneousDist<T>::TRandom_(double n){
	while(1){
		double u1=UniformRandom();
		double u2=UniformRandom();
		double x,v;
		if(u1 < 0.5){
			x=1/(4*u1-1);
			v=u2/(x*x);
		}
		else{
			x=4*u1-3;
			v=u2;
		}
		if( v < 1-(fabs(x)/2) || v < pow(1+(x*x/n), -(n+1)/2.0) )
			return x;
	}
}


template <typename T> double MiscellaneousDist<T>::GammaRandom_(double a, double b){
	assert(a>0 && b>0);
	double u1,u2;
	if(a > 50){
		return GaussianRandom()*sqrt(a)/b + (a/b);
	}
	else if(a > 1){
		double c1=a-1, c2=(a-(1/(6*a)))/c1, c3=2/c1, c4=1+c3, c5=1/sqrt(a);
		while(1){
			while(1){
				u1=UniformRandom();
				u2=UniformRandom();
				if(a > 2.5){
					u1 = u2 + c5 * (1-1.86*u1);
				}
				if(u1 > 0 && u1 < 1) break;
			}
			double w=c2*u2/u1;
			if(c3*u1+w+1/w <= c4 || c3*log(u1)-log(w)+w <= 1)
				return (b*c1*w);
		}
	}
	else{
		double e=exp(1);
		while(1){
			u1=UniformRandom();
			u2=UniformRandom();
			double x,y;
			if(u1 > e/(e+a)){
				x=-log((a+e)*(1-u1)/(a*e));
				y=pow(x,a-1);
			}
			else{
				x=pow((a+e)*u1*e,1/a);
				y=exp(-a);
			}
			if(u2<y)
				return (b*x);
		}
	}
}


template <typename T> double MiscellaneousDist<T>::BetaRandom_(double a, double b){
	double y1=GammaRandom(a,1);
	double y2=GammaRandom(b,1);
	return y1/(y1+y2);
}


// m degrees of freedom in the numerator and n degrees of freedom in the denominator
template <typename T> double MiscellaneousDist<T>::FisherRandom_(double m, double n){
	double xnom=ChiSquareRandom(m)/m;
	double xdenom;
	while(1){
		xdenom=ChiSquareRandom(n)/n;
		if(xdenom > xnom/mtl_numeric_limits<double>::max()) break;
	}
	return xnom/xdenom;
}


// n degree of freedom
template <typename T> double MiscellaneousDist<T>::ChiSquareRandom_(double n){
	return GammaRandom(n/2.0,2.0);
}


template <typename T> double MiscellaneousDist<T>::CauchyRandom_(){
	static double pi=4*atan(1);
	//f(x)=1/(pi*(1+x^2))
	return tan(pi*(UniformRandom()-0.5));
}


template <typename T> int MiscellaneousDist<T>::BernoulliRandom_(double p){
	if(UniformRandom()<=p) return 1;
	else return 0;
}


template <typename T> int MiscellaneousDist<T>::BinomialRandom_(int n,double p){
	int K=n;
	if(n <= 30){
		int count = 0;
		for(int i=1;i<=n;i++){
			double u=UniformRandom();
			if(u < p) count++;
		}
		return count;
	}
	else{
		int i, k=n, x=0;
		double l=p;
		while(1){
			i=(int)(1+k*l);
			double v=BetaRandom(i,k+1-i);
			if(l>v){
				l=l/v;
				k=i-1;
			}
			else{
				x=x+i;
				l=(l-v)/(1-v);
				k=k-i;
			}
			if(k<=K) break;
		}
		for(i=1;i<=k;i++){
			double u=UniformRandom();
			if(u<p) x++;
		}
		return x;
	}
}


template <typename T> int MiscellaneousDist<T>::PossionRandom_(double lambda){
	if(lambda<30){
		double p=1;
		int N=0;
		double c=exp(-lambda);
		while(1){
			double u=UniformRandom();
			p=p*u;
			N=N+1;
			if(p<c) break;
		}
		return N-1;
	}
	else{
		static double pi=4*atan(1);
		double c=0.767-3.36/lambda;
		double beta=pi*pow((2*lambda),-0.5);
		double alpha=beta*lambda;
		double k=log(c)-lambda-log(beta);
		double x;
		while(1){
			while(1){
				double u1=UniformRandom();
				x=(alpha-log((1-u1)/u1))/beta;
				if(x>-0.5) break;
			}
			double u2=UniformRandom();
			int N=(int)(x+0.5);
			if( alpha-beta*x+log(u2/(1+exp(2*(alpha-beta*x)))) <= k+N*log(lambda)-log(N) )
				return N;
		}
	}
}


////////////////////////////////////////////////////////////////////////////
// Implementation of the exported routines
////////////////////////////////////////////////////////////////////////////

#ifdef USE_LOCAL_RAND
inline double UniformRandom(){
	return UniformDist<double>::Rand_();
}


inline void SRand(unsigned int seed){
	UniformDist<double>::SRand_(seed);
}
#endif


inline double GaussianRandom(){
	return GaussianDist<double>::Randn_();
}


inline void SRandn(unsigned int seed){
#ifdef USE_LOCAL_RAND
	GaussianDist<double>::SRandn_(seed);
#endif
}


inline double ExponentialRandom(double lambda){
	return MiscellaneousDist<double>::ExponentialRandom_(lambda);
}


// n degree of freedom
inline double TRandom(double n){
	return MiscellaneousDist<double>::TRandom_(n);
}


inline double GammaRandom(double a, double b){
	return MiscellaneousDist<double>::GammaRandom_(a,b);
}


inline double BetaRandom(double a, double b){
	return MiscellaneousDist<double>::BetaRandom_(a,b);
}


// m degrees of freedom in the numerator and n degrees of freedom in the denominator
inline double FisherRandom(double m, double n){
	return MiscellaneousDist<double>::FisherRandom_(m,n);
}


// n degree of freedom
inline double ChiSquareRandom(double n){
	return MiscellaneousDist<double>::ChiSquareRandom_(n);
}


inline double CauchyRandom(){
	return MiscellaneousDist<double>::CauchyRandom_();
}


inline int BernoulliRandom(double p){
	return MiscellaneousDist<double>::BernoulliRandom_(p);
}


inline int BinomialRandom(int n,double p){
	return MiscellaneousDist<double>::BinomialRandom_(n,p);
}


inline int PossionRandom(double lambda){
	return MiscellaneousDist<double>::PossionRandom_(lambda);
}


#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产日韩视频一区二区三区| 午夜激情久久久| 亚洲永久精品大片| 国产大陆a不卡| 欧美理论电影在线| 中文字幕一区二区三区蜜月| 蜜臀精品久久久久久蜜臀 | 中文字幕成人在线观看| 亚洲男人天堂av| 国产精品中文字幕欧美| 欧美少妇一区二区| 国产精品福利一区二区| 国产在线精品一区二区夜色| 欧美日韩精品三区| 一区二区三区四区亚洲| 成人精品国产免费网站| 久久麻豆一区二区| 极品尤物av久久免费看| 欧美日韩高清一区| 亚洲精品老司机| 91一区二区在线| 自拍偷拍国产亚洲| 99国内精品久久| 亚洲美女免费视频| 日本高清不卡视频| 亚洲欧美激情一区二区| 成人av高清在线| 亚洲欧洲精品天堂一级| 成人sese在线| 亚洲天天做日日做天天谢日日欢| 成人在线视频一区| 国产精品美女www爽爽爽| 国产经典欧美精品| 国产精品国产三级国产有无不卡 | 免费看日韩精品| 91麻豆精品国产| 麻豆91在线播放| 久久久久国产精品人| 成人一区二区在线观看| 欧美激情一二三区| 色综合咪咪久久| 亚洲一二三区在线观看| 欧美日韩二区三区| 日韩成人一级片| 精品三级在线看| 国产成人超碰人人澡人人澡| 中文字幕中文字幕在线一区| 在线观看成人小视频| 亚洲成人1区2区| 欧美xxxxx裸体时装秀| 国产精品一级二级三级| 中文字幕亚洲一区二区av在线| 色综合天天综合在线视频| 性久久久久久久久久久久| 精品人伦一区二区色婷婷| 国产成人免费视频精品含羞草妖精| 欧美国产视频在线| 日本韩国欧美一区| 蜜桃视频一区二区| 中文字幕在线观看一区二区| 日本高清不卡一区| 激情文学综合插| 亚洲三级久久久| 欧美一卡二卡在线| 成人污视频在线观看| 午夜精品一区二区三区电影天堂| 久久综合九色综合欧美就去吻 | 亚洲男人的天堂av| 欧美一级理论性理论a| 国产99久久久国产精品| 五月激情丁香一区二区三区| 日本一区二区三区dvd视频在线| 色综合久久久久网| 黄色精品一二区| 亚洲成年人影院| 国产精品视频看| 精品欧美一区二区久久| 色综合天天综合给合国产| 国产在线精品视频| 亚洲18影院在线观看| 国产精品麻豆视频| 久久综合99re88久久爱| 欧美老女人在线| 色8久久人人97超碰香蕉987| 国产成人av自拍| 久久成人综合网| 日产国产高清一区二区三区 | 中文字幕第一页久久| 欧美一区2区视频在线观看| 色狠狠桃花综合| 成人性色生活片| 国产精品综合一区二区三区| 午夜精品aaa| 亚洲一区二区在线免费观看视频 | 精品国产凹凸成av人导航| 欧美揉bbbbb揉bbbbb| 91麻豆免费视频| 国产99久久精品| 国产盗摄精品一区二区三区在线| 久久精品99国产精品日本| 偷拍亚洲欧洲综合| 一区二区三区四区乱视频| 亚洲美女淫视频| 亚洲男女毛片无遮挡| 国产精品视频免费看| 中文字幕成人在线观看| 日本一区二区三区高清不卡| 国产天堂亚洲国产碰碰| 久久婷婷成人综合色| 久久亚洲影视婷婷| 久久久久国产精品厨房| 久久久久久久久久久久久女国产乱| 日韩免费一区二区三区在线播放| 欧美在线播放高清精品| 在线一区二区三区| 欧美日韩在线三区| 欧美日韩精品高清| 日韩亚洲欧美成人一区| 日韩情涩欧美日韩视频| 精品88久久久久88久久久| 久久久亚洲高清| 国产精品欧美一级免费| 中文字幕日韩精品一区| 亚洲夂夂婷婷色拍ww47 | 5858s免费视频成人| 欧美一二三在线| xnxx国产精品| 亚洲欧洲精品成人久久奇米网| 亚洲免费三区一区二区| 亚洲一区二区欧美日韩| 日韩影院在线观看| 国产伦精品一区二区三区免费| 国产精品1区2区3区| www.欧美日韩国产在线| 色94色欧美sute亚洲13| 欧美一级片在线看| 久久久精品tv| 亚洲影视资源网| 免费人成在线不卡| 成人黄色电影在线| 欧美日韩卡一卡二| 久久久久国产精品人| 亚洲精品菠萝久久久久久久| 秋霞午夜av一区二区三区 | 日本中文字幕不卡| 国产成人免费视频网站 | 色婷婷久久久综合中文字幕| 欧美日本韩国一区| 国产午夜精品久久久久久久| 亚洲乱码中文字幕| 国产一区亚洲一区| 欧美色视频在线观看| 亚洲精品一区二区三区99| 亚洲激情六月丁香| 激情综合色丁香一区二区| 色婷婷精品大在线视频| 精品国产麻豆免费人成网站| 最新久久zyz资源站| 天天色综合成人网| 色婷婷综合五月| 国产农村妇女精品| 日本欧美大码aⅴ在线播放| 成人a区在线观看| 精品欧美乱码久久久久久1区2区| 亚洲视频在线观看三级| 国产一区二区精品久久91| 欧美色倩网站大全免费| 国产精品人成在线观看免费| 久久精品99久久久| 欧美精品日韩一区| 亚洲色图视频网| 国产99久久久精品| 精品毛片乱码1区2区3区| 亚洲国产精品一区二区www| 粉嫩绯色av一区二区在线观看| 欧美一区二区黄| 亚洲午夜免费福利视频| 91视频观看免费| 国产精品久久久久影院色老大| 精品午夜久久福利影院| 欧美精品1区2区| 亚洲国产成人av好男人在线观看| 9色porny自拍视频一区二区| 久久精品视频网| 国产一区二区三区在线观看精品| 欧美一区二区三区在线| 视频一区欧美日韩| 欧美日韩国产一二三| 亚洲国产精品尤物yw在线观看| 99久久精品国产精品久久| 国产欧美精品一区aⅴ影院| 国产九色sp调教91| 久久久久久久久一| 国产成人在线视频播放| 久久久久成人黄色影片| 国产盗摄精品一区二区三区在线| 精品国精品自拍自在线| 国产精品综合在线视频| 国产欧美在线观看一区| 成人亚洲一区二区一|