ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cranfill.cpp
Go to the documentation of this file.
1 
5 #include <fvar.hpp>
6 
7 #ifdef __TURBOC__
8  #pragma hdrstop
9  #include <iostream.h>
10 #endif
11 
12 #ifdef __ZTC__
13  #include <iostream.hpp>
14 #endif
15 
16 #include <math.h>
17 
23 double var(const dvector& vec)
24 {
25  double x = norm(vec) / sqrt(static_cast<double>(vec.size()));
26  double y = mean(vec);
27  return x * x - y * y;
28 }
34 double std_dev(const dvector& vec)
35 {
36  return sqrt(var(vec));
37 }
43 double mean(const dvector& vec)
44 {
45  double sum = 0;
46  for (int i = vec.indexmin(); i <= vec.indexmax(); ++i)
47  {
48  sum += vec.elem(i);
49  }
50  return sum / vec.size();
51 }
58 void dvector::fill_seqadd(const double base, const double offset)
59 {
60  double sequence = base;
61  for (int i = indexmin(); i <= indexmax(); ++i)
62  {
63  elem(i) = sequence;
64  sequence += offset;
65  }
66 }
73 void ivector::fill_seqadd(int base, int offset)
74 {
75  int sequence = base;
76  for (int i = indexmin(); i <= indexmax(); ++i)
77  {
78  elem(i) = sequence;
79  sequence += offset;
80  }
81 }
88 void lvector::fill_seqadd(const AD_LONG_INT& base, const AD_LONG_INT& offset)
89 {
90  AD_LONG_INT sequence = base;
91  for (int i = indexmin(); i <= indexmax(); ++i)
92  {
93  elem(i) = sequence;
94  sequence += offset;
95  }
96 }
106  const int& column,
107  const double base,
108  const double offset)
109 {
110  double sequence = base;
111  for (int i = rowmin(); i <= rowmax(); ++i)
112  {
113  elem(i, column) = sequence;
114  sequence += offset;
115  }
116 }
123 void dmatrix::colfill(int column, const dvector& vec)
124 {
125  for (int i = rowmin(); i <= rowmax(); ++i)
126  {
127  (*this)[i][column] = vec[i];
128  }
129 }
136 void dmatrix::rowfill(int row, const dvector& vec)
137 {
138  elem(row) = vec;
139 }
149  const int& row,
150  const double base,
151  const double offset)
152 {
153  elem(row).fill_seqadd(base, offset);
154 }
void rowfill(int j, const dvector &v)
Fills dmatrix row at index row with values from vec.
Definition: cranfill.cpp:136
int & elem(int i)
Definition: ivector.h:90
double & elem(int i)
Definition: dvector.h:152
#define x
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
int indexmin() const
Definition: fvar.hpp:676
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
void fill_seqadd(double, double)
Fills dvector elements with values starting from base and incremented by offset.
Definition: cranfill.cpp:58
void colfill_seqadd(const int &, const int &, const int &)
dvector row(const dmatrix &matrix, int i)
Returns a copied row for matrix at i.
Definition: dmat6.cpp:24
void fill_seqadd(int, int)
Fills ivector elements with values starting from base and incremented by offset.
Definition: cranfill.cpp:73
double mean(const dvector &vec)
Returns computed mean of vec.
Definition: cranfill.cpp:43
double norm(const d3_array &a)
Return computed norm value of a.
Definition: d3arr2a.cpp:190
double std_dev(const dvector &vec)
Returns the computed standand deviation of vec.
Definition: cranfill.cpp:34
int indexmax() const
Definition: fvar.hpp:681
AD_LONG_INT & elem(int i)
Definition: fvar.hpp:667
int rowmax() const
Definition: fvar.hpp:2929
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2c.cpp:11
double var(const dvector &vec)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: cranfill.cpp:23
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int indexmin() const
Definition: ivector.h:99
int indexmax() const
Definition: ivector.h:104
dvector & elem(int i)
Definition: fvar.hpp:3011
void rowfill_seqadd(const int &, double, double)
Fills dmatrix row at index with elements with values starting from base and incremented by offset...
Definition: cranfill.cpp:148
void colfill(int j, const dvector &v)
Fills dmatrix column at index column with values from vec.
Definition: cranfill.cpp:123
unsigned int size() const
Get number of elements in array.
Definition: dvector.h:209
void fill_seqadd(const AD_LONG_INT &, const AD_LONG_INT &)
Fills ivector elements with values starting from base and incremented by offset.
Definition: cranfill.cpp:88
#define AD_LONG_INT
Definition: fvar.hpp:81
dvector column(const dmatrix &matrix, int j)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat6.cpp:13
int rowmin() const
Definition: fvar.hpp:2925