1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <Eigen/Dense>
#include <iostream>
#include <string>
using namespace std;
using namespace Eigen;
main(){
bool varIn[3];
varIn[0]=true;
varIn[1]=true;
varIn[2]=false;
bool varIn1[3];
varIn1[0]=true;
varIn1[1]=true;
varIn1[2]=false;
//(Actually, varIn1=varIn, I do not know how to define varIn1=varIn)
MatrixXd X1(20,4);
MatrixXd Xf(20,3);
MatrixXd d(20,1);
MatrixXd X0(20,3);
MatrixXd Y(20,1);
MatrixXd X(20,1);
MatrixXd b(20,1);
int n = X1.rows();
int nR = n-X0.cols(); // degree of freedom for Reduced model
int nF=nR-1; // degree of freedom for Full model
double RSSr; // Residual Sum of Sqarues for Reduced model
double RSSf; // Residual Sum of Sqarues for Full model
double F_value;
X1 << 1,1,0,0
,1,1,0,0
,1,1,0,0
,1,1,0,0
,1,1,0,0
,1,0,2,0
,1,0,2,0
,1,0,2,0
,1,0,2,0
,1,0,2,0
,1,0,0,3
,1,0,0,3
,1,0,0,3
,1,0,0,3
,1,0,0,3
,1,0,0,3
,1,0,0,3
,1,0,0,3
,1,0,0,3
,1,0,0,3.0000001;
Y <<50,51,52,54,53,60,59,65,67,70,70,73,74,78,82,80,87,84,88,92;
b << X1.col(0);
X0 << X1.leftCols(3);
Xf << X1.rightCols(3);
//RSSr << getRSS(X0,Y);
// I want to eliminate 2nd column of X0 in the 1st time(X=X0[,(1,3)]), and
// eliminate 3rd column of X0 in the 2nd time(X=X0[,(1,2)]) according to matrix Xf ,bool varIn and varIn1
// here is my operation in detail
for(int i=0;i<Xf.cols();i++){
if(true==varIn[i]){ //varIn={true,true,false}
varIn1[i] = false; //Here is: I want to eliminate columns with varIn[i]==true
X=b; //initiate X=b
for(int j=0;j<Xf.cols();j++){ // i=0,varIn1={false,true,false}, then X<<b,Xf.col(2);
if(true==varIn1[j]){
X.resize(n,X.cols()+1); //? how to resize X
X<<X,Xf.col(j); //need to define X.cols()
}
}//j
//RSSf = getRSS(X,Y);
//F_value = getFval(RSSf,RSSr,X0.cols(),X.cols(),n);
}//if varIn==true
}//for i
std::cout << "test"<< std::endl << X << std::endl << std::endl;
system("pause");
}//main
|