From 18cd72a36fc582ab62d51f74ce76131ac605dbcf Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 26 Jun 2020 12:58:40 +0000 Subject: [PATCH] Documentation for eddda4e43ebe1ba797a5b31d962515bd56d3888e --- ...__least__squares__regressor_8cpp__incl.map | 10 +- ...__least__squares__regressor_8cpp__incl.md5 | 2 +- ...__least__squares__regressor_8cpp__incl.svg | 66 +- d4/d68/qr__decompose_8h_source.html | 25 +- ...inary__least__squares__regressor_8cpp.html | 655 ++++++++++-------- ...rdinary__least__squares__regressor_8cpp.js | 3 +- ...1a3968e7947464bee7714f6d43b7002_cgraph.map | 20 + ...1a3968e7947464bee7714f6d43b7002_cgraph.md5 | 1 + ...1a3968e7947464bee7714f6d43b7002_cgraph.svg | 433 ++++++++++++ ...68e7947464bee7714f6d43b7002_cgraph_org.svg | 345 +++++++++ ...66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map | 27 +- ...66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 | 2 +- ...66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg | 405 ++++++++++- ...b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg | 378 ++++++++++ globals_func_t.html | 15 +- globals_t.html | 19 +- navtreedata.js | 2 +- navtreeindex1.js | 2 +- navtreeindex2.js | 2 +- navtreeindex3.js | 8 +- navtreeindex4.js | 3 +- search/all_14.js | 2 +- search/functions_14.js | 2 +- 23 files changed, 2034 insertions(+), 393 deletions(-) create mode 100644 dc/d38/ordinary__least__squares__regressor_8cpp_ae1a3968e7947464bee7714f6d43b7002_cgraph.map create mode 100644 dc/d38/ordinary__least__squares__regressor_8cpp_ae1a3968e7947464bee7714f6d43b7002_cgraph.md5 create mode 100644 dc/d38/ordinary__least__squares__regressor_8cpp_ae1a3968e7947464bee7714f6d43b7002_cgraph.svg create mode 100644 dc/d38/ordinary__least__squares__regressor_8cpp_ae1a3968e7947464bee7714f6d43b7002_cgraph_org.svg create mode 100644 dc/d38/ordinary__least__squares__regressor_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg diff --git a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.map b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.map index 020cd81ca..cee9012ba 100644 --- a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.map +++ b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.map @@ -1,6 +1,8 @@ - - - - + + + + + + diff --git a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.md5 b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.md5 index 05d572c7b..722ec6c02 100644 --- a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.md5 +++ b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.md5 @@ -1 +1 @@ -3342bed250275ada240abc86394a8bff \ No newline at end of file +868ad72095fe395df7c4d0862a42dea5 \ No newline at end of file diff --git a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.svg b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.svg index 5870dd927..35a9f8d32 100644 --- a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.svg +++ b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.svg @@ -4,18 +4,18 @@ - + numerical_methods/ordinary_least_squares_regressor.cpp - + Node1 - -numerical_methods/ordinary -_least_squares_regressor.cpp + +numerical_methods/ordinary +_least_squares_regressor.cpp @@ -23,46 +23,76 @@ Node2 - -iomanip + +cassert Node1->Node2 - - + + Node3 - -iostream + +cmath Node1->Node3 - - + + Node4 - -vector + +iomanip Node1->Node4 - - + + + + + +Node5 + + +iostream + + + + + +Node1->Node5 + + + + + +Node6 + + +vector + + + + + +Node1->Node6 + + diff --git a/d4/d68/qr__decompose_8h_source.html b/d4/d68/qr__decompose_8h_source.html index d5e14ed1b..d8661d5d3 100644 --- a/d4/d68/qr__decompose_8h_source.html +++ b/d4/d68/qr__decompose_8h_source.html @@ -312,7 +312,7 @@ $(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h_source.html','
MAX_ITERATIONS
#define MAX_ITERATIONS
Maximum number of iterations to check.
Definition: newton_raphson_method.cpp:21
semi_implicit_euler_step
void semi_implicit_euler_step(const double dx, const double &x, std::valarray< double > *y, std::valarray< double > *dy)
Compute next step approximation using the semi-implicit-Euler method.
Definition: ode_semi_implicit_euler.cpp:82
std::clock_t
-
operator+
std::vector< T > operator+(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:196
+
operator+
std::vector< T > operator+(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:198
eq
static double eq(double i)
Definition: newton_raphson_method.cpp:29
std::cos
T cos(T... args)
eq_der
static double eq_der(double i)
Definition: newton_raphson_method.cpp:39
@@ -323,14 +323,16 @@ $(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h_source.html','
main
int main(int argc, char *argv[])
Definition: ode_forward_euler.cpp:188
std::setfill
T setfill(T... args)
midpoint_euler_step
void midpoint_euler_step(const double dx, const double &x, std::valarray< double > *y, std::valarray< double > *dy)
Compute next step approximation using the midpoint-Euler method.
Definition: ode_midpoint_euler.cpp:85
-
is_square
bool is_square(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:55
+
is_square
bool is_square(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:57
std::sqrt
T sqrt(T... args)
qr_algorithm
Functions to compute QR decomposition of any rectangular matrix.
-
operator*
std::vector< std::vector< T > > operator*(std::vector< std::vector< T >> const &A, std::vector< std::vector< T >> const &B)
Definition: ordinary_least_squares_regressor.cpp:72
+
operator*
std::vector< std::vector< T > > operator*(std::vector< std::vector< T >> const &A, std::vector< std::vector< T >> const &B)
Definition: ordinary_least_squares_regressor.cpp:74
forward_euler_step
void forward_euler_step(const double dx, const double &x, std::valarray< double > *y, std::valarray< double > *dy)
Compute next step approximation using the forward-Euler method.
Definition: ode_forward_euler.cpp:86
+
test
void test()
Definition: ordinary_least_squares_regressor.cpp:358
std::clock
T clock(T... args)
-
operator<<
std::ostream & operator<<(std::ostream &out, std::vector< std::vector< T >> const &v)
Definition: ordinary_least_squares_regressor.cpp:20
+
operator<<
std::ostream & operator<<(std::ostream &out, std::vector< std::vector< T >> const &v)
Definition: ordinary_least_squares_regressor.cpp:22
save_exact_solution
void save_exact_solution(const double &X0, const double &X_MAX, const double &step_size, const std::valarray< double > &Y0)
Definition: ode_forward_euler.cpp:152
+
test1
void test1(double eta=0.01)
Definition: adaline_learning.cpp:204
qr_algorithm::vector_proj
std::valarray< T > vector_proj(const std::valarray< T > &a, const std::valarray< T > &b)
Definition: qr_decompose.h:104
std::cout
std::ofstream
STL class.
@@ -338,8 +340,8 @@ $(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h_source.html','
std::ofstream::close
T close(T... args)
std::perror
T perror(T... args)
std::valarray
STL class.
-
main
int main()
Definition: ordinary_least_squares_regressor.cpp:358
-
predict_OLS_regressor
std::vector< float > predict_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< float > const &beta)
Definition: ordinary_least_squares_regressor.cpp:340
+
main
int main()
Definition: ordinary_least_squares_regressor.cpp:410
+
predict_OLS_regressor
std::vector< float > predict_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< float > const &beta)
Definition: ordinary_least_squares_regressor.cpp:342
std::ofstream::open
T open(T... args)
qr_algorithm::operator<<
std::ostream & operator<<(std::ostream &out, std::valarray< std::valarray< T >> const &v)
Definition: qr_decompose.h:33
forward_euler
double forward_euler(double dx, double x0, double x_max, std::valarray< double > *y, bool save_to_file=false)
Compute approximation using the forward-Euler method in the given limits.
Definition: ode_forward_euler.cpp:102
@@ -349,10 +351,10 @@ $(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h_source.html','
EPSILON
#define EPSILON
system accuracy limit
Definition: newton_raphson_method.cpp:20
problem
void problem(const double &x, std::valarray< double > *y, std::valarray< double > *dy)
Problem statement for a system with first-order differential equations. Updates the system differenti...
Definition: ode_forward_euler.cpp:54
data
int data[MAX]
test data
Definition: hash_search.cpp:24
-
fit_OLS_regressor
std::vector< float > fit_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< T > const &Y)
Definition: ordinary_least_squares_regressor.cpp:310
-
operator-
std::vector< T > operator-(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:175
+
fit_OLS_regressor
std::vector< float > fit_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< T > const &Y)
Definition: ordinary_least_squares_regressor.cpp:312
+
operator-
std::vector< T > operator-(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:177
std::endl
T endl(T... args)
-
get_inverse
std::vector< std::vector< float > > get_inverse(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:218
+
get_inverse
std::vector< std::vector< float > > get_inverse(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:220
qr_algorithm::vector_dot
double vector_dot(const std::valarray< T > &a, const std::valarray< T > &b)
Definition: qr_decompose.h:76
std::left
T left(T... args)
problem
void problem(const double &x, std::valarray< double > *y, std::valarray< double > *dy)
Problem statement for a system with first-order differential equations. Updates the system differenti...
Definition: ode_midpoint_euler.cpp:53
@@ -366,13 +368,14 @@ $(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h_source.html','
exact_solution
void exact_solution(const double &x, std::valarray< double > *y)
Exact solution of the problem. Used for solution comparison.
Definition: ode_semi_implicit_euler.cpp:66
std::setw
T setw(T... args)
std::cin
+
test2
void test2(double eta=0.01)
Definition: adaline_learning.cpp:238
std::numeric_limits
std::ofstream::is_open
T is_open(T... args)
exact_solution
void exact_solution(const double &x, std::valarray< double > *y)
Exact solution of the problem. Used for solution comparison.
Definition: ode_midpoint_euler.cpp:66
-
operator/
std::vector< float > operator/(std::vector< T > const &A, float const scalar)
Definition: ordinary_least_squares_regressor.cpp:166
+
operator/
std::vector< float > operator/(std::vector< T > const &A, float const scalar)
Definition: ordinary_least_squares_regressor.cpp:168
main
int main(int argc, char *argv[])
Definition: ode_midpoint_euler.cpp:192
std::pow
T pow(T... args)
-
get_transpose
std::vector< std::vector< T > > get_transpose(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:289
+
get_transpose
std::vector< std::vector< T > > get_transpose(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:291

main function

-
358  {
-
359  size_t N, F;
-
360 
-
361  std::cout << "Enter number of features: ";
-
362  // number of features = columns
-
363  std::cin >> F;
-
364  std::cout << "Enter number of samples: ";
-
365  // number of samples = rows
-
366  std::cin >> N;
-
367 
- -
369  std::vector<float> Y(N);
-
370 
-
371  std::cout
-
372  << "Enter training data. Per sample, provide features ad one output."
-
373  << std::endl;
-
374 
-
375  for (size_t rows = 0; rows < N; rows++) {
-
376  std::vector<float> v(F);
-
377  std::cout << "Sample# " << rows + 1 << ": ";
-
378  for (size_t cols = 0; cols < F; cols++)
-
379  // get the F features
-
380  std::cin >> v[cols];
-
381  data[rows] = v;
-
382  // get the corresponding output
-
383  std::cin >> Y[rows];
-
384  }
-
385 
- -
387  std::cout << std::endl << std::endl << "beta:" << beta << std::endl;
-
388 
-
389  size_t T;
-
390  std::cout << "Enter number of test samples: ";
-
391  // number of test sample inputs
-
392  std::cin >> T;
- -
394  // vector<float> Y2(T);
-
395 
-
396  for (size_t rows = 0; rows < T; rows++) {
-
397  std::cout << "Sample# " << rows + 1 << ": ";
-
398  std::vector<float> v(F);
-
399  for (size_t cols = 0; cols < F; cols++) std::cin >> v[cols];
-
400  data2[rows] = v;
-
401  }
-
402 
-
403  std::vector<float> out = predict_OLS_regressor(data2, beta);
-
404  for (size_t rows = 0; rows < T; rows++) std::cout << out[rows] << std::endl;
-
405 
-
406  return 0;
-
407 }
+
410  {
+
411  test();
+
412 
+
413  size_t N, F;
+
414 
+
415  std::cout << "Enter number of features: ";
+
416  // number of features = columns
+
417  std::cin >> F;
+
418  std::cout << "Enter number of samples: ";
+
419  // number of samples = rows
+
420  std::cin >> N;
+
421 
+ +
423  std::vector<float> Y(N);
+
424 
+
425  std::cout
+
426  << "Enter training data. Per sample, provide features and one output."
+
427  << std::endl;
+
428 
+
429  for (size_t rows = 0; rows < N; rows++) {
+
430  std::vector<float> v(F);
+
431  std::cout << "Sample# " << rows + 1 << ": ";
+
432  for (size_t cols = 0; cols < F; cols++)
+
433  // get the F features
+
434  std::cin >> v[cols];
+
435  data[rows] = v;
+
436  // get the corresponding output
+
437  std::cin >> Y[rows];
+
438  }
+
439 
+ +
441  std::cout << std::endl << std::endl << "beta:" << beta << std::endl;
+
442 
+
443  size_t T;
+
444  std::cout << "Enter number of test samples: ";
+
445  // number of test sample inputs
+
446  std::cin >> T;
+ +
448  // vector<float> Y2(T);
+
449 
+
450  for (size_t rows = 0; rows < T; rows++) {
+
451  std::cout << "Sample# " << rows + 1 << ": ";
+
452  std::vector<float> v(F);
+
453  for (size_t cols = 0; cols < F; cols++) std::cin >> v[cols];
+
454  data2[rows] = v;
+
455  }
+
456 
+
457  std::vector<float> out = predict_OLS_regressor(data2, beta);
+
458  for (size_t rows = 0; rows < T; rows++) std::cout << out[rows] << std::endl;
+
459 
+
460  return 0;
+
461 }
Here is the call graph for this function:
-
+
@@ -488,18 +494,18 @@ template<typename T >

pre-multiplication of a vector by a scalar

Returns
resultant vector
-
131  {
-
132  // Number of rows in A
-
133  size_t N_A = A.size();
-
134 
-
135  std::vector<float> result(N_A);
+
133  {
+
134  // Number of rows in A
+
135  size_t N_A = A.size();
136 
-
137  for (size_t row = 0; row < N_A; row++) {
-
138  result[row] += A[row] * static_cast<float>(scalar);
-
139  }
-
140 
-
141  return result;
-
142 }
+
137  std::vector<float> result(N_A);
+
138 
+
139  for (size_t row = 0; row < N_A; row++) {
+
140  result[row] += A[row] * static_cast<float>(scalar);
+
141  }
+
142 
+
143  return result;
+
144 }
Here is the call graph for this function:
@@ -538,32 +544,32 @@ template<typename T >

Matrix multiplication such that if A is size (mxn) and B is of size (pxq) then the multiplication is defined only when n = p and the resultant matrix is of size (mxq)

Returns
resultant matrix
-
73  {
-
74  // Number of rows in A
-
75  size_t N_A = A.size();
-
76  // Number of columns in B
-
77  size_t N_B = B[0].size();
-
78 
-
79  std::vector<std::vector<T>> result(N_A);
+
75  {
+
76  // Number of rows in A
+
77  size_t N_A = A.size();
+
78  // Number of columns in B
+
79  size_t N_B = B[0].size();
80 
-
81  if (A[0].size() != B.size()) {
-
82  std::cerr << "Number of columns in A != Number of rows in B ("
-
83  << A[0].size() << ", " << B.size() << ")" << std::endl;
-
84  return result;
-
85  }
-
86 
-
87  for (size_t row = 0; row < N_A; row++) {
-
88  std::vector<T> v(N_B);
-
89  for (size_t col = 0; col < N_B; col++) {
-
90  v[col] = static_cast<T>(0);
-
91  for (size_t j = 0; j < B.size(); j++)
-
92  v[col] += A[row][j] * B[j][col];
-
93  }
-
94  result[row] = v;
-
95  }
-
96 
-
97  return result;
-
98 }
+
81  std::vector<std::vector<T>> result(N_A);
+
82 
+
83  if (A[0].size() != B.size()) {
+
84  std::cerr << "Number of columns in A != Number of rows in B ("
+
85  << A[0].size() << ", " << B.size() << ")" << std::endl;
+
86  return result;
+
87  }
+
88 
+
89  for (size_t row = 0; row < N_A; row++) {
+
90  std::vector<T> v(N_B);
+
91  for (size_t col = 0; col < N_B; col++) {
+
92  v[col] = static_cast<T>(0);
+
93  for (size_t j = 0; j < B.size(); j++)
+
94  v[col] += A[row][j] * B[j][col];
+
95  }
+
96  result[row] = v;
+
97  }
+
98 
+
99  return result;
+
100 }
Here is the call graph for this function:
@@ -601,25 +607,25 @@ template<typename T >

multiplication of a matrix with a column vector

Returns
resultant vector
-
106  {
-
107  // Number of rows in A
-
108  size_t N_A = A.size();
-
109 
-
110  std::vector<T> result(N_A);
+
108  {
+
109  // Number of rows in A
+
110  size_t N_A = A.size();
111 
-
112  if (A[0].size() != B.size()) {
-
113  std::cerr << "Number of columns in A != Number of rows in B ("
-
114  << A[0].size() << ", " << B.size() << ")" << std::endl;
-
115  return result;
-
116  }
-
117 
-
118  for (size_t row = 0; row < N_A; row++) {
-
119  result[row] = static_cast<T>(0);
-
120  for (size_t j = 0; j < B.size(); j++) result[row] += A[row][j] * B[j];
-
121  }
-
122 
-
123  return result;
-
124 }
+
112  std::vector<T> result(N_A);
+
113 
+
114  if (A[0].size() != B.size()) {
+
115  std::cerr << "Number of columns in A != Number of rows in B ("
+
116  << A[0].size() << ", " << B.size() << ")" << std::endl;
+
117  return result;
+
118  }
+
119 
+
120  for (size_t row = 0; row < N_A; row++) {
+
121  result[row] = static_cast<T>(0);
+
122  for (size_t j = 0; j < B.size(); j++) result[row] += A[row][j] * B[j];
+
123  }
+
124 
+
125  return result;
+
126 }
Here is the call graph for this function:
@@ -657,17 +663,17 @@ template<typename T >

post-multiplication of a vector by a scalar

Returns
resultant vector
-
149  {
-
150  // Number of rows in A
-
151  size_t N_A = A.size();
-
152 
-
153  std::vector<float> result(N_A);
+
151  {
+
152  // Number of rows in A
+
153  size_t N_A = A.size();
154 
-
155  for (size_t row = 0; row < N_A; row++)
-
156  result[row] = A[row] * static_cast<float>(scalar);
-
157 
-
158  return result;
-
159 }
+
155  std::vector<float> result(N_A);
+
156 
+
157  for (size_t row = 0; row < N_A; row++)
+
158  result[row] = A[row] * static_cast<float>(scalar);
+
159 
+
160  return result;
+
161 }
Here is the call graph for this function:
@@ -705,21 +711,21 @@ template<typename T >

addition of two vectors of identical lengths

Returns
resultant vector
-
196  {
-
197  // Number of rows in A
-
198  size_t N = A.size();
-
199 
-
200  std::vector<T> result(N);
+
198  {
+
199  // Number of rows in A
+
200  size_t N = A.size();
201 
-
202  if (B.size() != N) {
-
203  std::cerr << "Vector dimensions shouldbe identical!" << std::endl;
-
204  return A;
-
205  }
-
206 
-
207  for (size_t row = 0; row < N; row++) result[row] = A[row] + B[row];
+
202  std::vector<T> result(N);
+
203 
+
204  if (B.size() != N) {
+
205  std::cerr << "Vector dimensions shouldbe identical!" << std::endl;
+
206  return A;
+
207  }
208 
-
209  return result;
-
210 }
+
209  for (size_t row = 0; row < N; row++) result[row] = A[row] + B[row];
+
210 
+
211  return result;
+
212 }
Here is the call graph for this function:
@@ -757,21 +763,21 @@ template<typename T >

subtraction of two vectors of identical lengths

Returns
resultant vector
-
175  {
-
176  // Number of rows in A
-
177  size_t N = A.size();
-
178 
-
179  std::vector<T> result(N);
+
177  {
+
178  // Number of rows in A
+
179  size_t N = A.size();
180 
-
181  if (B.size() != N) {
-
182  std::cerr << "Vector dimensions shouldbe identical!" << std::endl;
-
183  return A;
-
184  }
-
185 
-
186  for (size_t row = 0; row < N; row++) result[row] = A[row] - B[row];
+
181  std::vector<T> result(N);
+
182 
+
183  if (B.size() != N) {
+
184  std::cerr << "Vector dimensions shouldbe identical!" << std::endl;
+
185  return A;
+
186  }
187 
-
188  return result;
-
189 }
+
188  for (size_t row = 0; row < N; row++) result[row] = A[row] - B[row];
+
189 
+
190  return result;
+
191 }
Here is the call graph for this function:
@@ -809,9 +815,9 @@ template<typename T >

division of a vector by a scalar

Returns
resultant vector
-
166  {
-
167  return (1.f / scalar) * A;
-
168 }
+
168  {
+
169  return (1.f / scalar) * A;
+
170 }
@@ -843,19 +849,19 @@ template<typename T >

operator to print a matrix

-
21  {
-
22  const int width = 10;
-
23  const char separator = ' ';
-
24 
-
25  for (size_t row = 0; row < v.size(); row++) {
-
26  for (size_t col = 0; col < v[row].size(); col++)
-
27  out << std::left << std::setw(width) << std::setfill(separator)
-
28  << v[row][col];
-
29  out << std::endl;
-
30  }
-
31 
-
32  return out;
-
33 }
+
23  {
+
24  const int width = 10;
+
25  const char separator = ' ';
+
26 
+
27  for (size_t row = 0; row < v.size(); row++) {
+
28  for (size_t col = 0; col < v[row].size(); col++)
+
29  out << std::left << std::setw(width) << std::setfill(separator)
+
30  << v[row][col];
+
31  out << std::endl;
+
32  }
+
33 
+
34  return out;
+
35 }
Here is the call graph for this function:
@@ -893,16 +899,16 @@ template<typename T >

operator to print a vector

-
39  {
-
40  const int width = 15;
-
41  const char separator = ' ';
-
42 
-
43  for (size_t row = 0; row < v.size(); row++)
-
44  out << std::left << std::setw(width) << std::setfill(separator)
-
45  << v[row];
-
46 
-
47  return out;
-
48 }
+
41  {
+
42  const int width = 15;
+
43  const char separator = ' ';
+
44 
+
45  for (size_t row = 0; row < v.size(); row++)
+
46  out << std::left << std::setw(width) << std::setfill(separator)
+
47  << v[row];
+
48 
+
49  return out;
+
50 }
Here is the call graph for this function:
@@ -950,19 +956,91 @@ template<typename T >
Returns
vector with regression values for each sample
-
342  {
-
343  std::vector<float> result(X.size());
-
344 
-
345  for (size_t rows = 0; rows < X.size(); rows++) {
-
346  // -> start with constant term
-
347  result[rows] = beta[X[0].size()];
-
348  for (size_t cols = 0; cols < X[0].size(); cols++)
-
349  result[rows] += beta[cols] * X[rows][cols];
-
350  }
-
351  // Nx1
-
352  return result;
-
353 }
+
344  {
+
345  std::vector<float> result(X.size());
+
346 
+
347  for (size_t rows = 0; rows < X.size(); rows++) {
+
348  // -> start with constant term
+
349  result[rows] = beta[X[0].size()];
+
350  for (size_t cols = 0; cols < X[0].size(); cols++)
+
351  result[rows] += beta[cols] * X[rows][cols];
+
352  }
+
353  // Nx1
+
354  return result;
+
355 }
+
+
+ +

◆ test()

+ +
+
+ + + + + + + +
void test ()
+
+

Self test checks

+
358  {
+
359  int F = 3, N = 5;
+
360 
+
361  /* test function = x^2 -5 */
+
362  std::cout << "Test 1 (quadratic function)....";
+
363  // create training data set with features = x, x^2, x^3
+ +
365  {{-5, 25, -125}, {-1, 1, -1}, {0, 0, 0}, {1, 1, 1}, {6, 36, 216}});
+
366  // create corresponding outputs
+
367  std::vector<float> Y1({20, -4, -5, -4, 31});
+
368  // perform regression modelling
+
369  std::vector<float> beta1 = fit_OLS_regressor(data1, Y1);
+
370  // create test data set with same features = x, x^2, x^3
+ +
372  {{-2, 4, -8}, {2, 4, 8}, {-10, 100, -1000}, {10, 100, 1000}});
+
373  // expected regression outputs
+
374  std::vector<float> expected1({-1, -1, 95, 95});
+
375  // predicted regression outputs
+ +
377  // compare predicted results are within +-0.01 limit of expected
+
378  for (size_t rows = 0; rows < out1.size(); rows++)
+
379  assert(std::abs(out1[rows] - expected1[rows]) < 0.01);
+
380  std::cout << "passed\n";
+
381 
+
382  /* test function = x^3 + x^2 - 100 */
+
383  std::cout << "Test 2 (cubic function)....";
+
384  // create training data set with features = x, x^2, x^3
+ +
386  {{-5, 25, -125}, {-1, 1, -1}, {0, 0, 0}, {1, 1, 1}, {6, 36, 216}});
+
387  // create corresponding outputs
+
388  std::vector<float> Y2({-200, -100, -100, 98, 152});
+
389  // perform regression modelling
+
390  std::vector<float> beta2 = fit_OLS_regressor(data2, Y2);
+
391  // create test data set with same features = x, x^2, x^3
+ +
393  {{-2, 4, -8}, {2, 4, 8}, {-10, 100, -1000}, {10, 100, 1000}});
+
394  // expected regression outputs
+
395  std::vector<float> expected2({-104, -88, -1000, 1000});
+
396  // predicted regression outputs
+ +
398  // compare predicted results are within +-0.01 limit of expected
+
399  for (size_t rows = 0; rows < out2.size(); rows++)
+
400  assert(std::abs(out2[rows] - expected2[rows]) < 0.01);
+
401  std::cout << "passed\n";
+
402 
+
403  std::cout << std::endl; // ensure test results are displayed on screen
+
404  // (flush stdout)
+
405 }
+
+Here is the call graph for this function:
+
+
+
+
+
@@ -970,17 +1048,20 @@ template<typename T >
STL class.
T size(T... args)
T setfill(T... args)
-
bool is_square(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:55
+
bool is_square(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:57
+
void test()
Definition: ordinary_least_squares_regressor.cpp:358
+
void test1(double eta=0.01)
Definition: adaline_learning.cpp:204
-
std::vector< float > predict_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< float > const &beta)
Definition: ordinary_least_squares_regressor.cpp:340
+
std::vector< float > predict_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< float > const &beta)
Definition: ordinary_least_squares_regressor.cpp:342
int data[MAX]
test data
Definition: hash_search.cpp:24
-
std::vector< float > fit_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< T > const &Y)
Definition: ordinary_least_squares_regressor.cpp:310
+
std::vector< float > fit_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< T > const &Y)
Definition: ordinary_least_squares_regressor.cpp:312
T endl(T... args)
-
std::vector< std::vector< float > > get_inverse(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:218
+
std::vector< std::vector< float > > get_inverse(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:220
T left(T... args)
T setw(T... args)
-
std::vector< std::vector< T > > get_transpose(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:289
+
void test2(double eta=0.01)
Definition: adaline_learning.cpp:238
+
std::vector< std::vector< T > > get_transpose(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:291