double update_inverse_matrix_global_shift(const MAT & M, MAT & M_new, const operator_container_t &creation_operators, const operator_container_t &annihilation_operators, double BETA, double dtau) { typedef boost::tuple<double,int,double> key_t; typedef std::set<key_t> map_t; map_t annset, crset; double det_rat = 1.0; det_rat *= make_set_impl(annihilation_operators, BETA, dtau, annset); det_rat *= make_set_impl(creation_operators, BETA, dtau, crset); M_new.destructive_resize(M.size1(), M.size2()); int row = -1; int column = -1; for (map_t::iterator ita = annset.begin(); ita != annset.end(); ita++) { column++; for (map_t::iterator itc = crset.begin(); itc != crset.end(); itc++) { row++; M_new(row, column) = M(boost::get<1>(*itc), boost::get<1>(*ita))* boost::get<2>(*itc)*boost::get<2>(*ita); } row = -1; } return det_rat; }
int choleskyDecomp(MAT& A) { using namespace boost::numeric::bindings; int n = A.size1(); int info; info = lapack::potrf('L', A); for (int i = 0; i<A.size1();i++) for(int j=i+1;j<A.size2();j++) A(i,j) = 0; return info; }
void eig(const MAT& A, VEC& Sig) { using namespace boost::numeric::bindings; matrix<double, column_major> Ac = A; int m = A.size1(), n = A.size2(); int maxDim = std::max(m,n), minDim = std::min(m,n); Sig.resize(minDim); matrix<double, column_major> U(m,m), SigI(n,m), VT(n,n); lapack::gesvd('A','A', Ac, Sig, U, VT); }
void printMat(MAT& mat, std::string label="", int precision=2) { int width = precision + 7; std::cout<<label<<"["<<mat.size1()<<","<<mat.size2()<<"] "<<"\n"; std::cout<<"["; for(int i=0;i<mat.size1();i++) { if ( i != 0) std::cout<<" "; for(int j=0;j<mat.size2();j++) { printf("%*.*e",width,precision,mat(i,j)); //std::cout<<mat(i,j); if(j!=mat.size2()-1) std::cout<<", "; } std::cout<<";"; if ( i == mat.size1()-1) std::cout<<"]"; std::cout<<std::endl<<std::endl; } }
void compute_M_row_column_down(int position_c, int position_a, MAT & M) { MAT M_new(M.size1()-1,M.size2()-1); int k_old; int l_old; for (int k=0; k<M_new.size1(); k++) { k_old = (k<position_c ? k : k+1); for (int l=0; l<M_new.size2(); l++) { l_old = (l<position_a ? l : l+1); M_new(k,l) = M(k_old, l_old)-M(k_old,position_a)*M(position_c,l_old)/M(position_c,position_a); } } M_new.swap(M); }
void compute_M_row_column_up(int row, int column, MAT & M, MAT2& sign_Fs, MAT2& Fe_M, typename MAT::type det_rat) { typedef typename MAT::type SCALAR; SCALAR det_rat_inv=1./det_rat; double sign=((row+column)%2==0 ? 1 : -1); Eigen::Matrix<SCALAR,Eigen::Dynamic,Eigen::Dynamic> M_sign_Fs(sign_Fs.size(),1); M_sign_Fs = M.block()*sign_Fs; assert(M.size1()==M.size2()); MAT M_new(M.size1()+1,M.size2()+1); int i_new; int j_new; // element (j,i) M_new(column,row) = sign*det_rat_inv; // row j and column i for (int k=0; k<M.size1(); k++) { i_new = (k<column ? k : k+1); j_new = (k<row ? k : k+1); M_new(i_new,row) = -M_sign_Fs(k)*det_rat_inv; M_new(column,j_new) = -sign*Fe_M(k)*det_rat_inv; } // remaining elements for (int k=0; k<M.size1(); k++) { i_new = (k<column ? k : k+1); for (int l=0; l<M.size1(); l++) { j_new = (l<row ? l : l+1); M_new(i_new, j_new) = M(k,l) + M_sign_Fs(k)*Fe_M(l)*det_rat_inv; } } M_new.swap(M); return; }