pmlpp/gauss_markov_checker/gauss_markov_checker.cpp

87 lines
3.7 KiB
C++
Raw Normal View History

2023-12-30 00:41:59 +01:00
/*************************************************************************/
/* gauss_markov_checker.cpp */
/*************************************************************************/
/* This file is part of: */
/* PMLPP Machine Learning Library */
/* https://github.com/Relintai/pmlpp */
/*************************************************************************/
2023-12-30 00:43:39 +01:00
/* Copyright (c) 2023-present Péter Magyar. */
2023-12-30 00:41:59 +01:00
/* Copyright (c) 2022-2023 Marc Melikyan */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
2023-01-24 18:12:23 +01:00
#include "gauss_markov_checker.h"
#include "../stat/stat.h"
#include <iostream>
2023-04-22 17:17:58 +02:00
/*
2023-01-27 13:01:16 +01:00
void MLPPGaussMarkovChecker::checkGMConditions(std::vector<real_t> eps) {
2023-01-24 19:00:54 +01:00
bool condition1 = arithmeticMean(eps);
bool condition2 = homoscedasticity(eps);
bool condition3 = exogeneity(eps);
2023-01-24 19:00:54 +01:00
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;
}
}
2023-01-27 13:01:16 +01:00
bool MLPPGaussMarkovChecker::arithmeticMean(std::vector<real_t> eps) {
MLPPStat stat;
2023-01-24 19:00:54 +01:00
if (stat.mean(eps) == 0) {
return true;
2023-01-24 19:00:54 +01:00
} else {
return false;
2023-01-24 19:00:54 +01:00
}
}
2023-01-27 13:01:16 +01:00
bool MLPPGaussMarkovChecker::homoscedasticity(std::vector<real_t> eps) {
MLPPStat stat;
2023-01-27 13:01:16 +01:00
real_t currentVar = (eps[0] - stat.mean(eps)) * (eps[0] - stat.mean(eps)) / eps.size();
for (uint32_t i = 0; i < eps.size(); i++) {
2023-01-24 19:00:54 +01:00
if (currentVar != (eps[i] - stat.mean(eps)) * (eps[i] - stat.mean(eps)) / eps.size()) {
return false;
2023-01-24 19:00:54 +01:00
}
}
return true;
2023-01-24 19:00:54 +01:00
}
2023-01-27 13:01:16 +01:00
bool MLPPGaussMarkovChecker::exogeneity(std::vector<real_t> eps) {
MLPPStat stat;
for (uint32_t i = 0; i < eps.size(); i++) {
for (uint32_t j = 0; j < eps.size(); j++) {
2023-01-24 19:00:54 +01:00
if (i != j) {
if ((eps[i] - stat.mean(eps)) * (eps[j] - stat.mean(eps)) / eps.size() != 0) {
return false;
2023-01-24 19:00:54 +01:00
}
}
}
}
return true;
}
2023-04-22 17:17:58 +02:00
*/
2023-01-24 19:20:18 +01:00
void MLPPGaussMarkovChecker::_bind_methods() {
}