|
SNAP Library 2.1, User Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <dt.h>
Public Member Functions | |
| TRnd (const int &_Seed=1, const int &Steps=0) | |
| TRnd (TSIn &SIn) | |
| void | Save (TSOut &SOut) const |
| void | LoadXml (const PXmlTok &XmlTok, const TStr &Nm) |
| void | SaveXml (TSOut &SOut, const TStr &Nm) const |
| TRnd & | operator= (const TRnd &Rnd) |
| bool | operator== (const TRnd &) const |
| double | GetUniDev () |
| int | GetUniDevInt (const int &Range=0) |
| int | GetUniDevInt (const int &MnVal, const int &MxVal) |
| uint | GetUniDevUInt (const uint &Range=0) |
| int64 | GetUniDevInt64 (const int64 &Range=0) |
| uint64 | GetUniDevUInt64 (const uint64 &Range=0) |
| double | GetNrmDev () |
| double | GetNrmDev (const double &Mean, const double &SDev, const double &Mn, const double &Mx) |
| double | GetExpDev () |
| double | GetExpDev (const double &Lambda) |
| double | GetGammaDev (const int &Order) |
| double | GetPoissonDev (const double &Mean) |
| double | GetBinomialDev (const double &Prb, const int &Trials) |
| int | GetGeoDev (const double &Prb) |
| double | GetPowerDev (const double &AlphaSlope) |
| double | GetRayleigh (const double &Sigma) |
| double | GetWeibull (const double &K, const double &Lambda) |
| void | PutSeed (const int &_Seed) |
| int | GetSeed () const |
| void | Randomize () |
| void | Move (const int &Steps) |
| bool | Check () |
| void | SaveTxt (TOLx &Lx) const |
Static Public Member Functions | |
| static double | GetUniDevStep (const int &Seed, const int &Steps) |
| static double | GetNrmDevStep (const int &Seed, const int &Steps) |
| static double | GetExpDevStep (const int &Seed, const int &Steps) |
| static TRnd | LoadTxt (TILx &Lx) |
Static Public Attributes | |
| static const int | RndSeed = 0 |
Private Member Functions | |
| int | GetNextSeed () |
Private Attributes | |
| int | Seed |
Static Private Attributes | |
| static const int | a = 16807 |
| static const int | m = 2147483647 |
| static const int | q = 127773 |
| static const int | r = 2836 |
| TRnd::TRnd | ( | const int & | _Seed = 1, |
| const int & | Steps = 0 |
||
| ) | [inline] |
| bool TRnd::Check | ( | ) |
| double TRnd::GetBinomialDev | ( | const double & | Prb, |
| const int & | Trials | ||
| ) |
Definition at line 154 of file dt.cpp.
{
int j;
static int nold=(-1);
double am,em,g,angle,p,bnl,sq,t,y;
static double pold=(-1.0),pc,plog,pclog,en,oldg;
p=(Prb <= 0.5 ? Prb : 1.0-Prb);
am=Trials*p;
if (Trials < 25) {
bnl=0.0;
for (j=1;j<=Trials;j++)
if (GetUniDev() < p) ++bnl;
} else if (am < 1.0) {
g=exp(-am);
t=1.0;
for (j=0;j<=Trials;j++) {
t *= GetUniDev();
if (t < g) break;
}
bnl=(j <= Trials ? j : Trials);
} else {
if (Trials != nold) {
en=Trials;
oldg=TSpecFunc::LnGamma(en+1.0);
nold=Trials;
} if (p != pold) {
pc=1.0-p;
plog=log(p);
pclog=log(pc);
pold=p;
}
sq=sqrt(2.0*am*pc);
do {
do {
angle=TMath::Pi*GetUniDev();
y=tan(angle);
em=sq*y+am;
} while (em < 0.0 || em >= (en+1.0));
em=floor(em);
t=1.2*sq*(1.0+y*y)*exp(oldg-(em+1.0)
-TSpecFunc::LnGamma(en-em+1.0)+em*plog+(en-em)*pclog);
} while (GetUniDev() > t);
bnl=em;
}
if (p != Prb) bnl=Trials-bnl;
return bnl;
}
| double TRnd::GetExpDev | ( | ) |
| double TRnd::GetExpDev | ( | const double & | Lambda | ) |
| static double TRnd::GetExpDevStep | ( | const int & | Seed, |
| const int & | Steps | ||
| ) | [inline, static] |
| double TRnd::GetGammaDev | ( | const int & | Order | ) |
Definition at line 95 of file dt.cpp.
{
int j;
double am,e,s,v1,v2,x,y;
if (Order<1){Fail;}
if (Order<6) {
x=1.0;
for (j=1;j<=Order;j++) x *=GetUniDev();
x = -log(x);
} else {
do {
do {
do {
v1=2.0*GetUniDev()-1.0;
v2=2.0*GetUniDev()-1.0;
} while (v1*v1+v2*v2 > 1.0);
y=v2/v1;
am=Order-1;
s=sqrt(2.0*am+1.0);
x=s*y+am;
} while (x <= 0.0);
e=(1.0+y*y)*exp(am*log(x/am)-s*y);
} while (GetUniDev()>e);
}
return x;
}
| int TRnd::GetGeoDev | ( | const double & | Prb | ) | [inline] |
| int TRnd::GetNextSeed | ( | ) | [inline, private] |
| double TRnd::GetNrmDev | ( | ) |
Definition at line 63 of file dt.cpp.
{
double v1, v2, rsq;
do {
v1=2.0*GetUniDev()-1.0; // pick two uniform numbers in the square
v2=2.0*GetUniDev()-1.0; // extending from -1 to +1 in each direction
rsq=v1*v1+v2*v2; // see if they are in the unit cicrcle
} while ((rsq>=1.0)||(rsq==0.0)); // and if they are not, try again
double fac=sqrt(-2.0*log(rsq)/rsq); // Box-Muller transformation
return v1*fac;
// return v2*fac; // second deviate
}
| double TRnd::GetNrmDev | ( | const double & | Mean, |
| const double & | SDev, | ||
| const double & | Mn, | ||
| const double & | Mx | ||
| ) |
| static double TRnd::GetNrmDevStep | ( | const int & | Seed, |
| const int & | Steps | ||
| ) | [inline, static] |
| double TRnd::GetPoissonDev | ( | const double & | Mean | ) |
Definition at line 121 of file dt.cpp.
{
static double sq,alxm,g,oldm=(-1.0);
double em,t,y;
if (Mean < 12.0) {
if (Mean != oldm) {
oldm=Mean;
g=exp(-Mean);
}
em = -1;
t=1.0;
do {
++em;
t *= GetUniDev();
} while (t>g);
} else {
if (Mean != oldm) {
oldm=Mean;
sq=sqrt(2.0*Mean);
alxm=log(Mean);
g=Mean*alxm-TSpecFunc::LnGamma(Mean+1.0);
}
do {
do {
y=tan(TMath::Pi*GetUniDev());
em=sq*y+Mean;
} while (em < 0.0);
em=floor(em);
t=0.9*(1.0+y*y)*exp(em*alxm-TSpecFunc::LnGamma(em+1.0)-g);
} while (GetUniDev()>t);
}
return em;
}
| double TRnd::GetPowerDev | ( | const double & | AlphaSlope | ) | [inline] |
| double TRnd::GetRayleigh | ( | const double & | Sigma | ) | [inline] |
| int TRnd::GetSeed | ( | ) | const [inline] |
| double TRnd::GetUniDev | ( | ) | [inline] |
Definition at line 30 of file dt.h.
{return GetNextSeed()/double(m);}
| int TRnd::GetUniDevInt | ( | const int & | Range = 0 | ) |
Definition at line 39 of file dt.cpp.
{
int Seed=GetNextSeed();
if (Range==0){return Seed;}
else {return Seed%Range;}
}
| int TRnd::GetUniDevInt | ( | const int & | MnVal, |
| const int & | MxVal | ||
| ) | [inline] |
Definition at line 32 of file dt.h.
{
IAssert(MnVal<=MxVal); return MnVal+GetUniDevInt(MxVal-MnVal+1);}
| int64 TRnd::GetUniDevInt64 | ( | const int64 & | Range = 0 | ) |
Definition at line 51 of file dt.cpp.
{
const int64 RndVal = int64((uint64(GetUniDevInt())<<32) | uint64(GetUniDevInt()));
if (Range==0){return RndVal;}
else {return RndVal%Range;}
}
| static double TRnd::GetUniDevStep | ( | const int & | Seed, |
| const int & | Steps | ||
| ) | [inline, static] |
| uint TRnd::GetUniDevUInt | ( | const uint & | Range = 0 | ) |
Definition at line 45 of file dt.cpp.
{
uint Seed=uint(GetNextSeed()%0x10000)*0x10000+uint(GetNextSeed()%0x10000);
if (Range==0){return Seed;}
else {return Seed%Range;}
}
| uint64 TRnd::GetUniDevUInt64 | ( | const uint64 & | Range = 0 | ) |
Definition at line 57 of file dt.cpp.
{
const uint64 RndVal = uint64((uint64(GetUniDevInt())<<32) | uint64(GetUniDevInt()));
if (Range==0){return RndVal;}
else {return RndVal%Range;}
}
| double TRnd::GetWeibull | ( | const double & | K, |
| const double & | Lambda | ||
| ) | [inline] |
| TRnd TRnd::LoadTxt | ( | TILx & | Lx | ) | [static] |
| void TRnd::LoadXml | ( | const PXmlTok & | XmlTok, |
| const TStr & | Nm | ||
| ) |
Definition at line 9 of file dt.cpp.
{
XLoadHd(Nm);
Seed=TXmlObjSer::GetIntArg(XmlTok, "Seed");
}
| void TRnd::Move | ( | const int & | Steps | ) |
Definition at line 29 of file dt.cpp.
{
for (int StepN=0; StepN<Steps; StepN++){GetNextSeed();}
}
| bool TRnd::operator== | ( | const TRnd & | ) | const [inline] |
| void TRnd::PutSeed | ( | const int & | _Seed | ) |
| void TRnd::Randomize | ( | ) | [inline] |
| void TRnd::Save | ( | TSOut & | SOut | ) | const [inline] |
| void TRnd::SaveXml | ( | TSOut & | SOut, |
| const TStr & | Nm | ||
| ) | const |
Definition at line 14 of file dt.cpp.
{
XSaveBETagArg(Nm, "Seed", TInt::GetStr(Seed));
}
const int TRnd::RndSeed = 0 [static] |
int TRnd::Seed [private] |