Created
November 18, 2015 19:10
-
-
Save Kaupenjoe/681eb261a7558aa003ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void PolynomRegression::computeAandBandW(void) | |
{ | |
//Temporary Matrices with Dimension of model complexity + 1 | |
knn::matrix tempAE(mE+1, mE+1); | |
knn::matrix tempBE(mE+1, 1); | |
knn::matrix tempWE(mE+1, 1); | |
std::ofstream logFile; | |
logFile.open("log.txt",std::ios::out); | |
for (int k = 0; k <= mE; ++k) | |
{ | |
for (int m = 0; m <= mE; ++m) | |
{ | |
//Fills the Matrix A with xp^k+m | |
for (int p = 1; p < xInE.size(); ++p) | |
{ | |
//k+1 and m+1 as Matrices start at index 1 | |
tempAE.operator()(m+1, k+1) += pow(xInE[p], k + m); //AE(m,k) = xp^k+m | |
logFile << k+1 << " " << m+1 << " " << tempAE.operator()(k + 1, m + 1) << endl; | |
} | |
} | |
for (int p = 1; p < xInE.size(); ++p) | |
{ | |
tempBE.operator()(k+1, 1) += (tInE[p] * pow((xInE[p]), k)); | |
logFile << k+1 << " " << tempBE.operator()(k + 1, 1) << endl; | |
} | |
} | |
AE.operator=(tempAE); | |
bE.operator=(tempBE); | |
//Invert the Matrix | |
AE.invert(); | |
//A^-1 * b = w | Calculates the Weight Matrix with the Inverted Matrix of A | |
tempWE.operator=(AE.operator*(bE)); | |
wE.operator=(tempWE); | |
wE = AE * bE; | |
logFile.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment