亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? example.cpp

?? 非常好用的用C編寫的矩陣類,可在不同編譯器下編譯使用.
?? CPP
字號:
/// \ingroup newmat
///@{

/// \file example.cpp
/// Example of use of matrix package.
/// Carry out a simple regression analysis using a number of different methods
/// to illustrate matrix manipulation, solving equations,
/// Cholesky decomposition, QR decomposition, Singular Value decomposition.


#define WANT_STREAM                  // include.h will get stream fns
#define WANT_MATH                    // include.h will get math fns
                                     // newmatap.h will get include.h

#include "newmatap.h"                // need matrix applications

#include "newmatio.h"                // need matrix output routines

#ifdef use_namespace
using namespace NEWMAT;              // access NEWMAT namespace
#endif


// demonstration of matrix package on linear regression problem


void test1(Real* y, Real* x1, Real* x2, int nobs, int npred)
{
   cout << "\n\nTest 1 - traditional, bad\n";

   // traditional sum of squares and products method of calculation
   // but not adjusting means; maybe subject to round-off error

   // make matrix of predictor values with 1s into col 1 of matrix
   int npred1 = npred+1;        // number of cols including col of ones.
   Matrix X(nobs,npred1);
   X.column(1) = 1.0;

   // load x1 and x2 into X
   //    [use << rather than = when loading arrays]
   X.column(2) << x1;  X.column(3) << x2;

   // vector of Y values
   ColumnVector Y(nobs); Y << y;

   // form sum of squares and product matrix
   //    [use << rather than = for copying Matrix into SymmetricMatrix]
   SymmetricMatrix SSQ; SSQ << X.t() * X;

   // calculate estimate
   //    [bracket last two terms to force this multiplication first]
   //    [ .i() means inverse, but inverse is not explicity calculated]
   ColumnVector A = SSQ.i() * (X.t() * Y);

   // Get variances of estimates from diagonal elements of inverse of SSQ
   // get inverse of SSQ - we need it for finding D
   DiagonalMatrix D; D << SSQ.i();
   ColumnVector V = D.as_column();

   // Calculate fitted values and residuals
   ColumnVector Fitted = X * A;
   ColumnVector Residual = Y - Fitted;
   Real ResVar = sum_square(Residual) / (nobs-npred1);

   // Get diagonals of Hat matrix (an expensive way of doing this)
   DiagonalMatrix Hat;  Hat << X * (X.t() * X).i() * X.t();

   // print out answers
   cout << "\nEstimates and their standard errors\n\n";

   // make vector of standard errors
   ColumnVector SE(npred1);
   for (int i=1; i<=npred1; i++) SE(i) = sqrt(V(i)*ResVar);
   // use concatenation function to form matrix and use matrix print
   // to get two columns
   cout << setw(11) << setprecision(5) << (A | SE) << endl;

   cout << "\nObservations, fitted value, residual value, hat value\n";

   // use concatenation again; select only columns 2 to 3 of X
   cout << setw(9) << setprecision(3) <<
     (X.columns(2,3) | Y | Fitted | Residual | Hat.as_column());
   cout << "\n\n";
}

void test2(Real* y, Real* x1, Real* x2, int nobs, int npred)
{
   cout << "\n\nTest 2 - traditional, OK\n";

   // traditional sum of squares and products method of calculation
   // with subtraction of means - less subject to round-off error
   // than test1

   // make matrix of predictor values
   Matrix X(nobs,npred);

   // load x1 and x2 into X
   //    [use << rather than = when loading arrays]
   X.column(1) << x1;  X.column(2) << x2;

   // vector of Y values
   ColumnVector Y(nobs); Y << y;

   // make vector of 1s
   ColumnVector Ones(nobs); Ones = 1.0;

   // calculate means (averages) of x1 and x2 [ .t() takes transpose]
   RowVector M = X.sum_columns() / nobs;

   // and subtract means from x1 and x2
   Matrix XC(nobs,npred);
   XC = X - Ones * M;

   // do the same to Y [use sum to get sum of elements]
   ColumnVector YC(nobs);
   Real m = sum(Y) / nobs;  YC = Y - Ones * m;

   // form sum of squares and product matrix
   //    [use << rather than = for copying Matrix into SymmetricMatrix]
   SymmetricMatrix SSQ; SSQ << XC.t() * XC;

   // calculate estimate
   //    [bracket last two terms to force this multiplication first]
   //    [ .i() means inverse, but inverse is not explicity calculated]
   ColumnVector A = SSQ.i() * (XC.t() * YC);

   // calculate estimate of constant term
   //    [AsScalar converts 1x1 matrix to Real]
   Real a = m - (M * A).as_scalar();

   // Get variances of estimates from diagonal elements of inverse of SSQ
   //    [ we are taking inverse of SSQ - we need it for finding D ]
   Matrix ISSQ = SSQ.i(); DiagonalMatrix D; D << ISSQ;
   ColumnVector V = D.AsColumn();
   Real v = 1.0/nobs + (M * ISSQ * M.t()).as_scalar();
					    // for calc variance of const

   // Calculate fitted values and residuals
   int npred1 = npred+1;
   ColumnVector Fitted = X * A + a;
   ColumnVector Residual = Y - Fitted;
   Real ResVar = sum_square(Residual) / (nobs-npred1);

   // Get diagonals of Hat matrix (an expensive way of doing this)
   Matrix X1(nobs,npred1); X1.column(1)<<Ones; X1.columns(2,npred1)<<X;
   DiagonalMatrix Hat;  Hat << X1 * (X1.t() * X1).i() * X1.t();

   // print out answers
   cout << "\nEstimates and their standard errors\n\n";
   cout.setf(ios::fixed, ios::floatfield);
   cout << setw(11) << setprecision(5)  << a << " ";
   cout << setw(11) << setprecision(5)  << sqrt(v*ResVar) << endl;
   // make vector of standard errors
   ColumnVector SE(npred);
   for (int i=1; i<=npred; i++) SE(i) = sqrt(V(i)*ResVar);
   // use concatenation function to form matrix and use matrix print
   // to get two columns
   cout << setw(11) << setprecision(5) << (A | SE) << endl;
   cout << "\nObservations, fitted value, residual value, hat value\n";
   cout << setw(9) << setprecision(3) <<
     (X | Y | Fitted | Residual | Hat.as_column());
   cout << "\n\n";
}

void test3(Real* y, Real* x1, Real* x2, int nobs, int npred)
{
   cout << "\n\nTest 3 - Cholesky\n";

   // traditional sum of squares and products method of calculation
   // with subtraction of means - using Cholesky decomposition

   Matrix X(nobs,npred);
   X.column(1) << x1;  X.column(2) << x2;
   ColumnVector Y(nobs); Y << y;
   RowVector M = X.sum_columns() / nobs;
   Matrix XC(nobs,npred);
   ColumnVector Ones(nobs); Ones = 1.0;
   XC = X - Ones * M;
   ColumnVector YC(nobs);
   Real m = sum(Y) / nobs;  YC = Y - Ones * m;
   SymmetricMatrix SSQ; SSQ << XC.t() * XC;

   // Cholesky decomposition of SSQ
   LowerTriangularMatrix L = Cholesky(SSQ);

   // calculate estimate
   ColumnVector A = L.t().i() * (L.i() * (XC.t() * YC));

   // calculate estimate of constant term
   Real a = m - (M * A).AsScalar();

   // Get variances of estimates from diagonal elements of invoice of SSQ
   DiagonalMatrix D; D << L.t().i() * L.i();
   ColumnVector V = D.as_column();
   Real v = 1.0/nobs + sum_square(L.i() * M.t());

   // Calculate fitted values and residuals
   int npred1 = npred+1;
   ColumnVector Fitted = X * A + a;
   ColumnVector Residual = Y - Fitted;
   Real ResVar = sum_square(Residual) / (nobs-npred1);

   // Get diagonals of Hat matrix (an expensive way of doing this)
   Matrix X1(nobs,npred1); X1.column(1)<<Ones; X1.columns(2,npred1)<<X;
   DiagonalMatrix Hat;  Hat << X1 * (X1.t() * X1).i() * X1.t();

   // print out answers
   cout << "\nEstimates and their standard errors\n\n";
   cout.setf(ios::fixed, ios::floatfield);
   cout << setw(11) << setprecision(5)  << a << " ";
   cout << setw(11) << setprecision(5)  << sqrt(v*ResVar) << endl;
   ColumnVector SE(npred);
   for (int i=1; i<=npred; i++) SE(i) = sqrt(V(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 | Y | Fitted | Residual | Hat.as_column());
   cout << "\n\n";
}

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 = sum_square(Y1) / (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.as_column());
   cout << "\n\n";
}

