#NEWLINE# def initialize( self ) : #NEWLINE# #INDENT# S = sum ( [ np . dot ( unit . X . T , unit . X ) for unit in self . units ] ) #NEWLINE# Y = sum ( [ np . dot ( unit . X . T , unit . Y ) for unit in self . units ] ) #NEWLINE# self . a = L . lstsq ( S , Y ) [ 0 ] #NEWLINE# D = 0 #NEWLINE# t = 0 #NEWLINE# sigmasq = 0 #NEWLINE# for unit in self . units : #NEWLINE# #INDENT# unit . r = ( unit . Y - np . dot ( unit . X , self . a ) ) #NEWLINE# if ( self . q > 1 ) : #NEWLINE# #INDENT# unit . b = L . lstsq ( unit . Z , unit . r ) [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# Z = unit . Z . reshape ( ( unit . Z . shape [ 0 ] , 1 ) ) #NEWLINE# unit . b = L . lstsq ( Z , D . r ) [ 0 ] #NEWLINE# #UNINDENT# sigmasq += ( ( np . power ( unit . Y , 2 ) . sum ( ) - ( self . a * np . dot ( unit . X . T , unit . Y ) ) . sum ( ) ) - ( unit . b * np . dot ( unit . Z . T , unit . r ) ) . sum ( ) ) #NEWLINE# D += np . multiply . outer ( unit . b , unit . b ) #NEWLINE# t += L . pinv ( np . dot ( unit . Z . T , unit . Z ) ) #NEWLINE# #UNINDENT# self . df_resid = ( ( self . N - ( ( self . m - 1 ) * self . q ) ) - self . p ) #NEWLINE# sigmasq /= ( ( self . N - ( ( self . m - 1 ) * self . q ) ) - self . p ) #NEWLINE# self . sigma = np . sqrt ( sigmasq ) #NEWLINE# self . D = ( ( D - ( sigmasq * t ) ) / self . m )