Beispiel #1
0
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;
}
Beispiel #2
0
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;
}
Beispiel #3
0
void move_column(MAT& M, int old_column, int new_column) {
    assert(0<=old_column&&old_column<M.size1());
    assert(0<=new_column&&new_column<M.size1());
    if (old_column==new_column) {
        return;
    } else if (old_column<new_column) {
        for (int i=old_column; i<new_column; ++i) {
            for (int m=0; m<M.size1(); ++m) {
                std::swap(M(m,i),M(m,i+1));
            }
        }
    } else if (old_column>new_column) {
        for (int i=old_column-1; i>=new_column; --i) {
            for (int m=0; m<M.size1(); ++m) {
                std::swap(M(m,i),M(m,i+1));
            }
        }
    }
}
Beispiel #4
0
void move_row(MAT& M, int old_row, int new_row) {
    assert(0<=old_row&&old_row<M.size1());
    assert(0<=new_row&&new_row<M.size1());
    if (old_row==new_row) {
        return;
    } else if (old_row<new_row) {
        for (int i=old_row; i<new_row; ++i) {
            for (int m=0; m<M.size1(); ++m) {
                std::swap(M(i,m),M(i+1,m));
            }
        }
    } else if (old_row>new_row) {
        for (int i=old_row-1; i>=new_row; --i) {
            for (int m=0; m<M.size1(); ++m) {
                std::swap(M(i,m),M(i+1,m));
            }
        }
    }
}
Beispiel #5
0
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);
}
Beispiel #6
0
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;
	}
}
Beispiel #7
0
SCALAR det_rat_shift_end(double new_t_end, int k, int flavor_rem, MAT & M,
 const operator_container_t & creation_operators, const HYB & F, double BETA) {

  SCALAR det_rat = 0;
  operator_container_t::const_iterator itc = creation_operators.begin();
  for (int i = 0; i < M.size1(); i++) {
    det_rat += interpolate_F(new_t_end - itc->time(), BETA, F[flavor_rem][itc->flavor()]) * M(i, k);
    itc++;
  }
  return det_rat;
}
Beispiel #8
0
SCALAR det_rat_shift_start(double new_t_start, int k, int flavor_ins,
 MAT & M, operator_container_t & annihilation_operators, const HYB & F, double BETA) {

  SCALAR det_rat = 0;
  operator_container_t::iterator ita = annihilation_operators.begin();
  for (int i = 0; i < M.size1(); i++) {
    det_rat += interpolate_F(ita->time() - new_t_start, BETA, F[ita->flavor()][flavor_ins]) * M(k, i);//right
    ita++;
  }

  return det_rat;
}
Beispiel #9
0
int compute_M_shift_end(double new_t_end, int k, int new_position, int flavor_rem, MAT & M,
 const operator_container_t & creation_operators, const HYB & F,
 double BETA, SCALAR det_rat) {

  std::vector<SCALAR> R(M.size1(), 0), M_k(M.size1(), 0), Fe(M.size1(), 0);

  operator_container_t::const_iterator itc = creation_operators.begin();
  for (int i = 0; i < (int) M_k.size(); i++) {
    M_k[i] = M(i, k);
    Fe[i] = interpolate_F(new_t_end - itc->time(), BETA, F[flavor_rem][itc->flavor()]);
    itc++;
  }
  for (int i = 0; i < (int) R.size(); i++) {
    if (i != k) {
      for (int j = 0; j < (int) R.size(); j++)
        R[i] += Fe[j] * M(j, i);
    }
  }
  for (int m = 0; m < (int) M.size1(); m++) {
    if (m != k) {
      for (int n = 0; n < (int) M.size1(); n++) {
        M(n, m) -= M_k[n] * R[m] / det_rat;
      }
    } else {
      for (int n = 0; n < (int) M.size1(); n++) {
        M(n, m) = M_k[n] / det_rat;
      }
    }
  }

  //swap column
  move_column(M, k, new_position);

  return std::abs(k-new_position);
}  
Beispiel #10
0
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);
}
Beispiel #11
0
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;
}  
Beispiel #12
0
int compute_M_shift_start(double new_t_start, int k, int new_position, int flavor_ins,
        MAT & M, const operator_container_t & annihilation_operators, const HYB & F, double BETA, SCALAR det_rat) {

  std::vector<SCALAR> R(M.size1(), 0), M_k(M.size1(), 0), Fs(M.size1(), 0);

  operator_container_t::const_iterator ita = annihilation_operators.begin();
  for (int i = 0; i < (int) M_k.size(); i++) {
    M_k[i] = M(k, i);
    Fs[i] = interpolate_F(ita->time() - new_t_start, BETA, F[ita->flavor()][flavor_ins]);
    ita++;
  }

  for (int i = 0; i < (int) R.size(); i++) {
    if (i != k) {
      for (int j = 0; j < (int) R.size(); j++)
        R[i] += M(i, j) * Fs[j];
    }
  }

  for (int n = 0; n < (int) M.size1(); n++) {
    if (n != k) {
      for (int m = 0; m < (int) M.size1(); m++) {
        M(n, m) -= M_k[m] * R[n] / det_rat;
      }
    } else {
      for (int m = 0; m < (int) M.size1(); m++) {
        M(n, m) = M_k[m] / det_rat;
      }
    }
  }

  //swap rows
  move_row(M, k, new_position);

  return std::abs(k-new_position);
}