权重矩阵

回归就是求矩阵系数,那么一个这样的矩阵表达式:X*A=Y,如何求系数矩阵A呢,两边同时乘以X转置,得X‘*X*A=X’*Y;那么在下一步两边同时乘以X‘*X的逆得到,
A = inv(X' * X) * X' * Y    ,这里是为了防止 矩阵X不满秩,所以先乘以一个转秩  

function [Bw, Ui] = dopWeightBasis(B, W)
%
% Purpose : This function generates a discrete orthogonal weighted  
%           basis from a unitary basis function set. The weightings must
%           either be a vector w or a matrix W. In the case of a vector of
%           weighty they are used as the diagonal of the weighting matrix
%           i.e. W = diag(w);
%
% Use (syntax):
%       Pw = generateWeightedPoly(noPoints, degree, weights);
%
% Input Parameters :
%       B: A unitary basis set from which the weighted basis functions ar
%       eto be generated
%       W: the weights which must be the same length as the number of
%       points.
%
% Return Parameters :
%       Bw: the weighted polynomial basis.
%       Ui: The post multiplying matrix which einsures Bw = B * Ui
%
% Description and algorithms:
%       This algorith is based on a method developed by Paul O'Leary and
%       Matthew Harker.
%
% References : "Savitzky-Golay Smoothing for Multivariate Cyclic
% Measurement Data", Paul O'Leary, Matthew Harker and Richard Neumayr,
% Submitted to the National Indian Conference on Graphics and Computer
% Vision 2010, Jaipur India.
%
% Author :  Paul O'Leary
% Date :    15. Sept 2009
% Version : 1.0
%
% (c) 2009 Paul O'Leary, Chair of Automation, University of Leoben, Leoben, Austria
% email: [email protected], url: automation.unileoben.ac.at
%
% History:
%   Date:           Comment:
%   15. Sept        Original version
%
%--------------------------------------------------------
%

% if a vector of weights is delivered then generate the seighting matrix
if isvector(W)
    factor = 10;
    if ( min( W ) / max(W) )<= factor*eps
        error('The weighting vector must be positive definite.');
    end;
    W = diag( W );
end;
%
% test the inputs for correctness
%
[nW, mW] = size( W );
%
if ~(nW == mW)
    error('The weigthing matrix must be square');
end;
%
try
    % test if W is positive definite
    chol(W);
catch me
    error('The weighting matrix W must be positive semi definite');
end;
%
[nB, mB] = size( B );
if ~(nB == nW)
    error('The dimensions of the basis function matrix B and W are not consistent');
end;
%---------------------------------------------------------------
% Do the necessary computations to generate the weighted basis.
%
U = chol(B' * W * B);
Ui = inv( U );
%
Bw = B * Ui;

你可能感兴趣的:(权重矩阵)