Created
May 27, 2012 02:41
-
-
Save sbyrnes/2797087 to your computer and use it in GitHub Desktop.
Implementation of the Normal Equation
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
// FORMULA: theta = pinv(X'*X)*X'*y; | |
function generateTheta(X, y) | |
{ | |
// Get the transpose of X | |
Xt = X.transpose(); | |
// Multiple X by its transpose | |
var Xmain = X.x(Xt); | |
// Get the inverse of the result of multiplying X by its transpose | |
var Xinv = Xmain.inverse(); | |
// Get the transpose of X' times y | |
var Atd = X.x(y); | |
// Theta is the result of the multiplication of both | |
var theta = Xinv.x(Atd); | |
return theta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment