[Lemon-commits] alpar: r3189 - hugo/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Tue Feb 20 14:01:23 CET 2007
Author: alpar
Date: Tue Feb 20 14:01:22 2007
New Revision: 3189
Modified:
hugo/trunk/lemon/random.h
Log:
Some two dimensional random distribution added.
They should be revised.
Modified: hugo/trunk/lemon/random.h
==============================================================================
--- hugo/trunk/lemon/random.h (original)
+++ hugo/trunk/lemon/random.h Tue Feb 20 14:01:22 2007
@@ -69,6 +69,7 @@
#include <ctime>
#include <cmath>
+#include <lemon/dim2.h>
///\ingroup misc
///\file
///\brief Mersenne Twister random number generator
@@ -742,11 +743,66 @@
///
double exponential(double lambda=1.0)
{
- return -log(real<double>())/lambda;
+ return -std::log(real<double>())/lambda;
}
///@}
+ ///\name Two dimensional distributions
+ ///
+
+ ///@{
+
+ /// Uniform distribution on the full unit circle.
+ dim2::Point<double> ball2()
+ {
+ double V1,V2;
+ do {
+ V1=2*real<double>()-1;
+ V2=2*real<double>()-1;
+
+ } while(V1*V1+V2*V2>=1);
+ return dim2::Point<double>(V1,V2);
+ }
+ /// A kind of two dimensional Gauss distribution
+
+ /// This function provides a turning symmetric two-dimensional distribution.
+ /// Both coordinates are of standard normal distribution, but they are not
+ /// independent.
+ ///
+ /// \note The coordinates are the two random variables provided by
+ /// the Box-Muller method.
+ dim2::Point<double> gauss2()
+ {
+ double V1,V2,S;
+ do {
+ V1=2*real<double>()-1;
+ V2=2*real<double>()-1;
+ S=V1*V1+V2*V2;
+ } while(S>=1);
+ double W=std::sqrt(-2*std::log(S)/S);
+ return dim2::Point<double>(W*V1,W*V2);
+ }
+ /// A kind of two dimensional exponential distribution
+
+ /// This function provides a turning symmetric two-dimensional distribution.
+ /// The x-coordinate is of conditionally exponential distribution
+ /// with the condition that x is positive and y=0. If x is negative and
+ /// y=0 then, -x is of exponential distribution. The same is true for the
+ /// y-coordinate.
+ dim2::Point<double> exponential2()
+ {
+ double V1,V2,S;
+ do {
+ V1=2*real<double>()-1;
+ V2=2*real<double>()-1;
+ S=V1*V1+V2*V2;
+ } while(S>=1);
+ double W=-std::log(S)/S;
+ return dim2::Point<double>(W*V1,W*V2);
+ }
+
+ ///@}
};
More information about the Lemon-commits
mailing list