annotate liboctave/oct-rand.h @ 8710:739141cde75a ss-3-1-52

fix typo in Array-f.cc
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 09 Feb 2009 21:51:31 +0100
parents a2950622f070
children eb63fbe60fab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
1 /*
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 2003, 2005, 2006, 2007 John W. Eaton
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
4
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
6
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
10 option) any later version.
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
11
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
15 for more details.
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
16
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
19 <http://www.gnu.org/licenses/>.
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
20
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
21 */
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
22
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
23 #if !defined (octave_rand_h)
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
24 #define octave_rand_h 1
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
25
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
26 #include <map>
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
27 #include <string>
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
28
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
29 #include "dColVector.h"
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
30 #include "dMatrix.h"
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4308
diff changeset
31 #include "dNDArray.h"
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
32 #include "lo-ieee.h"
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
33
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
34 class
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5730
diff changeset
35 OCTAVE_API
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
36 octave_rand
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
37 {
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
38 protected:
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
39
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
40 octave_rand (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
41
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
42 public:
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
43
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
44 ~octave_rand (void) { }
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
45
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
46 static bool instance_ok (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
47
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
48 // Return the current seed.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
49 static double seed (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
50 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
51 return instance_ok () ? instance->do_seed () : octave_NaN;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
52 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
53
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
54 // Set the seed.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
55 static void seed (double s)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
56 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
57 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
58 instance->do_seed (s);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
59 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
60
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
61 // Return the current state.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
62 static ColumnVector state (const std::string& d = std::string ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
63 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
64 return instance_ok () ? instance->do_state (d) : ColumnVector ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
65 }
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
66
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
67 // Set the current state/
7533
ff52243af934 save state separately for each MT random number generator
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
68 static void state (const ColumnVector &s,
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
69 const std::string& d = std::string ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
70 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
71 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
72 instance->do_state (s, d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
73 }
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
74
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
75 // Return the current distribution.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
76 static std::string distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
77 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
78 return instance_ok () ? instance->do_distribution () : std::string ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
79 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
80
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
81 // Set the current distribution. May be either "uniform" (the
7533
ff52243af934 save state separately for each MT random number generator
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
82 // default), "normal", "exponential", "poisson", or "gamma".
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
83 static void distribution (const std::string& d)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
84 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
85 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
86 instance->do_distribution (d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
87 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
88
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
89 static void uniform_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
90 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
91 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
92 instance->do_uniform_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
93 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
94
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
95 static void normal_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
96 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
97 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
98 instance->do_normal_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
99 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
100
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
101 static void exponential_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
102 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
103 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
104 instance->do_exponential_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
105 }
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
106
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
107 static void poisson_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
108 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
109 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
110 instance->do_poisson_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
111 }
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
112
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
113 static void gamma_distribution (void)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
114 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
115 if (instance_ok ())
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
116 instance->do_gamma_distribution ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
117 }
5730
109fdf7b3dcb [project @ 2006-04-03 19:18:26 by jwe]
jwe
parents: 5307
diff changeset
118
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
119 // Return the next number from the sequence.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
120 static double scalar (double a = 1.0)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
121 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
122 return instance_ok () ? instance->do_scalar (a) : octave_NaN;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
123 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
124
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
125 // Return a matrix of numbers from the sequence, filled in column
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
126 // major order.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
127 static Matrix matrix (octave_idx_type r, octave_idx_type c, double a = 1.0)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
128 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
129 return instance_ok () ? instance->do_matrix (r, c, a) : Matrix ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
130 }
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
131
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4308
diff changeset
132 // Return an N-dimensional array of numbers from the sequence,
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4308
diff changeset
133 // filled in column major order.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
134 static NDArray nd_array (const dim_vector& dims, double a = 1.0)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
135 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
136 return instance_ok () ? instance->do_nd_array (dims, a) : NDArray ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
137 }
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4308
diff changeset
138
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
139 // Return an array of numbers from the sequence.
7537
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
140 static Array<double> vector (octave_idx_type n, double a = 1.0)
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
141 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
142 return instance_ok () ? instance->do_vector (n, a) : Array<double> ();
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
143 }
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
144
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
145 private:
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
146
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
147 static octave_rand *instance;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
148
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
149 enum
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
150 {
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
151 unknown_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
152 uniform_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
153 normal_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
154 expon_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
155 poisson_dist,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
156 gamma_dist
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
157 };
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
158
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
159 // Current distribution of random numbers.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
160 int current_distribution;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
161
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
162 // If TRUE, use old RANLIB generators. Otherwise, use Mersenne
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
163 // Twister generator.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
164 bool use_old_generators;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
165
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
166 // Saved MT states.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
167 std::map<int, ColumnVector> rand_states;
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
168
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
169 // Return the current seed.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
170 double do_seed (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
171
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
172 // Set the seed.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
173 void do_seed (double s);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
174
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
175 // Return the current state.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
176 ColumnVector do_state (const std::string& d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
177
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
178 // Set the current state/
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
179 void do_state (const ColumnVector &s, const std::string& d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
180
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
181 // Return the current distribution.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
182 std::string do_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
183
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
184 // Set the current distribution. May be either "uniform" (the
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
185 // default), "normal", "exponential", "poisson", or "gamma".
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
186 void do_distribution (const std::string& d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
187
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
188 void do_uniform_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
189
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
190 void do_normal_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
191
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
192 void do_exponential_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
193
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
194 void do_poisson_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
195
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
196 void do_gamma_distribution (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
197
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
198 // Return the next number from the sequence.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
199 double do_scalar (double a = 1.);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
200
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
201 // Return a matrix of numbers from the sequence, filled in column
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
202 // major order.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
203 Matrix do_matrix (octave_idx_type r, octave_idx_type c, double a = 1.);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
204
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
205 // Return an N-dimensional array of numbers from the sequence,
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
206 // filled in column major order.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
207 NDArray do_nd_array (const dim_vector& dims, double a = 1.);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
208
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
209 // Return an array of numbers from the sequence.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
210 Array<double> do_vector (octave_idx_type n, double a = 1.);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
211
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
212 // Some helper functions.
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
213
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
214 void initialize_ranlib_generators (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
215
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
216 void initialize_mersenne_twister (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
217
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
218 ColumnVector get_internal_state (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
219
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
220 void save_state (void);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
221
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
222 int get_dist_id (const std::string& d);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
223
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
224 void set_internal_state (const ColumnVector& s);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
225
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
226 void switch_to_generator (int dist);
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
227
a2950622f070 make octave_rand a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7533
diff changeset
228 void fill (octave_idx_type len, double *v, double a);
4308
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
229 };
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
230
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
231 #endif
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
232
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
233 /*
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
234 ;;; Local Variables: ***
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
235 ;;; mode: C++ ***
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
236 ;;; End: ***
b738d1a02adb [project @ 2003-01-24 19:37:12 by jwe]
jwe
parents:
diff changeset
237 */