void test5(Real* y, Real* x1, Real* x2, int nobs, int npred)
{
   cout << "\n\nTest 5 - singular value\n";

   // Singular value decomposition 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 SVD
   Matrix U, V; DiagonalMatrix D;
   SVD(X,D,U,V);                              // X = U * D * V.t()
   ColumnVector Fitted = U.t() * Y;
   ColumnVector A = V * ( D.i() * Fitted );
   Fitted = U * Fitted;
   ColumnVector Residual = Y - Fitted;
   Real ResVar = sum_square(Residual) / (nobs-npred1);

   // get variances of estimates
   D << V * (D * D).i() * V.t();

   // Get diagonals of Hat matrix
   DiagonalMatrix Hat;  Hat << U * U.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 | Residual | Hat.as_column());
   cout << "\n\n";
}

int main()
{
   cout << "\nDemonstration of Matrix package\n";
   cout << "\nPrint a real number (may help lost memory test): " << 3.14159265 << "\n";

   // Test for any memory not deallocated after running this program
   Real* s1; { ColumnVector A(8000); s1 = A.data(); }

   {
      // the data

      Real y[]  = { 8.3, 5.5, 8.0, 8.5, 5.7, 4.4, 6.3, 7.9, 9.1 };
      Real x1[] = { 2.4, 1.8, 2.4, 3.0, 2.0, 1.2, 2.0, 2.7, 3.6 };
      Real x2[] = { 1.7, 0.9, 1.6, 1.9, 0.5, 0.6, 1.1, 1.0, 0.5 };


      int nobs = 9;                           // number of observations
      int npred = 2;                          // number of predictor values

      // we want to find the values of a,a1,a2 to give the best
      // fit of y[i] with a0 + a1*x1[i] + a2*x2[i]
      // Also print diagonal elements of hat matrix, X*(X.t()*X).i()*X.t()

      // this example demonstrates five methods of calculation

      Try
      {
         test1(y, x1, x2, nobs, npred);
         test2(y, x1, x2, nobs, npred);
         test3(y, x1, x2, nobs, npred);
         test4(y, x1, x2, nobs, npred);
         test5(y, x1, x2, nobs, npred);
      }
      CatchAll { cout << BaseException::what(); }
   }

#ifdef DO_FREE_CHECK
   FreeCheck::Status();
#endif
   Real* s2; { ColumnVector A(8000); s2 = A.data(); }
   cout << "\n\nThe following test does not work with all compilers - see documentation\n";
   cout << "Checking for lost memory: "
      << (unsigned long)s1 << " " << (unsigned long)s2 << " ";
   if (s1 != s2) cout << " - see section 2.8\n"; else cout << " - ok\n";

   return 0;

}


