ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ranfill2.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <fvar.hpp>
12 
13 #ifdef __TURBOC__
14  #pragma hdrstop
15  #include <iostream.h>
16 #endif
17 
18 #ifdef __ZTC__
19  #include <iostream.hpp>
20 #endif
21 
22 #include <math.h>
23 
24 double auto_rand(long int& idum, int reset);
26 double randn(long int& n);
27 
32  void dvar_vector::fill_randu(long int& n)
33  {
34  long int nn;
37 
38  nn=n;
39  for (int i=indexmin(); i<=indexmax(); i++)
40  {
41  elem(i)=auto_rand(nn,1);
42  }
45  }
46 
51  void dvar_vector::fill_randbi(long int& n, double p)
52  {
53  if ( p<0 || p>1)
54  {
55  cerr << "Error in dvar_vector::fill_randbi proportions of"
56  " successes must lie between 0 and 1\n";
57  ad_exit(1);
58  }
59  long int nn;
62  nn=n;
63  for (int i=indexmin(); i<=indexmax(); i++)
64  {
65  if (auto_rand(nn,1)<=p)
66  {
67  elem(i)=1.;
68  }
69  else
70  {
71  elem(i)=0.;
72  }
73  }
76  }
77 
82 void dvar_matrix::colfill_randu(const int &j, long int &n)
83  {
84  long int nn;
87  nn=n;
88  for (int i=rowmin(); i<=rowmax(); i++)
89  {
90  elem(i,j)=auto_rand(nn,1);
91  }
94  }
95 
100 void dvar_matrix::rowfill_randu(const int& i, long int& n)
101  {
102  long int nn;
105  nn=n;
106  for (int j=colmin(); j<=colmax(); j++)
107  {
108  elem(i,j)=auto_rand(nn,1);
109  }
112  }
113 
118  void dvar_vector::fill_randn(long int& n)
119  {
120  long int nn;
123  nn=n;
124  for (int i=indexmin(); i<=indexmax(); i++)
125  {
126  elem(i)=randn(nn);
127  }
130  }
131 
136 void dvar_matrix::colfill_randn(const int &j, long int &n)
137  {
138  long int nn;
141  nn=n;
142  for (int i=rowmin(); i<=rowmax(); i++)
143  {
144  elem(i,j)=randn(nn);
145  }
148  }
149 
154 void dvar_matrix::rowfill_randn(const int& i, long int& n)
155  {
156  long int nn;
159  nn=n;
160  for (int j=colmin(); j<=colmax(); j++)
161  {
162  elem(i,j)=randn(nn);
163  }
166  }
167 
172  void dvar_matrix::fill_randn(long int& n)
173  {
174  long int nn=n;
177  for (int i=rowmin(); i<=rowmax(); i++)
178  {
179  elem(i).fill_randn_ni(nn);
180  nn+=2;
181  }
184  }
185 
190  void dvar_matrix::fill_randu(long int& n)
191  {
192  long int nn=n;
195  for (int i=rowmin(); i<=rowmax(); i++)
196  {
197  elem(i).fill_randn_ni(nn);
198  nn+=2;
199  }
202  }
203 
208  void dvar3_array::fill_randn(long int& n)
209  {
210  long int nn;
211  nn=n;
212  for (int i=slicemin(); i<=slicemax(); i++)
213  {
214  elem(i).fill_randn_ni(nn);
215  nn+=2;
216  }
218  }
219 
224  void dvar3_array::fill_randu(long int& n)
225  {
226  long int nn;
227  nn=n;
228  for (int i=slicemin(); i<=slicemax(); i++)
229  {
230  elem(i).fill_randu_ni(nn);
231  nn+=2;
232  }
234  }
void fill_randu(long int &n)
Description not yet available.
Definition: ranfill2.cpp:224
void fill_randbi(long int &n, double)
Description not yet available.
Definition: ranfill2.cpp:51
int rowmax(void) const
Definition: fvar.hpp:2564
dvar_vector & elem(int i)
Definition: fvar.hpp:2507
int slicemin() const
Definition: fvar.hpp:4274
void fill_randn(long int &n)
Description not yet available.
Definition: ranfill2.cpp:118
double auto_rand(long int &idum, int reset)
Random number generator.
Definition: ranfill.cpp:84
void reinitialize_auto_rand()
Description not yet available.
Definition: ranfill.cpp:71
void colfill_randn(const int &j, long int &n)
Description not yet available.
Definition: ranfill2.cpp:136
int colmin(void) const
Definition: fvar.hpp:2552
int slicemax() const
Definition: fvar.hpp:4275
void fill_randn_ni(long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:102
exitptr ad_exit
Definition: gradstrc.cpp:53
prevariable elem(int i)
Definition: fvar.hpp:2221
void fill_randu(long int &n)
Description not yet available.
Definition: ranfill2.cpp:190
dvar_matrix & elem(int i)
? Retrieves an element of a dvar3_array.
Definition: fvar.hpp:4315
void fill_randu_ni(long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:160
void colfill_randu(const int &j, long int &n)
Description not yet available.
Definition: ranfill2.cpp:82
void RETURN_ARRAYS_INCREMENT()
Definition: gradstrc.cpp:478
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static _THREAD gradient_structure * _instance
int rowmin(void) const
Definition: fvar.hpp:2560
void fill_randn_ni(long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:116
int indexmin() const
Definition: fvar.hpp:2287
double randn(const random_number_generator &rng)
Normal number generator.
Definition: rngen.cpp:183
void fill_randn(long int &n)
Description not yet available.
Definition: ranfill2.cpp:172
void rowfill_randn(const int &i, long int &n)
Description not yet available.
Definition: ranfill2.cpp:154
void RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
void fill_randn(long int &n)
Description not yet available.
Definition: ranfill2.cpp:208
int indexmax() const
Definition: fvar.hpp:2292
void fill_randu(long int &n)
Description not yet available.
Definition: ranfill2.cpp:32
int colmax(void) const
Definition: fvar.hpp:2556
void rowfill_randu(const int &i, long int &n)
Description not yet available.
Definition: ranfill2.cpp:100