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