本文整理汇总了C++中UpperTriangularMatrix::t方法的典型用法代码示例。如果您正苦于以下问题:C++ UpperTriangularMatrix::t方法的具体用法?C++ UpperTriangularMatrix::t怎么用?C++ UpperTriangularMatrix::t使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UpperTriangularMatrix
的用法示例。
在下文中一共展示了UpperTriangularMatrix::t方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeCovariance
void NonLinearLeastSquares::MakeCovariance()
{
if (Covariance.Nrows()==0)
{
UpperTriangularMatrix UI = U.i();
Covariance << UI * UI.t() * errorvar;
SE << Covariance; // get diagonals
for (int i = 1; i<=n_param; i++) SE(i) = sqrt(SE(i));
}
}
示例2: downdate_Cholesky
// produces the Cholesky decomposition of A - x.t() * x where A = chol.t() * chol
void downdate_Cholesky(UpperTriangularMatrix &chol, RowVector x)
{
int nRC = chol.Nrows();
// solve R^T a = x
LowerTriangularMatrix L = chol.t();
ColumnVector a(nRC); a = 0.0;
int i, j;
for (i = 1; i <= nRC; ++i)
{
// accumulate subtr sum
Real subtrsum = 0.0;
for(int k = 1; k < i; ++k) subtrsum += a(k) * L(i,k);
a(i) = (x(i) - subtrsum) / L(i,i);
}
// test that l2 norm of a is < 1
Real squareNormA = a.SumSquare();
if (squareNormA >= 1.0)
Throw(ProgramException("downdate_Cholesky() fails", chol));
Real alpha = sqrt(1.0 - squareNormA);
// compute and apply Givens rotations to the vector a
ColumnVector cGivens(nRC); cGivens = 0.0;
ColumnVector sGivens(nRC); sGivens = 0.0;
for(i = nRC; i >= 1; i--)
alpha = pythag(alpha, a(i), cGivens(i), sGivens(i));
// apply Givens rotations to the jth column of chol
ColumnVector xtilde(nRC); xtilde = 0.0;
for(j = nRC; j >= 1; j--)
{
// only the first j rotations have an affect on chol,0
for(int k = j; k >= 1; k--)
GivensRotation(cGivens(k), -sGivens(k), chol(k,j), xtilde(j));
}
}
示例3: test4
void test4(Real* y, Real* x1, Real* x2, int nobs, int npred)
{
cout << "\n\nTest 4 - QR triangularisation\n";
// QR triangularisation method
// load data - 1s into col 1 of matrix
int npred1 = npred+1;
Matrix X(nobs,npred1); ColumnVector Y(nobs);
X.Column(1) = 1.0; X.Column(2) << x1; X.Column(3) << x2; Y << y;
// do Householder triangularisation
// no need to deal with constant term separately
Matrix X1 = X; // Want copy of matrix
ColumnVector Y1 = Y;
UpperTriangularMatrix U; ColumnVector M;
QRZ(X1, U); QRZ(X1, Y1, M); // Y1 now contains resids
ColumnVector A = U.i() * M;
ColumnVector Fitted = X * A;
Real ResVar = Y1.SumSquare() / (nobs-npred1);
// get variances of estimates
U = U.i(); DiagonalMatrix D; D << U * U.t();
// Get diagonals of Hat matrix
DiagonalMatrix Hat; Hat << X1 * X1.t();
// print out answers
cout << "\nEstimates and their standard errors\n\n";
ColumnVector SE(npred1);
for (int i=1; i<=npred1; i++) SE(i) = sqrt(D(i)*ResVar);
cout << setw(11) << setprecision(5) << (A | SE) << endl;
cout << "\nObservations, fitted value, residual value, hat value\n";
cout << setw(9) << setprecision(3) <<
(X.Columns(2,3) | Y | Fitted | Y1 | Hat.AsColumn());
cout << "\n\n";
}