casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Random.h
Go to the documentation of this file.
1 //# Random.h: Random number classes
2 //# Copyright (C) 1992,1993,1994,1995,1999,2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASA_RANDOM_H
29 #define CASA_RANDOM_H
30 
31 #include <casacore/casa/aips.h>
33 namespace casacore { //# NAMESPACE CASACORE - BEGIN
34 
35 class String;
36 template<class T> class Vector;
37 
38 // <summary>Base class for random number generators</summary>
39 //
40 // <use visibility=export>
41 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
42 // </reviewed>
43 //
44 // <prerequisite>
45 // <li> A knowledge of C++, in particular inheritance
46 // <li> College level mathematics
47 // </prerequisite>
48 //
49 // <etymology>
50 // RNG stands for "Random Number Generator"
51 // </etymology>
52 //
53 // <synopsis>
54 // <h4>General Structure of the Classes</h4>
55 //
56 
57 // The two base classes <linkto class=RNG>RNG</linkto> and
58 // <linkto class=Random>Random</linkto> are used together to generate a variety
59 // of random number distributions. A distinction must be made between
60 // <em>random number generators</em>, implemented by class derived from
61 // <src>RNG</src>, and <em>random number distributions</em>. A random number
62 // generator produces a series of randomly ordered bits. These bits can be
63 // used directly, or cast to another representation, such as a floating point
64 // value. A random number generator should produce a <em>uniform</em>
65 // distribution. A random number distribution, on the other hand, uses the
66 // randomly generated bits of a generator to produce numbers from a
67 // distribution with specific properties. Each instance of <src>Random</src>
68 // uses an instance of class <src>RNG</src> to provide the raw, uniform
69 // distribution used to produce the specific distribution. Several instances
70 // of <src>Random</src> classes can share the same instance of <src>RNG</src>,
71 // or each instance can use its own copy.
72 
73 // <h4> RNG </h4>
74 //
75 
76 // Random distributions are constructed from classes derived from
77 // <src>RNG</src>, the actual random number generators. The <src>RNG</src>
78 // class contains no data; it only serves to define the interface to random
79 // number generators. The <src>RNG::asuInt</src> member returns a 32-bit
80 // unsigned integer of random bits. Applications that require a number of
81 // random bits can use this directly. More often, these random bits are
82 // transformed to a uniformly distributed floating point number using either
83 // <src>asFloat</src> or <src>asDouble</src>. These functions return differing
84 // precisions and the <src>asDouble</src> function will use two different
85 // random 32-bit integers to get a legal <src>double</src>, while
86 // <src>asFloat</src> will use a single integer. These members are used by
87 // classes derived fro the <src>Random</src> base class to implement a variety
88 // of random number distributions.
89 //
90 // Currently, the following subclasses are provided:
91 // <ul>
92 // <li> <linkto class=MLCG>MLCG</linkto>:
93 // Multiplicative Linear Congruential Generator.
94 // A reasonable generator for most purposes.
95 // <li> <linkto class=ACG>ACG</linkto>: Additive Number Generator.
96 // A high quality generator that uses more memory and computation time.
97 // </ul>
98 //
99 // <note role=warning> This class assumes that IEEE floating point
100 // representation is used for the floating point numbers and that the integer
101 // and unsigned integer type is exactly 32 bits long.
102 // </note>
103 // </synopsis>
104 //
105 // <example>
106 // </example>
107 //
108 // <motivation>
109 // Random numbers are used everywhere, particularly in simulations.
110 // </motivation>
111 //
112 // <thrown>
113 // <li> AipsError: If a programming error or unexpected numeric size is
114 // detected. Should not occur in normal usage.
115 // </thrown>
116 //
117 // <todo asof="2000/05/09">
118 // <li> Nothing I hope!
119 // </todo>
120 
121 class RNG {
122 public:
123  // A virtual destructor is needed to ensure that the destructor of derived
124  // classes gets used.
125  virtual ~RNG();
126 
127  // Resets the random number generator. After calling this function the random
128  // numbers generated will be the same as if the object had just been
129  // constructed.
130  virtual void reset() = 0;
131 
132  // Return the 32-random bits as an unsigned integer
133  virtual uInt asuInt() = 0;
134 
135  // Return random bits converted to either a Float or a Double. The returned
136  // value x is in the range 1.0 > x >= 0.0
137  // <group>
138  Float asFloat();
139  Double asDouble();
140  // </group>
141 };
142 
143 // <summary>Additive number generator</summary>
144 //
145 // <use visibility=export>
146 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
147 // </reviewed>
148 //
149 // <prerequisite>
150 // <li> A knowledge of C++, in particular inheritance
151 // <li> College level mathematics
152 // </prerequisite>
153 //
154 // <etymology>
155 // ACG stands for "Additive Congruential Generator"
156 // </etymology>
157 //
158 // <synopsis>
159 // This class implements the additive number generator as presented in Volume
160 // II of The Art of Computer Programming by Knuth. I have coded the algorithm
161 // and have added the extensions by Andres Nowatzyk of CMU to randomize the
162 // result of algorithm M a bit by using an LCG & a spatial permutation table.
163 //
164 // The version presented uses the same constants for the LCG that Andres uses
165 // (chosen by trial & error). The spatial permutation table is the same size
166 // (it is based on word size). This is for 32-bit words.
167 //
168 // The <src>auxillary table</src> used by the LCG table varies in size, and is
169 // chosen to be the the smallest power of two which is larger than twice the
170 // size of the state table.
171 //
172 // Class <src>ACG</src> is a variant of a Linear Congruential Generator
173 // (Algorithm M) described in Knuth, "Art of Computer Programming, Vol III".
174 // This result is permuted with a Fibonacci Additive Congruential Generator to
175 // get good independence between samples. This is a very high quality random
176 // number generator, although it requires a fair amount of memory for each
177 // instance of the generator.
178 //
179 // The constructor takes two parameters: the seed and the size. The seed can
180 // be any number. The performance of the generator depends on having a
181 // distribution of bits through the seed. If you choose a number in the range
182 // of 0 to 31, a seed with more bits is chosen. Other values are
183 // deterministically modified to give a better distribution of bits. This
184 // provides a good random number generator while still allowing a sequence to
185 // be repeated given the same initial seed.
186 //
187 // The <src>size</src> parameter determines the size of two tables used in the
188 // generator. The first table is used in the Additive Generator; see the
189 // algorithm in Knuth for more information. In general, this table contains
190 // <src>size</src> integers. The default value, used in the algorithm in Knuth,
191 // gives a table of 55 integers (220 bytes). The table size affects the period
192 // of the generators; smaller values give shorter periods and larger tables
193 // give longer periods. The smallest table size is 7 integers, and the longest
194 // is 98. The <src>size</src> parameter also determines the size of the table
195 // used for the Linear Congruential Generator. This value is chosen implicitly
196 // based on the size of the Additive Congruential Generator table. It is two
197 // powers of two larger than the power of two that is larger than
198 // <src>size</src>. For example, if <src>size</src> is 7, the ACG table
199 // contains 7 integers and the LCG table contains 128 integers. Thus, the
200 // default size (55) requires 55 + 256 integers, or 1244 bytes. The largest
201 // table requires 2440 bytes and the smallest table requires 100 bytes.
202 // Applications that require a large number of generators or applications that
203 // are not so fussy about the quality of the generator may elect to use the
204 // <src>MLCG</src> generator.
205 //
206 // <note role=warning> This class assumes that the integer and unsigned integer
207 // type is exactly 32 bits long.
208 // </note>
209 // </synopsis>
210 //
211 // <example>
212 // </example>
213 //
214 // <thrown>
215 // <li> AipsError: If a programming error or unexpected numeric size is
216 // detected. Should not occur in normal usage.
217 // </thrown>
218 //
219 // <todo asof="2000/05/09">
220 // <li> Nothing I hope!
221 // </todo>
222 
223 class ACG : public RNG {
224 
225 public:
226  // The constructor allows you to specify seeds. The seed should be a big
227  // random number and size must be between 7 and 98. See the synopsis for more
228  // details.
229  explicit ACG(uInt seed = 0, Int size = 55);
230 
231  // The destructor cleans up memory allocated by this class
232  virtual ~ACG();
233 
234  // Resets the random number generator. After calling this function the random
235  // numbers generated will be the same as if the object had just been
236  // constructed.
237  virtual void reset();
238 
239  // Return the 32-random bits as an unsigned integer
240  virtual uInt asuInt();
241 
242 private:
243  uInt itsInitSeed; //# used to reset the generator
245 
253 };
254 
255 // <summary> Multiplicative linear congruential generator </summary>
256 
257 // <use visibility=export>
258 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
259 // </reviewed>
260 //
261 // <prerequisite>
262 // <li> A knowledge of C++, in particular inheritance
263 // <li> College level mathematics
264 // </prerequisite>
265 //
266 // <etymology>
267 // MLCG stands for "Multiplicative Linear Congruential Generator"
268 // </etymology>
269 //
270 
271 // <synopsis>
272 // The <src>MLCG</src> class implements a <em>Multiplicative Linear
273 // Congruential Generator</em>. In particular, it is an implementation of the
274 // double MLCG described in <em>Efficient and Portable Combined Random Number
275 // Generators</em> by Pierre L'Ecuyer, appearing in <em>Communications of the
276 // ACM, Vol. 31. No. 6</em>. This generator has a fairly long period, and has
277 // been statistically analyzed to show that it gives good inter-sample
278 // independence.
279 //
280 
281 // The constructor has two parameters, both of which are seeds for the
282 // generator. As in the <src>ACG</src> generator, both seeds are modified to
283 // give a "better" distribution of seed digits. Thus, you can safely use values
284 // such as <src>0</src> or <src>1</src> for the seeds. The <src>MLCG</src>
285 // generator used much less state than the <src>ACG</src> generator; only two
286 // integers (8 bytes) are needed for each generator.
287 
288 // <note role=warning> This class assumes that the integer and unsigned integer
289 // type is exactly 32 bits long.
290 // </note>
291 // </synopsis>
292 
293 // <example>
294 // </example>
295 //
296 // <thrown>
297 // <li> AipsError: If a programming error or unexpected numeric size is
298 // detected. Should not occur in normal usage.
299 // </thrown>
300 //
301 // <todo asof="2000/05/09">
302 // <li> Nothing I hope!
303 // </todo>
304 
305 class MLCG : public RNG {
306 public:
307  // The constructor allows you to specify seeds.
308  explicit MLCG(Int seed1 = 0, Int seed2 = 1);
309 
310  // The destructor is trivial
311  virtual ~MLCG();
312 
313  // Return the 32-random bits as an unsigned integer
314  virtual uInt asuInt();
315 
316  // Resets the random number generator. After calling this function the random
317  // numbers generated will be the same as if the object had just been
318  // constructed.
319  virtual void reset();
320 
321  // Functions that allow the user to retrieve or change the seed integers. The
322  // seeds returned are not the user supplied values but the values obtained
323  // after some deterministic modification to produce a more uniform bit
324  // distribution.
325  // <group>
326  Int seed1() const;
327  void seed1(Int s);
328  Int seed2() const;
329  void seed2(Int s);
330  void reseed(Int s1, Int s2);
331  // </group>
332 
333 private:
338 };
339 
340 inline Int MLCG::seed1() const
341 {
342  return itsSeedOne;
343 }
344 
345 inline void MLCG::seed1(Int s)
346 {
347  itsInitSeedOne = s;
348  reset();
349 }
350 
351 inline Int MLCG::seed2() const
352 {
353  return itsSeedTwo;
354 }
355 
356 inline void MLCG::seed2(Int s)
357 {
358  itsInitSeedTwo = s;
359  reset();
360 }
361 
362 inline void MLCG::reseed(Int s1, Int s2)
363 {
364  itsInitSeedOne = s1;
365  itsInitSeedTwo = s2;
366  reset();
367 }
368 
369 // <summary>Base class for random number distributions</summary>
370 
371 // <use visibility=export>
372 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
373 // </reviewed>
374 //
375 // <prerequisite>
376 // <li> A knowledge of C++, in particular inheritance
377 // <li> College level mathematics
378 // </prerequisite>
379 //
380 // <synopsis>
381 // A random number generator may be declared by first constructing a
382 // <src>RNG</src> object and then a <src>Random</src>. For example,
383 // <srcblock>
384 // ACG gen(10, 20);
385 // NegativeExpntl rnd (1.0, &gen);
386 // </srcblock>
387 // declares an additive congruential generator with seed 10 and table size 20,
388 // that is used to generate exponentially distributed values with mean of 1.0.
389 //
390 // The virtual member <src>Random::operator()</src> is the common way of
391 // extracting a random number from a particular distribution. The base class,
392 // <src>Random</src> does not implement <src>operator()</src>. This is
393 // performed by each of the derived classes. Thus, given the above declaration
394 // of <src>rnd</src>, new random values may be obtained via, for example,
395 // <src>Double nextExpRand = rnd();</src>
396 //
397 // Currently, the following subclasses are provided:
398 //
399 // <ul>
400 // <li> <linkto class=Binomial>Binomial</linkto>
401 // <li> <linkto class=Erlang>Erlang</linkto>
402 // <li> <linkto class=Geometric>Geometric</linkto>
403 // <li> <linkto class=HyperGeometric>HyperGeometric</linkto>
404 // <li> <linkto class=NegativeExpntl>NegativeExpntl</linkto>
405 // <li> <linkto class=Normal>Normal</linkto>
406 // <li> <linkto class=LogNormal>LogNormal</linkto>
407 // <li> <linkto class=Poisson>Poisson</linkto>
408 // <li> <linkto class=DiscreteUniform>DiscreteUniform</linkto>
409 // <li> <linkto class=Uniform>Uniform</linkto>
410 // <li> <linkto class=Weibull>Weibull</linkto>
411 // </ul>
412 // </synopsis>
413 //
414 // <example>
415 // </example>
416 //
417 // <thrown>
418 // <li> No exceptions are thrown directly from this class.
419 // </thrown>
420 //
421 // <todo asof="2000/05/09">
422 // <li> Nothing I hope!
423 // </todo>
424 
425 class Random {
426 public:
427 
428  // This enumerator lists all the predefined random number distributions.
429  enum Types {
430  // 2 parameters. The binomial distribution models successfully drawing
431  // items from a pool. Specify n and p. n is the number of items in the
432  // pool, and p, is the probability of each item being successfully drawn.
433  // It is required that n > 0 and 0 <= p <= 1
435 
436  // 2 parameters. Model a uniform random variable over the closed
437  // interval. Specify the values low and high. The low parameter is the
438  // lowest possible return value and the high parameter is the highest. It
439  // is required that low < high.
441 
442  // 2 parameters, mean and variance. It is required that the mean is
443  // non-zero and the variance is positive.
445 
446  // 1 parameters, the mean. It is required that 0 <= probability < 1
448 
449  // 2 parameters, mean and variance. It is required that the variance is
450  // positive and that the mean is non-zero and not bigger than the
451  // square-root of the variance.
453 
454  // 2 parameters, the mean and variance. It is required that the variance is
455  // positive.
457 
458  // 2 parameters, mean and variance. It is required that the supplied
459  // variance is positive and that the mean is non-zero
461 
462  // 1 parameter, the mean.
464 
465  // 1 parameter, the mean. It is required that the mean is non-negative
467 
468  // 2 parameters, low and high. Model a uniform random variable over the
469  // closed interval. The low parameter is the lowest possible return value
470  // and the high parameter can never be returned. It is required that low <
471  // high.
473 
474  // 2 parameters, alpha and beta. It is required that the alpha parameter is
475  // not zero.
477 
478  // An non-predefined random number distribution
480 
481  // Number of distributions
483 
484  // A virtual destructor is needed to ensure that the destructor of derived
485  // classes gets used. Not that this destructor does NOT delete the pointer to
486  // the RNG object
487  virtual ~Random();
488 
489  // This function returns a random number from the appropriate distribution.
490  virtual Double operator()() = 0;
491 
492  // Functions that allow you to access and change the class that generates the
493  // random bits.
494  // <group>
495  RNG* generator();
496  void generator(RNG* p);
497  // </group>
498 
499  // Convert the enumerator to a lower-case string.
501 
502  // Convert the string to enumerator. The parsing of the string is case
503  // insensitive. Returns the Random::UNKNOWN value if the string does not
504  // cotrtrespond to any of the enumerators.
505  static Random::Types asType(const String& str);
506 
507  // Convert the Random::Type enumerator to a specific object (derived from
508  // Random but upcast to a Random object). Returns a null pointer if the
509  // object could not be constructed. This will occur is the enumerator is
510  // UNKNOWN or NUMBER_TYPES or there is insufficient memory. The caller of
511  // this function is responsible for deleting the pointer.
512  static Random* construct(Random::Types type, RNG* gen);
513 
514  // These function allow you to manipulate the parameters (mean variance etc.)
515  // of random number distribution. The parameters() function returns the
516  // current value, the setParameters function allows you to change the
517  // parameters and the checkParameters function will return False if the
518  // supplied parameters are not appropriate for the distribution.
519  // <group>
520  virtual void setParameters(const Vector<Double>& parms) = 0;
521  virtual Vector<Double> parameters() const = 0;
522  virtual Bool checkParameters(const Vector<Double>& parms) const = 0;
523  // </group>
524 
525  // returns the default parameters for the specified distribution. Returns an
526  // empty Vector if a non-predifined distribution is used.
528 
529 protected:
530  //# This class contains pure virtual functions hence the constructor can only
531  //# sensibly be used by derived classes.
532  Random(RNG* generator);
533 
534  //# The RNG class provides the random bits.
536 };
537 
538 inline Random::Random(RNG* gen)
539 {
540  itsRNG = gen;
541 }
542 
544 {
545  return itsRNG;
546 }
547 
548 inline void Random::generator(RNG* p)
549 {
550  itsRNG = p;
551 }
552 
553 
554 // <summary> Binomial distribution </summary>
555 
556 // <synopsis>
557 // The binomial distribution models successfully drawing items from a pool.
558 // <src>n</src> is the number of items in the pool, and <src>p</src>, is the
559 // probability of each item being successfully drawn. The
560 // <src>operator()</src> functions returns an integral value indicating the
561 // number of items actually drawn from the pool. It is possible to get this
562 // same value as an integer using the asInt function.
563 
564 // It is assumed that <src>n > 0</src> and <src>0 <= p <= 1</src> an AipsError
565 // exception thrown if it is not true. The remaining members allow you to read
566 // and set the parameters.
567 // </synopsis>
568 
569 // <example>
570 // </example>
571 //
572 // <thrown>
573 // <li> AipsError: if bad values for the arguments are given, as specified
574 // above.
575 // </thrown>
576 //
577 // <todo asof="2000/05/09">
578 // <li> Nothing I hope!
579 // </todo>
580 
581 class Binomial: public Random {
582 public:
583  // Construct a random number generator for a binomial distribution. The first
584  // argument is a class that produces random bits. This pointer is NOT taken
585  // over by this class and the user is responsible for deleting it. The second
586  // and third arguments are the parameters are the Binomial distribution as
587  // described in the synopsis.
588  Binomial(RNG* gen, uInt n=1, Double p=0.5);
589 
590  // The destructor is trivial
591  virtual ~Binomial();
592 
593  // Returns a value from the Binomial distribution. The returned value is a
594  // non-negative integer and using the asInt function bypasses the conversion
595  // to a floating point number.
596  // <group>
597  virtual Double operator()();
598  uInt asInt();
599  // </group>
600 
601  // Functions that allow you to query and change the parameters of the
602  // binomial distribution.
603  // <group>
604  uInt n() const;
605  void n(uInt newN);
606  void n(Double newN);
607  Double p() const;
608  void p(Double newP);
609  // </group>
610 
611  // These function allow you to manipulate the parameters (n & p) described
612  // above through the base class. The Vectors must always be of length two.
613  // <group>
614  virtual void setParameters(const Vector<Double>& parms);
615  virtual Vector<Double> parameters() const;
616  virtual Bool checkParameters(const Vector<Double>& parms) const;
617  // </group>
618 
619 private:
622 };
623 
624 inline uInt Binomial::n() const {
625  return itsN;
626 }
627 
628 inline Double Binomial::p() const {
629  return itsP;
630 }
631 
632 // <summary>Discrete uniform distribution</summary>
633 
634 // <synopsis>
635 
636 // The <src>DiscreteUniform</src> class implements a quantized uniform random
637 // variable over the closed interval ranging from <src>[low..high]</src>. The
638 // <src>low</src> parameter is the lowest possible return value and the
639 // <src>high</src> parameter is the highest. The <src>operator()</src>
640 // functions returns a value from this distribution. It is possible to get this
641 // same value as an integer using the asInt function.
642 
643 // It is assumed that low limit is less than the high limit and an AipsError
644 // exception thrown if this is not true. The remaining members allow you to
645 // read and set the parameters.
646 
647 // </synopsis>
648 
649 // <example>
650 // </example>
651 //
652 // <thrown>
653 // <li> AipsError: if bad values for the arguments are given, as specified
654 // above.
655 // </thrown>
656 //
657 // <todo asof="2000/05/09">
658 // <li> Nothing I hope!
659 // </todo>
660 
661 class DiscreteUniform: public Random {
662 public:
663  // Construct a random number generator for a discrete uniform
664  // distribution. The first argument is a class that produces random
665  // bits. This pointer is NOT taken over by this class and the user is
666  // responsible for deleting it. The second and third arguments define the
667  // range of possible return values for this distribution as described in the
668  // synopsis.
669  DiscreteUniform(RNG* gen, Int low=-1, Int high=1);
670 
671  // The destructor is trivial
672  virtual ~DiscreteUniform();
673 
674  // Returns a value from the discrete uniform distribution. The returned
675  // value is a integer and using the asInt function bypasses the conversion to
676  // a floating point number.
677  // <group>
678  virtual Double operator()();
679  Int asInt();
680  // </group>
681 
682  // Functions that allow you to query and change the parameters of the
683  // discrete uniform distribution.
684  // <group>
685  Int low() const;
686  void low(Int x);
687  Int high() const;
688  void high(Int x);
689  void range(Int low, Int high);
690  // </group>
691 
692  // These function allow you to manipulate the parameters (low & high)
693  // described above through the base class. The Vectors must always be of
694  // length two.
695  // <group>
696  virtual void setParameters(const Vector<Double>& parms);
697  virtual Vector<Double> parameters() const;
698  virtual Bool checkParameters(const Vector<Double>& parms) const;
699  // </group>
700 
701 private:
702  static Double calcDelta(Int low, Int high);
706 };
707 
708 inline Int DiscreteUniform::low() const {
709  return itsLow;
710 }
711 
712 inline Int DiscreteUniform::high() const {
713  return itsHigh;
714 }
715 
716 // <summary>Erlang distribution</summary>
717 
718 // <synopsis>
719 // The <src>Erlang</src> class implements an Erlang distribution with mean
720 // <src>mean</src> and variance <src>variance</src>.
721 
722 // It is assumed that the mean is non-zero and the variance is positive an
723 // AipsError exception thrown if this is not true. The remaining members allow
724 // you to read and set the parameters.
725 // </synopsis>
726 
727 // <example>
728 // </example>
729 //
730 // <thrown>
731 // <li> AipsError: if bad values for the arguments are given, as specified
732 // above.
733 // </thrown>
734 //
735 // <todo asof="2000/05/09">
736 // <li> Nothing I hope!
737 // </todo>
738 
739 class Erlang: public Random {
740 public:
741  // Construct a random number generator for an Erlang distribution. The first
742  // argument is a class that produces random bits. This pointer is NOT taken
743  // over by this class and the user is responsible for deleting it. The second
744  // and third arguments define the parameters for this distribution as
745  // described in the synopsis.
746  Erlang(RNG* gen, Double mean=1.0, Double variance=1.0);
747 
748  // The destructor is trivial
749  virtual ~Erlang();
750 
751  // Returns a value from the Erlang distribution.
752  virtual Double operator()();
753 
754  // Functions that allow you to query and change the parameters of the
755  // discrete uniform distribution.
756  // <group>
757  Double mean() const;
758  void mean(Double x);
759  Double variance() const;
760  void variance(Double x);
761  // </group>
762 
763  // These function allow you to manipulate the parameters (mean & variance)
764  // described above through the base class. The Vectors must always be of
765  // length two.
766  // <group>
767  virtual void setParameters(const Vector<Double>& parms);
768  virtual Vector<Double> parameters() const;
769  virtual Bool checkParameters(const Vector<Double>& parms) const;
770  // </group>
771 
772 private:
773  void setState();
778 };
779 
781  :Random(gen),
782  itsMean(mean),
783  itsVariance(variance)
784 {
785  setState();
786 }
787 
788 inline Double Erlang::mean() const {
789  return itsMean;
790 }
791 
792 inline void Erlang::mean(Double x) {
793  itsMean = x;
794  setState();
795 }
796 
797 inline Double Erlang::variance() const {
798  return itsVariance;
799 }
800 
801 inline void Erlang::variance(Double x) {
802  itsVariance = x;
803  setState();
804 }
805 
806 // <summary> Discrete geometric distribution </summary>
807 
808 // <synopsis>
809 // The <src>Geometric</src> class implements a discrete geometric distribution.
810 // The <src>probability</src> is the only parameter. The <src>operator()</src>
811 // functions returns an non-negative integral value indicating the number of
812 // uniform random samples actually drawn before one is obtained that is larger
813 // than the given probability. To get this same value as an integer use the
814 // asInt function.
815 //
816 // It is assumed that the probability is between zero and one
817 // <src>(0 <= probability < 1)</src> and and AipsError exception thrown if this
818 // is not true. The remaining function allow you to read and set the
819 // parameters.
820 // </synopsis>
821 
822 // <example>
823 // </example>
824 //
825 // <thrown>
826 // <li> AipsError: if bad values for the arguments are given, as specified
827 // above.
828 // </thrown>
829 //
830 // <todo asof="2000/05/09">
831 // <li> Nothing I hope!
832 // </todo>
833 
834 class Geometric: public Random {
835 public:
836  // Construct a random number generator for a geometric uniform
837  // distribution. The first argument is a class that produces random
838  // bits. This pointer is NOT taken over by this class and the user is
839  // responsible for deleting it. The second argument defines the range of
840  // possible return values for this distribution as described in the synopsis.
841  Geometric(RNG* gen, Double probability=0.5);
842 
843  // The destructor is trivial
844  virtual ~Geometric();
845 
846  // Returns a value from the geometric uniform distribution. The returned
847  // value is a non-negative integer and using the asInt function bypasses the
848  // conversion to a floating point number.
849  // <group>
850  virtual Double operator()();
851  uInt asInt();
852  // </group>
853 
854  // Functions that allow you to query and change the parameters of the
855  // geometric uniform distribution.
856  // <group>
857  Double probability() const;
858  void probability(Double x);
859  // </group>
860 
861  // These function allow you to manipulate the parameter (probability)
862  // described above through the base class. The Vectors must always be of
863  // length one.
864  // <group>
865  virtual void setParameters(const Vector<Double>& parms);
866  virtual Vector<Double> parameters() const;
867  virtual Bool checkParameters(const Vector<Double>& parms) const;
868  // </group>
869 
870 private:
872 };
873 
875  return itsProbability;
876 }
877 
878 // <summary> Hypergeometric distribution </summary>
879 
880 // <synopsis>
881 // The <src>HyperGeometric</src> class implements the hypergeometric
882 // distribution. The <src>mean</src> and <src>variance</src> are the
883 // parameters of the distribution. The <src>operator()</src> functions returns
884 // a value from this distribution
885 
886 // It is assumed the variance is positive and that the mean is non-zero and not
887 // bigger than the square-root of the variance. An AipsError exception is
888 // thrown if this is not true. The remaining members allow you to read and set
889 // the parameters.
890 // </synopsis>
891 
892 // <example>
893 // </example>
894 //
895 // <thrown>
896 // <li> AipsError: if bad values for the arguments are given, as specified
897 // above.
898 // </thrown>
899 //
900 // <todo asof="2000/05/09">
901 // <li> Nothing I hope!
902 // </todo>
903 
904 class HyperGeometric: public Random {
905 public:
906  // Construct a random number generator for an hypergeometric
907  // distribution. The first argument is a class that produces random
908  // bits. This pointer is NOT taken over by this class and the user is
909  // responsible for deleting it. The second and third arguments define the
910  // parameters for this distribution as described in the synopsis.
911  HyperGeometric(RNG* gen, Double mean=0.5, Double variance=1.0);
912 
913  // The destructor is trivial
914  virtual ~HyperGeometric();
915 
916  // Returns a value from the hypergeometric distribution.
917  virtual Double operator()();
918 
919  // Functions that allow you to query and change the parameters of the
920  // hypergeometric distribution.
921  // <group>
922  Double mean() const;
923  void mean(Double x);
924  Double variance() const;
925  void variance(Double x);
926  // </group>
927 
928  // These function allow you to manipulate the parameters (mean & variance)
929  // described above through the base class. The Vectors must always be of
930  // length two.
931  // <group>
932  virtual void setParameters(const Vector<Double>& parms);
933  virtual Vector<Double> parameters() const;
934  virtual Bool checkParameters(const Vector<Double>& parms) const;
935  // </group>
936 
937 private:
938  void setState();
942 };
943 
944 
946  :Random(gen),
947  itsMean(mean),
948  itsVariance(variance)
949 {
950  setState();
951 }
952 
953 inline Double HyperGeometric::mean() const {
954  return itsMean;
955 }
956 
957 inline void HyperGeometric::mean(Double x) {
958  itsMean = x;
959  setState();
960 }
961 
963  return itsVariance;
964 }
965 
967  itsVariance = x;
968  setState();
969 }
970 
971 // <summary>Normal or Gaussian distribution </summary>
972 
973 // <synopsis>
974 // The <src>Normal</src> class implements the normal or Gaussian distribution.
975 // The <src>mean</src> and <src>variance</src> are the parameters of the
976 // distribution. The <src>operator()</src> functions returns a value from this
977 // distribution
978 
979 // It is assumed that the supplied variance is positive and an AipsError
980 // exception is thrown if this is not true. The remaining members allow you to
981 // read and set the parameters. The <src>LogNormal</src> class is derived from
982 // this one.
983 // </synopsis>
984 
985 // <example>
986 // </example>
987 //
988 // <thrown>
989 // <li> AipsError: if bad values for the arguments are given, as specified
990 // above.
991 // </thrown>
992 //
993 // <todo asof="2000/05/09">
994 // <li> Nothing I hope!
995 // </todo>
996 
997 class Normal: public Random {
998 public:
999  // Construct a random number generator for a normal distribution. The first
1000  // argument is a class that produces random bits. This pointer is NOT taken
1001  // over by this class and the user is responsible for deleting it. The second
1002  // and third arguments define the parameters for this distribution as
1003  // described in the synopsis.
1004  Normal(RNG* gen, Double mean=0.0, Double variance=1.0);
1005 
1006  // The destructor is trivial
1007  virtual ~Normal();
1008 
1009  // Returns a value from the normal distribution.
1010  virtual Double operator()();
1011 
1012  // Functions that allow you to query and change the parameters of the
1013  // normal distribution.
1014  // <group>
1015  virtual Double mean() const;
1016  virtual void mean(Double x);
1017  virtual Double variance() const;
1018  virtual void variance(Double x);
1019  // </group>
1020 
1021  // These function allow you to manipulate the parameters (mean & variance)
1022  // described above through the base class. The Vectors must always be of
1023  // length two.
1024  // <group>
1025  virtual void setParameters(const Vector<Double>& parms);
1026  virtual Vector<Double> parameters() const;
1027  virtual Bool checkParameters(const Vector<Double>& parms) const;
1028  // </group>
1029 
1030 private:
1036 };
1037 
1038 inline Double Normal::mean() const {
1039  return itsMean;
1040 }
1041 
1042 inline Double Normal::variance() const {
1043  return itsVariance;
1044 }
1045 
1046 // <summary> Logarithmic normal distribution </summary>
1047 
1048 // <synopsis>
1049 // The <src>LogNormal</src> class implements the logaraithmic normal
1050 // distribution. The <src>mean</src> and <src>variance</src> are the
1051 // parameters of the distribution. The <src>operator()</src> functions returns
1052 // a value from this distribution
1053 
1054 // It is assumed that the supplied variance is positive and an AipsError
1055 // exception is thrown if this is not true. The remaining members allow you to
1056 // read and set the parameters.
1057 // </synopsis>
1058 
1059 // <example>
1060 // </example>
1061 //
1062 // <thrown>
1063 // <li> AipsError: if bad values for the arguments are given, as specified
1064 // above.
1065 // </thrown>
1066 //
1067 // <todo asof="2000/05/09">
1068 // <li> Nothing I hope!
1069 // </todo>
1070 
1071 class LogNormal: public Normal {
1072 public:
1073  // Construct a random number generator for a log-normal distribution. The
1074  // first argument is a class that produces random bits. This pointer is NOT
1075  // taken over by this class and the user is responsible for deleting it. The
1076  // second and third arguments define the parameters for this distribution as
1077  // described in the synopsis.
1078  LogNormal(RNG* gen, Double mean=1.0, Double variance=1.0);
1079 
1080  // The destructor is trivial
1081  virtual ~LogNormal();
1082 
1083  // Returns a value from the log-normal distribution.
1084  virtual Double operator()();
1085 
1086  // Functions that allow you to query and change the parameters of the
1087  // log-normal distribution.
1088  // <group>
1089  virtual Double mean() const;
1090  virtual void mean(Double x);
1091  virtual Double variance() const;
1092  virtual void variance(Double x);
1093  // </group>
1094 
1095  // These function allow you to manipulate the parameters (mean & variance)
1096  // described above through the base class. The Vectors must always be of
1097  // length two.
1098  // <group>
1099  virtual void setParameters(const Vector<Double>& parms);
1100  virtual Vector<Double> parameters() const;
1101  virtual Bool checkParameters(const Vector<Double>& parms) const;
1102  // </group>
1103 
1104 private:
1105  void setState();
1108 };
1109 
1110 inline Double LogNormal::mean() const {
1111  return itsLogMean;
1112 }
1113 
1114 inline Double LogNormal::variance() const {
1115  return itsLogVar;
1116 }
1117 
1118 // <summary>Negative exponential distribution</summary>
1119 
1120 // <synopsis>
1121 // The <src>NegativeExpntl</src> class implements a negative exponential
1122 // distribution. The <src>mean</src> parameter, is the only parameter of this
1123 // distribution. The <src>operator()</src> functions returns a value from this
1124 // distribution. The remaining members allow you to inspect and change the
1125 // mean.
1126 // </synopsis>
1127 
1128 // <example>
1129 // </example>
1130 //
1131 // <thrown>
1132 // <li> No exceptions are thrown by this class.
1133 // </thrown>
1134 //
1135 // <todo asof="2000/05/09">
1136 // <li> Nothing I hope!
1137 // </todo>
1138 
1139 class NegativeExpntl: public Random {
1140 public:
1141  // Construct a random number generator for a negative exponential
1142  // distribution. The first argument is a class that produces random
1143  // bits. This pointer is NOT taken over by this class and the user is
1144  // responsible for deleting it. The second argument defines the parameters
1145  // for this distribution as described in the synopsis.
1146  NegativeExpntl(RNG* gen, Double mean=1.0);
1147 
1148  // The destructor is trivial
1149  virtual ~NegativeExpntl();
1150 
1151  // Returns a value from the negative exponential distribution.
1152  virtual Double operator()();
1153 
1154  // Functions that allow you to query and change the parameters of the
1155  // negative exponential distribution.
1156  // <group>
1157  Double mean() const;
1158  void mean(Double x);
1159  // </group>
1160 
1161  // These function allow you to manipulate the parameters (mean)
1162  // described above through the base class. The Vectors must always be of
1163  // length one.
1164  // <group>
1165  virtual void setParameters(const Vector<Double>& parms);
1166  virtual Vector<Double> parameters() const;
1167  virtual Bool checkParameters(const Vector<Double>& parms) const;
1168  // </group>
1169 
1170 private:
1172 };
1173 
1175  return itsMean;
1176 }
1177 
1178 // <summary> Poisson distribution </summary>
1179 // <synopsis>
1180 // The <src>Poisson</src> class implements a Poisson distribution. The
1181 // <src>mean</src> parameter, is the only parameter of this distribution. The
1182 // <src>operator()</src> functions returns a value from this distribution. The
1183 // remaining members allow you to inspect and change the mean.
1184 
1185 // It is assumed that the supplied mean is non-negative and an AipsError
1186 // exception is thrown if this is not true. The remaining members allow you to
1187 // read and set the parameters.
1188 // </synopsis>
1189 
1190 // <example>
1191 // </example>
1192 //
1193 // <thrown>
1194 // <li> No exceptions are thrown by this class.
1195 // </thrown>
1196 //
1197 // <todo asof="2000/05/09">
1198 // <li> Nothing I hope!
1199 // </todo>
1200 
1201 class Poisson: public Random {
1202 public:
1203  // Construct a random number generator for a Poisson distribution. The first
1204  // argument is a class that produces random bits. This pointer is NOT taken
1205  // over by this class and the user is responsible for deleting it. The second
1206  // argument defines the parameters for this distribution as described in the
1207  // synopsis.
1208  Poisson(RNG* gen, Double mean=0.0);
1209 
1210  // The destructor is trivial
1211  virtual ~Poisson();
1212 
1213  // Returns a value from the Poisson distribution. The returned value is a
1214  // non-negative integer and using the asInt function bypasses the conversion
1215  // to a floating point number.
1216  // <group>
1217  virtual Double operator()();
1218  uInt asInt();
1219  // </group>
1220 
1221  // Functions that allow you to query and change the parameters of the
1222  // Poisson distribution.
1223  // <group>
1224  Double mean() const;
1225  void mean(Double x);
1226  // </group>
1227 
1228  // These function allow you to manipulate the parameters (mean)
1229  // described above through the base class. The Vectors must always be of
1230  // length one.
1231  // <group>
1232  virtual void setParameters(const Vector<Double>& parms);
1233  virtual Vector<Double> parameters() const;
1234  virtual Bool checkParameters(const Vector<Double>& parms) const;
1235  // </group>
1236 
1237 private:
1239 };
1240 
1241 inline Double Poisson::mean() const {
1242  return itsMean;
1243 }
1244 
1245 // <summary>Uniform distribution</summary>
1246 
1247 // <synopsis>
1248 // The <src>Uniform</src> class implements a uniform random variable over the
1249 // copen interval ranging from <src>[low..high)</src>. The <src>low</src>
1250 // parameter is the lowest possible return value and the <src>high</src>
1251 // parameter can never be returned. The <src>operator()</src> functions
1252 // returns a value from this distribution.
1253 
1254 // It is assumed that low limit is less than the high limit and an AipsError
1255 // exception is thrown if this is not true. The remaining members allow you to
1256 // read and set the parameters.
1257 
1258 // </synopsis>
1259 
1260 // <example>
1261 // </example>
1262 //
1263 // <thrown>
1264 // <li> AipsError: if bad values for the arguments are given, as specified
1265 // above.
1266 // </thrown>
1267 //
1268 // <todo asof="2000/05/09">
1269 // <li> Nothing I hope!
1270 // </todo>
1271 
1272 class Uniform: public Random {
1273 public:
1274  // Construct a random number generator for a uniform distribution. The first
1275  // argument is a class that produces random bits. This pointer is NOT taken
1276  // over by this class and the user is responsible for deleting it. The
1277  // remaining arguments define the parameters for this distribution as
1278  // described in the synopsis.
1279  Uniform(RNG* gen, Double low=-1.0, Double high=1.0);
1280 
1281  // The destructor is trivial
1282  virtual ~Uniform();
1283 
1284  // Returns a value from the uniform distribution.
1285  virtual Double operator()();
1286 
1287  // Functions that allow you to query and change the parameters of the
1288  // uniform distribution.
1289  // <group>
1290  Double low() const;
1291  void low(Double x);
1292  Double high() const;
1293  void high(Double x);
1294  void range(Double low, Double high);
1295  // </group>
1296 
1297  // These function allow you to manipulate the parameters (low & high)
1298  // described above through the base class. The Vectors must always be of
1299  // length two.
1300  // <group>
1301  virtual void setParameters(const Vector<Double>& parms);
1302  virtual Vector<Double> parameters() const;
1303  virtual Bool checkParameters(const Vector<Double>& parms) const;
1304  // </group>
1305 
1306 private:
1307  static Double calcDelta(Double low, Double high);
1311 };
1312 
1313 inline Double Uniform::low() const {
1314  return itsLow;
1315 }
1316 
1317 inline Double Uniform::high() const {
1318  return itsHigh;
1319 }
1320 
1321 // <summary>Weibull distribution</summary>
1322 
1323 // <synopsis>
1324 
1325 // The <src>Weibull</src> class implements a weibull distribution with
1326 // parameters <src>alpha</src> and <src>beta</src>. The first parameter to the
1327 // class constructor is <src>alpha</src>, and the second parameter is
1328 // <src>beta</src>. It is assumed that the alpha parameter is not zero and an
1329 // AipsError exception is thrown if this is not true. The remaining members
1330 // allow you to read and set the parameters.
1331 // </synopsis>
1332 
1333 // <example>
1334 // </example>
1335 //
1336 // <thrown>
1337 // <li> AipsError: if bad values for the arguments are given, as specified
1338 // above.
1339 // </thrown>
1340 //
1341 // <todo asof="2000/05/09">
1342 // <li> Nothing I hope!
1343 // </todo>
1344 
1345 class Weibull: public Random {
1346 public:
1347  // Construct a random number generator for a uniform distribution. The first
1348  // argument is a class that produces random bits. This pointer is NOT taken
1349  // over by this class and the user is responsible for deleting it. The
1350  // remaining arguments define the parameters for this distribution as
1351  // described in the synopsis.
1352  Weibull(RNG* gen, Double alpha=1.0, Double beta=1.0);
1353 
1354  // The destructor is trivial
1355  virtual ~Weibull();
1356 
1357  // Returns a value from the Weiball distribution.
1358  virtual Double operator()();
1359 
1360  // Functions that allow you to query and change the parameters of the
1361  // Weiball distribution.
1362  // <group>
1363  Double alpha() const;
1364  void alpha(Double x);
1365  Double beta() const;
1366  void beta(Double x);
1367  // </group>
1368 
1369  // These function allow you to manipulate the parameters (alpha & beta)
1370  // described above through the base class. The Vectors must always be of
1371  // length two.
1372  // <group>
1373  virtual void setParameters(const Vector<Double>& parms);
1374  virtual Vector<Double> parameters() const;
1375  virtual Bool checkParameters(const Vector<Double>& parms) const;
1376  // </group>
1377 
1378 private:
1379  void setState();
1383 };
1384 
1385 inline Double Weibull::alpha() const {
1386  return itsAlpha;
1387 }
1388 
1389 inline Double Weibull::beta() const {
1390  return itsBeta;
1391 }
1392 
1393 
1394 } //# NAMESPACE CASACORE - END
1395 
1396 #endif
virtual Vector< Double > parameters() const
void reseed(Int s1, Int s2)
Definition: Random.h:362
Double mean() const
Functions that allow you to query and change the parameters of the discrete uniform distribution...
Definition: Random.h:788
int Int
Definition: aipstype.h:50
virtual void reset()
Resets the random number generator.
Double itsMean
Definition: Random.h:1031
std::vector< double > Vector
Definition: ds9context.h:24
static Double calcDelta(Double low, Double high)
virtual Bool checkParameters(const Vector< Double > &parms) const
Negative exponential distribution.
Definition: Random.h:1139
Binomial(RNG *gen, uInt n=1, Double p=0.5)
Construct a random number generator for a binomial distribution.
virtual Double operator()()
Returns a value from the Binomial distribution.
Uniform distribution.
Definition: Random.h:1272
RNG * generator()
Functions that allow you to access and change the class that generates the random bits...
Definition: Random.h:543
virtual Vector< Double > parameters() const
virtual Bool checkParameters(const Vector< Double > &parms) const
Double itsProbability
Definition: Random.h:871
uInt itsInitSeed
Definition: Random.h:243
virtual void setParameters(const Vector< Double > &parms)=0
These function allow you to manipulate the parameters (mean variance etc.) of random number distribut...
void range(Int low, Int high)
virtual Vector< Double > parameters() const
virtual Vector< Double > parameters() const
2 parameters, the mean and variance.
Definition: Random.h:456
virtual Double operator()()
Returns a value from the hypergeometric distribution.
virtual Bool checkParameters(const Vector< Double > &parms) const
Float asFloat()
Return random bits converted to either a Float or a Double.
1 parameter, the mean.
Definition: Random.h:466
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (mean &amp; variance) described above through the b...
virtual Vector< Double > parameters() const
virtual Double operator()()
Returns a value from the Erlang distribution.
Erlang(RNG *gen, Double mean=1.0, Double variance=1.0)
Construct a random number generator for an Erlang distribution.
Definition: Random.h:780
Geometric(RNG *gen, Double probability=0.5)
Construct a random number generator for a geometric uniform distribution.
virtual Bool checkParameters(const Vector< Double > &parms) const
virtual Vector< Double > parameters() const
virtual Bool checkParameters(const Vector< Double > &parms) const
2 parameters, mean and variance.
Definition: Random.h:452
Discrete geometric distribution.
Definition: Random.h:834
Double itsBeta
Definition: Random.h:1381
Int seed2() const
Definition: Random.h:351
RNG * itsRNG
Definition: Random.h:535
virtual ~MLCG()
The destructor is trivial.
static Random * construct(Random::Types type, RNG *gen)
Convert the Random::Type enumerator to a specific object (derived from Random but upcast to a Random ...
Types
This enumerator lists all the predefined random number distributions.
Definition: Random.h:429
virtual Bool checkParameters(const Vector< Double > &parms) const
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (alpha &amp; beta) described above through the base...
virtual casacore::String type() const
Implements RegionShape::type.
Definition: RegionShapes.h:548
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (mean &amp; variance) described above through the b...
Int low() const
Functions that allow you to query and change the parameters of the discrete uniform distribution...
Definition: Random.h:708
virtual Double operator()()
Returns a value from the negative exponential distribution.
virtual ~Binomial()
The destructor is trivial.
Short itsStateSize
Definition: Random.h:248
virtual uInt asuInt()=0
Return the 32-random bits as an unsigned integer.
Base class for random number distributions.
Definition: Random.h:425
virtual Vector< Double > parameters() const
Additive number generator.
Definition: Random.h:223
Double itsDelta
Definition: Random.h:1310
virtual ~Erlang()
The destructor is trivial.
virtual ~Uniform()
The destructor is trivial.
ACG(uInt seed=0, Int size=55)
The constructor allows you to specify seeds.
Hypergeometric distribution.
Definition: Random.h:904
virtual ~DiscreteUniform()
The destructor is trivial.
size_t size() const
Double itsMean
Definition: Random.h:774
Double itsStdDev
Definition: Random.h:1033
short Short
Definition: aipstype.h:48
Weibull(RNG *gen, Double alpha=1.0, Double beta=1.0)
Construct a random number generator for a uniform distribution.
uInt lcgRecurr
Definition: Random.h:250
Double itsInvAlpha
Definition: Random.h:1382
virtual Vector< Double > parameters() const
virtual ~Geometric()
The destructor is trivial.
Double p() const
Definition: Random.h:628
virtual Vector< Double > parameters() const
Short itsJ
Definition: Random.h:251
static Random::Types asType(const String &str)
Convert the string to enumerator.
virtual ~RNG()
A virtual destructor is needed to ensure that the destructor of derived classes gets used...
Double probability() const
Functions that allow you to query and change the parameters of the geometric uniform distribution...
Definition: Random.h:874
virtual Double variance() const
Definition: Random.h:1042
virtual Double operator()()
Returns a value from the Poisson distribution.
virtual Double operator()()
Returns a value from the uniform distribution.
2 parameters.
Definition: Random.h:434
Binomial distribution.
Definition: Random.h:581
DiscreteUniform(RNG *gen, Int low=-1, Int high=1)
Construct a random number generator for a discrete uniform distribution.
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (n &amp; p) described above through the base class...
1 parameters, the mean.
Definition: Random.h:447
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (mean &amp; variance) described above through the b...
virtual Double variance() const
Definition: Random.h:1114
Double beta() const
Definition: Random.h:1389
virtual Double mean() const
Functions that allow you to query and change the parameters of the normal distribution.
Definition: Random.h:1038
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (mean &amp; variance) described above through the b...
virtual Bool checkParameters(const Vector< Double > &parms) const
Double variance() const
Definition: Random.h:797
virtual Bool checkParameters(const Vector< Double > &parms) const
virtual Double operator()()
Returns a value from the Weiball distribution.
Double low() const
Functions that allow you to query and change the parameters of the uniform distribution.
Definition: Random.h:1313
Int seed1() const
Functions that allow the user to retrieve or change the seed integers.
Definition: Random.h:340
Normal or Gaussian distribution.
Definition: Random.h:997
double Double
Definition: aipstype.h:55
Double itsHigh
Definition: Random.h:1309
static Vector< Double > defaultParameters(Random::Types type)
returns the default parameters for the specified distribution.
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (mean) described above through the base class...
Int itsSeedOne
Definition: Random.h:336
static String asString(Random::Types type)
Convert the enumerator to a lower-case string.
virtual Bool checkParameters(const Vector< Double > &parms) const
Int itsSeedTwo
Definition: Random.h:337
2 parameters, mean and variance.
Definition: Random.h:444
virtual ~HyperGeometric()
The destructor is trivial.
void range(Double low, Double high)
Int high() const
Definition: Random.h:712
Normal(RNG *gen, Double mean=0.0, Double variance=1.0)
Construct a random number generator for a normal distribution.
1 parameter, the mean.
Definition: Random.h:463
virtual Bool checkParameters(const Vector< Double > &parms) const
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Double itsMean
Definition: Random.h:1238
Short itsAuxSize
Definition: Random.h:249
virtual Double operator()()=0
This function returns a random number from the appropriate distribution.
virtual Bool checkParameters(const Vector< Double > &parms) const
virtual Bool checkParameters(const Vector< Double > &parms) const =0
Poisson(RNG *gen, Double mean=0.0)
Construct a random number generator for a Poisson distribution.
float Float
Definition: aipstype.h:54
Erlang distribution.
Definition: Random.h:739
Double high() const
Definition: Random.h:1317
Discrete uniform distribution.
Definition: Random.h:661
LogNormal(RNG *gen, Double mean=1.0, Double variance=1.0)
Construct a random number generator for a log-normal distribution.
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (low &amp; high) described above through the base c...
Uniform(RNG *gen, Double low=-1.0, Double high=1.0)
Construct a random number generator for a uniform distribution.
NegativeExpntl(RNG *gen, Double mean=1.0)
Construct a random number generator for a negative exponential distribution.
uInt * itsStatePtr
Definition: Random.h:246
Double mean() const
Functions that allow you to query and change the parameters of the Poisson distribution.
Definition: Random.h:1241
Random(RNG *generator)
Definition: Random.h:538
An non-predefined random number distribution.
Definition: Random.h:479
virtual ~NegativeExpntl()
The destructor is trivial.
Double variance() const
Definition: Random.h:962
Double itsA
Definition: Random.h:777
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (low &amp; high) described above through the base c...
Double asDouble()
2 parameters, mean and variance.
Definition: Random.h:460
virtual ~Random()
A virtual destructor is needed to ensure that the destructor of derived classes gets used...
Base class for random number generators.
Definition: Random.h:121
virtual Double operator()()
Returns a value from the log-normal distribution.
virtual void reset()
Resets the random number generator.
Double itsCachedValue
Definition: Random.h:1035
LatticeExprNode mean(const LatticeExprNode &expr)
Weibull distribution.
Definition: Random.h:1345
virtual ~Weibull()
The destructor is trivial.
2 parameters, low and high.
Definition: Random.h:472
Number of distributions.
Definition: Random.h:482
Double mean() const
Functions that allow you to query and change the parameters of the negative exponential distribution...
Definition: Random.h:1174
Int itsInitSeedOne
Definition: Random.h:334
virtual void reset()=0
Resets the random number generator.
Multiplicative linear congruential generator.
Definition: Random.h:305
MLCG(Int seed1=0, Int seed2=1)
The constructor allows you to specify seeds.
virtual Vector< Double > parameters() const
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual uInt asuInt()
Return the 32-random bits as an unsigned integer.
virtual ~LogNormal()
The destructor is trivial.
Poisson distribution.
Definition: Random.h:1201
virtual ~Normal()
The destructor is trivial.
virtual Vector< Double > parameters() const =0
virtual Double operator()()
Returns a value from the discrete uniform distribution.
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameter (probability) described above through the base c...
uInt n() const
Functions that allow you to query and change the parameters of the binomial distribution.
Definition: Random.h:624
LatticeExprNode variance(const LatticeExprNode &expr)
Double itsVariance
Definition: Random.h:775
virtual Double mean() const
Functions that allow you to query and change the parameters of the log-normal distribution.
Definition: Random.h:1110
uInt * itsAuxStatePtr
Definition: Random.h:247
HyperGeometric(RNG *gen, Double mean=0.5, Double variance=1.0)
Construct a random number generator for an hypergeometric distribution.
Definition: Random.h:945
virtual Vector< Double > parameters() const
virtual Double operator()()
Returns a value from the normal distribution.
Double itsVariance
Definition: Random.h:1032
virtual uInt asuInt()
Return the 32-random bits as an unsigned integer.
2 parameters, alpha and beta.
Definition: Random.h:476
static Double calcDelta(Int low, Int high)
virtual ~Poisson()
The destructor is trivial.
virtual void setParameters(const Vector< Double > &parms)
These function allow you to manipulate the parameters (mean) described above through the base class...
Double itsAlpha
Definition: Random.h:1380
Logarithmic normal distribution.
Definition: Random.h:1071
Double alpha() const
Functions that allow you to query and change the parameters of the Weiball distribution.
Definition: Random.h:1385
unsigned int uInt
Definition: aipstype.h:51
Short itsK
Definition: Random.h:252
Double mean() const
Functions that allow you to query and change the parameters of the hypergeometric distribution...
Definition: Random.h:953
virtual Double operator()()
Returns a value from the geometric uniform distribution.
Int itsInitTblEntry
Definition: Random.h:244
virtual ~ACG()
The destructor cleans up memory allocated by this class.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
Int itsInitSeedTwo
Definition: Random.h:335