ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ranf_ni2.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 
25 double auto_rand(long int& idum, int reset);
27 double randn(long int& n);
28 
33  void dvar_vector::fill_randbi_ni(long int& n, double p)
34  {
35  if ( p<0 || p>1)
36  {
37  cerr << "Error in dvar_vector::fill_randbi proportions of"
38  " successes must lie between 0 and 1\n";
39  ad_exit(1);
40  }
41  long int nn;
42  nn=n;
43  for (int i=indexmin(); i<=indexmax(); i++)
44  {
45  if (auto_rand(nn,1)<=p)
46  {
47  elem(i)=1.0;
48  }
49  else
50  {
51  elem(i)=0.0;
52  }
53  }
54  }
55 
60  void dvar_vector::fill_randu_ni(long int& n)
61  {
62  long int nn;
63  nn=n;
64  for (int i=indexmin(); i<=indexmax(); i++)
65  {
66  elem(i)=auto_rand(nn,1);
67  }
68  }
69 
74 void dvar_matrix::colfill_randu_ni(const int &j, long int &n)
75  {
76  long int nn;
77  nn=n;
78  for (int i=rowmin(); i<=rowmax(); i++)
79  {
80  elem(i,j)=auto_rand(nn,1);
81  }
82  }
83 
88 void dvar_matrix::rowfill_randu_ni(const int& i, long int& n)
89  {
90  long int nn;
91  nn=n;
92  for (int j=colmin(); j<=colmax(); j++)
93  {
94  elem(i,j)=auto_rand(nn,1);
95  }
96  }
97 
102  void dvar_vector::fill_randn_ni(long int& n)
103  {
104  long int nn;
105  nn=n;
106  for (int i=indexmin(); i<=indexmax(); i++)
107  {
108  elem(i)=randn(nn);
109  }
110  }
111 
116  void dvar_matrix::fill_randn_ni(long int& n)
117  {
118  long int nn=n;
119  for (int i=rowmin(); i<=rowmax(); i++)
120  {
121  elem(i).fill_randn_ni(nn);
122  nn+=2;
123  }
124  }
125 
130  void dvar3_array::fill_randn_ni(long int& n)
131  {
132  long int nn;
133  nn=n;
134  for (int i=slicemin(); i<=slicemax(); i++)
135  {
136  elem(i).fill_randn_ni(nn);
137  nn+=2;
138  }
139  }
140 
145  void dvar3_array::fill_randu_ni(long int& n)
146  {
147  long int nn;
148  nn=n;
149  for (int i=slicemin(); i<=slicemax(); i++)
150  {
151  elem(i).fill_randu_ni(nn);
152  nn+=2;
153  }
154  }
155 
160  void dvar_matrix::fill_randu_ni(long int& n)
161  {
162  long int nn;
163  nn=n;
164  for (int i=rowmin(); i<=rowmax(); i++)
165  {
166  elem(i).fill_randu_ni(nn);
167  nn+=2;
168  }
169  }
170 
175 void dvar_matrix::colfill_randn_ni(const int &j,long int &n)
176  {
177  long int nn;
178  nn=n;
179  for (int i=rowmin(); i<=rowmax(); i++)
180  {
181  elem(i,j)=randn(nn);
182  }
183  }
184 
189 void dvar_matrix::rowfill_randn_ni(const int& i, long int& n)
190  {
191  long int nn;
192  nn=n;
193  for (int j=colmin(); j<=colmax(); j++)
194  {
195  elem(i,j)=randn(nn);
196  }
197  }
void rowfill_randu_ni(const int &i, long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:88
int rowmax(void) const
Definition: fvar.hpp:2564
dvar_vector & elem(int i)
Definition: fvar.hpp:2507
int slicemin() const
Definition: fvar.hpp:4274
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
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
void colfill_randn_ni(const int &j, long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:175
exitptr ad_exit
Definition: gradstrc.cpp:53
prevariable elem(int i)
Definition: fvar.hpp:2221
void fill_randu_ni(long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:145
dvar_matrix & elem(int i)
? Retrieves an element of a dvar3_array.
Definition: fvar.hpp:4315
void rowfill_randn_ni(const int &i, long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:189
void fill_randbi_ni(long int &n, double)
Description not yet available.
Definition: ranf_ni2.cpp:33
void fill_randu_ni(long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:160
void fill_randn_ni(long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:130
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void fill_randu_ni(long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:60
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 colfill_randu_ni(const int &j, long int &n)
Description not yet available.
Definition: ranf_ni2.cpp:74
int indexmax() const
Definition: fvar.hpp:2292
int colmax(void) const
Definition: fvar.hpp:2556