diff --git a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.map b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.map index cee9012ba..543159b7c 100644 --- a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.map +++ b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.map @@ -1,4 +1,4 @@ - + diff --git a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.md5 b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.md5 index 722ec6c02..7af9c75ee 100644 --- a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.md5 +++ b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.md5 @@ -1 +1 @@ -868ad72095fe395df7c4d0862a42dea5 \ No newline at end of file +aeca54c7c366fb2ba509eb865c3e6b19 \ 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 35a9f8d32..1f68ce594 100644 --- a/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.svg +++ b/d1/d4b/ordinary__least__squares__regressor_8cpp__incl.svg @@ -3,18 +3,18 @@ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> - + -numerical_methods/ordinary_least_squares_regressor.cpp +machine_learning/ordinary_least_squares_regressor.cpp Node1 -numerical_methods/ordinary +machine_learning/ordinary _least_squares_regressor.cpp diff --git a/d4/d68/qr__decompose_8h_source.html b/d4/d68/qr__decompose_8h_source.html index d8661d5d3..23034d7f4 100644 --- a/d4/d68/qr__decompose_8h_source.html +++ b/d4/d68/qr__decompose_8h_source.html @@ -312,27 +312,19 @@ $(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h_source.html','
#define MAX_ITERATIONS
Maximum number of iterations to check.
Definition: newton_raphson_method.cpp:21
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::vector< T > operator+(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:198
static double eq(double i)
Definition: newton_raphson_method.cpp:29
T cos(T... args)
static double eq_der(double i)
Definition: newton_raphson_method.cpp:39
void exact_solution(const double &x, std::valarray< double > *y)
Exact solution of the problem. Used for solution comparison.
Definition: ode_forward_euler.cpp:67
T atof(T... args)
-
STL class.
-
T size(T... args)
int main(int argc, char *argv[])
Definition: ode_forward_euler.cpp:188
T setfill(T... args)
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
-
bool is_square(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:57
T sqrt(T... args)
Functions to compute QR decomposition of any rectangular matrix.
-
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
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
-
void test()
Definition: ordinary_least_squares_regressor.cpp:358
T clock(T... args)
-
std::ostream & operator<<(std::ostream &out, std::vector< std::vector< T >> const &v)
Definition: ordinary_least_squares_regressor.cpp:22
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
-
void test1(double eta=0.01)
Definition: adaline_learning.cpp:204
std::valarray< T > vector_proj(const std::valarray< T > &a, const std::valarray< T > &b)
Definition: qr_decompose.h:104
STL class.
@@ -340,8 +332,6 @@ $(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h_source.html','
T close(T... args)
T perror(T... args)
STL class.
-
int main()
Definition: ordinary_least_squares_regressor.cpp:410
-
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
T open(T... args)
std::ostream & operator<<(std::ostream &out, std::valarray< std::valarray< T >> const &v)
Definition: qr_decompose.h:33
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
@@ -350,13 +340,9 @@ $(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h_source.html','
T sin(T... args)
#define EPSILON
system accuracy limit
Definition: newton_raphson_method.cpp:20
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
-
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:312
-
std::vector< T > operator-(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:177
T endl(T... args)
-
std::vector< std::vector< float > > get_inverse(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:220
double vector_dot(const std::valarray< T > &a, const std::valarray< T > &b)
Definition: qr_decompose.h:76
-
T left(T... args)
+
T right(T... args)
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
int main()
Definition: newton_raphson_method.cpp:44
double midpoint_euler(double dx, double x0, double x_max, std::valarray< double > *y, bool save_to_file=false)
Compute approximation using the midpoint-Euler method in the given limits.
Definition: ode_midpoint_euler.cpp:107
@@ -368,14 +354,11 @@ $(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h_source.html','
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
T setw(T... args)
-
void test2(double eta=0.01)
Definition: adaline_learning.cpp:238
T is_open(T... args)
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
-
std::vector< float > operator/(std::vector< T > const &A, float const scalar)
Definition: ordinary_least_squares_regressor.cpp:168
int main(int argc, char *argv[])
Definition: ode_midpoint_euler.cpp:192
T pow(T... args)
-
std::vector< std::vector< T > > get_transpose(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:291

main function

410  {
-
411  test();
+
411  ols_test();
412 
413  size_t N, F;
414 
@@ -460,7 +460,79 @@ template<typename T >
Here is the call graph for this function:
-
+
+
+
+ +
+ + +

◆ ols_test()

+ +
+
+ + + + + + + +
void ols_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
+
371  std::vector<std::vector<float>> test_data1(
+
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
+
376  std::vector<float> out1 = predict_OLS_regressor(test_data1, beta1);
+
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
+
392  std::vector<std::vector<float>> test_data2(
+
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
+
397  std::vector<float> out2 = predict_OLS_regressor(test_data2, beta2);
+
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:
+
+
@@ -969,78 +1041,6 @@ template<typename T >
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:
-
-
-
-
-
@@ -1049,8 +1049,6 @@ Here is the call graph for this function:
T size(T... args)
T setfill(T... args)
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:342
int data[MAX]
test data
Definition: hash_search.cpp:24
@@ -1058,14 +1056,14 @@ Here is the call graph for this function:
T endl(T... args)
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)
+
void ols_test()
Definition: ordinary_least_squares_regressor.cpp:358
T setw(T... args)
-
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