From b4faca4a34a59a5c54aafc84be7537b9b6c420b6 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 13 Feb 2023 16:51:00 +0100 Subject: [PATCH] Added MLPPGaussMarkovCheckerOld. --- SCsub | 1 + .../gauss_markov_checker_old.cpp | 60 +++++++++++++++++++ .../gauss_markov_checker_old.h | 33 ++++++++++ 3 files changed, 94 insertions(+) create mode 100644 mlpp/gauss_markov_checker/gauss_markov_checker_old.cpp create mode 100644 mlpp/gauss_markov_checker/gauss_markov_checker_old.h diff --git a/SCsub b/SCsub index b6950d9..9be6f96 100644 --- a/SCsub +++ b/SCsub @@ -77,6 +77,7 @@ sources = [ "mlpp/ann/ann_old.cpp", "mlpp/numerical_analysis/numerical_analysis_old.cpp", "mlpp/regularization/reg_old.cpp", + "mlpp/gauss_markov_checker/gauss_markov_checker_old.cpp", "test/mlpp_tests.cpp", ] diff --git a/mlpp/gauss_markov_checker/gauss_markov_checker_old.cpp b/mlpp/gauss_markov_checker/gauss_markov_checker_old.cpp new file mode 100644 index 0000000..de8f671 --- /dev/null +++ b/mlpp/gauss_markov_checker/gauss_markov_checker_old.cpp @@ -0,0 +1,60 @@ +// +// GaussMarkovChecker.cpp +// +// Created by Marc Melikyan on 11/13/20. +// + +#include "gauss_markov_checker_old.h" +#include "../stat/stat.h" +#include + +void MLPPGaussMarkovCheckerOld::checkGMConditions(std::vector eps) { + bool condition1 = arithmeticMean(eps); + bool condition2 = homoscedasticity(eps); + bool condition3 = exogeneity(eps); + + if (condition1 && condition2 && condition3) { + std::cout << "Gauss-Markov conditions were not violated. You may use OLS to obtain a BLUE estimator" << std::endl; + } else { + std::cout << "A test of the expected value of 0 of the error terms returned " << std::boolalpha << condition1 << ", a test of homoscedasticity has returned " << std::boolalpha << condition2 << ", and a test of exogenity has returned " << std::boolalpha << "." << std::endl; + } +} + +bool MLPPGaussMarkovCheckerOld::arithmeticMean(std::vector eps) { + MLPPStat stat; + if (stat.mean(eps) == 0) { + return true; + } else { + return false; + } +} + +bool MLPPGaussMarkovCheckerOld::homoscedasticity(std::vector eps) { + MLPPStat stat; + real_t currentVar = (eps[0] - stat.mean(eps)) * (eps[0] - stat.mean(eps)) / eps.size(); + for (uint32_t i = 0; i < eps.size(); i++) { + if (currentVar != (eps[i] - stat.mean(eps)) * (eps[i] - stat.mean(eps)) / eps.size()) { + return false; + } + } + + return true; +} + +bool MLPPGaussMarkovCheckerOld::exogeneity(std::vector eps) { + MLPPStat stat; + for (uint32_t i = 0; i < eps.size(); i++) { + for (uint32_t j = 0; j < eps.size(); j++) { + if (i != j) { + if ((eps[i] - stat.mean(eps)) * (eps[j] - stat.mean(eps)) / eps.size() != 0) { + return false; + } + } + } + } + + return true; +} + +void MLPPGaussMarkovCheckerOld::_bind_methods() { +} diff --git a/mlpp/gauss_markov_checker/gauss_markov_checker_old.h b/mlpp/gauss_markov_checker/gauss_markov_checker_old.h new file mode 100644 index 0000000..4b1e52f --- /dev/null +++ b/mlpp/gauss_markov_checker/gauss_markov_checker_old.h @@ -0,0 +1,33 @@ + +#ifndef MLPP_GAUSS_MARKOV_CHECKER_OLD_H +#define MLPP_GAUSS_MARKOV_CHECKER_OLD_H + +// +// GaussMarkovChecker.hpp +// +// Created by Marc Melikyan on 11/13/20. +// + +#include "core/math/math_defs.h" + +#include "core/object/reference.h" + +#include +#include + +class MLPPGaussMarkovCheckerOld : public Reference { + GDCLASS(MLPPGaussMarkovCheckerOld, Reference); + +public: + void checkGMConditions(std::vector eps); + + // Independent, 3 Gauss-Markov Conditions + bool arithmeticMean(std::vector eps); // 1) Arithmetic Mean of 0. + bool homoscedasticity(std::vector eps); // 2) Homoscedasticity + bool exogeneity(std::vector eps); // 3) Cov of any 2 non-equal eps values = 0. + +protected: + static void _bind_methods(); +}; + +#endif /* GaussMarkovChecker_hpp */