def get_coef(self, X):
qr, qraux = self.qr, self.qraux
n, p = qr.shape
# sanity check
assert isinstance(qr, np.ndarray), 'internal error: QR should be a np.ndarray but got %s' % type(qr)
assert isinstance(qraux, np.ndarray), 'internal error: qraux should be a np.ndarray but got %s' % type(qraux)
# validate input array
X = check_array(X, dtype='numeric', copy=True, order='F')
nx, ny = X.shape
if nx != n:
raise ValueError('qr and X must have same number of rows')
# check on size
_validate_matrix_size(n, p)
# get the rank of the decomposition
k = self.rank
# get ix vector
# if p > n:
# ix = np.ones(n + (p - n)) * np.nan
# ix[:n] = np.arange(n) # i.e., array([0,1,2,nan,nan,nan])
# else:
# ix = np.arange(n)
# set up the structures to alter
coef, info = (np.zeros((k, ny), dtype=np.double, order='F'),
np.zeros(1, dtype=np.int, order='F'))
# call the fortran module IN PLACE
_safecall(dqrsl.dqrcf, qr, n, k, qraux, X, ny, coef, 0)
# post-processing
# if k < p:
# cf = np.ones((p,ny)) * np.nan
# cf[self.pivot[np.arange(k)], :] = coef
return coef if not k < p else coef[self.pivot[np.arange(k)], :]
评论列表
文章目录