///@}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区在线中文字幕| 在线不卡免费av| 欧美激情一区二区在线| 乱一区二区av| 日韩三级视频在线看| 日本网站在线观看一区二区三区 | www.激情成人| 国产亚洲午夜高清国产拍精品| 免费的国产精品| 欧美在线观看你懂的| 亚洲伦理在线精品| 色婷婷激情久久| 亚洲午夜精品17c| 在线精品国精品国产尤物884a| 亚洲欧美日韩久久| 欧美色视频在线| 日韩精品电影在线观看| 91久久精品国产91性色tv| 亚洲欧美另类图片小说| 91国偷自产一区二区开放时间| 一区二区三区在线视频免费| 欧美午夜电影在线播放| 午夜电影久久久| 91精品国产综合久久久久久| 日本不卡视频在线观看| 日韩一区二区在线观看视频| 国产乱子轮精品视频| 中文字幕精品综合| 色婷婷亚洲精品| 日本伊人色综合网| 国产性天天综合网| 一本大道久久a久久精品综合| 亚洲一区二区三区四区在线| 欧美一区二区在线视频| 国产精品69毛片高清亚洲| 国产精品国产三级国产普通话蜜臀 | 91福利在线免费观看| 午夜欧美大尺度福利影院在线看| 日韩精品一区二区三区在线| 成人高清免费观看| 午夜影院在线观看欧美| 久久综合九色综合欧美亚洲| 99国产麻豆精品| 久久成人久久爱| 国产精品麻豆久久久| 欧美日韩夫妻久久| 国产美女久久久久| 一区二区视频在线| 欧美一级黄色大片| 在线观看日韩国产| av资源网一区| 高清不卡在线观看| 老司机午夜精品99久久| 亚洲一二三四在线观看| 1000部国产精品成人观看| 久久婷婷一区二区三区| 亚洲色图20p| 久久久精品中文字幕麻豆发布| 欧美日韩精品一区二区三区四区 | 91精品国产一区二区| 一本一本大道香蕉久在线精品| 国产精品一级黄| 久久成人18免费观看| 日韩高清在线电影| 亚洲超丰满肉感bbw| 亚洲最大成人网4388xx| 亚洲美女屁股眼交| ...xxx性欧美| 最新不卡av在线| 最新国产精品久久精品| 中文字幕亚洲精品在线观看| 国产精品网站在线观看| 国产欧美日韩激情| 国产亚洲精品免费| 欧美激情一区二区三区全黄| 国产亚洲欧美色| 日本一区二区三区电影| 国产精品卡一卡二卡三| 国产精品国产三级国产aⅴ无密码| 国产欧美日本一区二区三区| 日本一区二区三级电影在线观看| 国产欧美日韩中文久久| 国产精品毛片a∨一区二区三区| 中文字幕不卡在线观看| 亚洲色图清纯唯美| 亚洲国产成人精品视频| 日本中文一区二区三区| 国内精品伊人久久久久av一坑| 韩国成人福利片在线播放| 国产一区二区在线影院| 成人动漫视频在线| 欧美激情艳妇裸体舞| 中文文精品字幕一区二区| 亚洲视频在线一区观看| 一区二区三区精密机械公司| 日韩极品在线观看| 韩国av一区二区| 91在线视频播放| 欧美日韩亚洲综合在线| 精品欧美一区二区久久| 中文字幕第一区综合| 玉足女爽爽91| 日韩精品1区2区3区| 国产成人综合在线播放| 91啪在线观看| 91精品国产91热久久久做人人| 欧美变态tickling挠脚心| 国产欧美精品一区| 亚洲地区一二三色| 精品一区二区三区的国产在线播放| 国产在线播精品第三| 97久久精品人人做人人爽50路 | 日韩中文字幕91| 国产一区在线视频| 色综合天天综合网国产成人综合天 | 欧美日韩亚洲国产综合| 欧美一级日韩一级| 国产精品二三区| 青青草国产精品亚洲专区无| 日韩一区二区三区免费看| 中日韩av电影| 麻豆精品在线视频| 91丨九色丨国产丨porny| 欧美电影免费观看高清完整版在线| 国产精品久久毛片av大全日韩| 日韩综合小视频| av中文字幕在线不卡| 精品国产露脸精彩对白| 一区二区三区四区不卡在线| 国产精品伊人色| 777亚洲妇女| 亚洲黄色小视频| 丁香婷婷综合网| 亚洲精品一区二区三区蜜桃下载| 一片黄亚洲嫩模| jiyouzz国产精品久久| 日韩一区二区在线观看视频| 一区二区理论电影在线观看| 国产成人超碰人人澡人人澡| 67194成人在线观看| 亚洲精品久久久久久国产精华液| 国产精品一二三四区| 日韩一区二区电影在线| 亚洲午夜私人影院| 色婷婷综合久久久中文字幕| 欧美韩国日本综合| 国产精华液一区二区三区| 日韩一区二区三区视频| 亚洲成人久久影院| 色狠狠色噜噜噜综合网| 中文字幕免费不卡在线| 国产精品一区二区三区四区| 欧美一区二区在线看| 亚洲成人中文在线| 在线观看精品一区| 最新热久久免费视频| 成人精品国产一区二区4080| 久久婷婷久久一区二区三区| 精品在线视频一区| 日韩免费视频线观看| 青青草精品视频| 日韩丝袜美女视频| 日韩中文字幕1| 日韩一区二区中文字幕| 日av在线不卡| 精品噜噜噜噜久久久久久久久试看| 天天操天天干天天综合网| 欧美性受xxxx| 日韩av二区在线播放| 91精品国产麻豆| 久久 天天综合| 久久久噜噜噜久噜久久综合| 国产精品18久久久久久久久 | 欧美群妇大交群的观看方式| 亚洲bt欧美bt精品777| 欧美男男青年gay1069videost| 伊人婷婷欧美激情| 欧美日韩成人一区| 老司机精品视频导航| 久久久蜜臀国产一区二区| 国产福利一区二区三区视频在线| 国产拍欧美日韩视频二区| 99视频在线精品| 亚洲另类中文字| 91精品国产乱码| 国产主播一区二区三区| 国产精品妹子av| 欧美色中文字幕| 久久国产麻豆精品| 欧美国产一区二区在线观看 | 欧美视频你懂的| 久久精品国产澳门| 国产精品理论片| 欧美日高清视频| 国产精品69毛片高清亚洲| 亚洲人成精品久久久久| 制服丝袜一区二区三区| 国产精品12区| 午夜精品久久久久久久蜜桃app| 精品粉嫩超白一线天av|