comparison linear_regression.py @ 379:74b402b5a81b

small modif by yoshue
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Mon, 07 Jul 2008 12:27:06 -0400
parents c9a89be5cb0a
children efb797c5efc0
comparison
equal deleted inserted replaced
378:835830e52b42 379:74b402b5a81b
86 86
87 class LinearRegressionEquations(LinearPredictorEquations): 87 class LinearRegressionEquations(LinearPredictorEquations):
88 P = LinearPredictorEquations 88 P = LinearPredictorEquations
89 XtX = T.matrix() # (n_inputs+1) x (n_inputs+1) 89 XtX = T.matrix() # (n_inputs+1) x (n_inputs+1)
90 XtY = T.matrix() # (n_inputs+1) x n_outputs 90 XtY = T.matrix() # (n_inputs+1) x n_outputs
91 extended_input = T.prepend_scalar_to_each_row(1,P.inputs) 91 extended_input = T.prepend_scalar_to_each_row(1.,P.inputs)
92 new_XtX = add_inplace(XtX,T.dot(extended_input.T,extended_input)) 92 new_XtX = add_inplace(XtX,T.dot(extended_input.T,extended_input))
93 new_XtY = add_inplace(XtY,T.dot(extended_input.T,P.targets)) 93 new_XtY = add_inplace(XtY,T.dot(extended_input.T,P.targets))
94 94 new_theta = T.Cholesky_solve_inplace(P.theta,XtX,XtY) # solve linear system XtX theta = XtY
95
95 class LinearPredictor(object): 96 class LinearPredictor(object):
96 """ 97 """
97 A linear predictor has parameters theta (a bias vector and a weight matrix) 98 A linear predictor has parameters theta (a bias vector and a weight matrix)
98 it can use to make a linear prediction (according to the LinearPredictorEquations). 99 it can use to make a linear prediction (according to the LinearPredictorEquations).
99 It can compute its output (bias + weight * input) and a squared error (||output - target||^2). 100 It can compute its output (bias + weight * input) and a squared error (||output - target||^2).