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