39 #ifndef HEADER_PURIFICATION_SP2ACC 40 #define HEADER_PURIFICATION_SP2ACC 50 template<
typename MatrixType>
76 virtual void get_poly(
const int it,
int& poly, real& alpha);
102 template<
typename MatrixType>
108 template<
typename MatrixType>
111 assert((
int)this->
VecPoly.size() > it);
116 real Xtrace = this->
X.trace();
117 real Xsqtrace = this->
Xsq.trace();
168 template<
typename MatrixType>
171 assert((
int)this->
VecPoly.size() > it);
172 assert(this->
VecPoly[it] != -1);
182 template<
typename MatrixType>
218 this->
X *= ((
real)2.0 * (1 - alpha_tmp) * alpha_tmp);
219 this->
X.add_identity((
real)(1 - alpha_tmp) * (1 - alpha_tmp));
220 this->
Xsq *= ((
real)alpha_tmp * alpha_tmp);
221 this->
Xsq += this->
X;
234 this->
X *= ((
real) - 2.0 * alpha_tmp);
235 this->
Xsq *= ((
real) - alpha_tmp * alpha_tmp);
236 this->
Xsq -= this->
X;
241 this->
X *= (
real)2.0;
242 this->
Xsq += this->
X;
248 this->
Xsq.transfer(this->
X);
252 template<
typename MatrixType>
259 real homo_low, homo_upp, lumo_upp, lumo_low;
271 lumo_low *= lumo_low;
273 lumo_upp *= lumo_upp;
284 homo_low *= homo_low;
286 homo_upp *= homo_upp;
315 template<
typename MatrixType>
334 if (((alpha1 == 1) && (alpha2 == 1)))
358 if ((homo_upp > 0.5) || (lumo_upp > 0.5))
373 " and alpha2 = %g", a, alpha1, alpha2);
379 C1 = -7.88 + 11.6 * alpha1 + 0.71 * alpha2;
391 template<
typename MatrixType>
397 if (allowed_error == 0)
402 assert((
int)this->
VecGap.size() > it);
413 tau = (allowed_error * this->
VecGap[it]) / (1 + allowed_error);
417 tau = allowed_error * 0.01;
422 #ifdef USE_CHUNKS_AND_TASKS 423 threshold = (this->
X).thresh_frob(tau);
438 template<
typename MatrixType>
443 real x, y, x_out, y_out;
447 int max_size = maxit_tmp + 1 + this->additional_iterations + 2;
450 this->
VecPoly.resize(max_size, -1);
453 this->
VecGap.resize(max_size, -1);
468 estim_num_iter = this->
maxit;
484 this->
VecGap[0] = 1 - x - y;
488 while (it <= maxit_tmp)
491 if ((x > y) || (it % 2 && (x == y)))
493 alpha_tmp = 2 / (2 - x_out);
495 x = (1 - alpha_tmp + alpha_tmp * x);
497 y = 2 * alpha_tmp * y - alpha_tmp * alpha_tmp * y * y;
499 x_out = (1 - alpha_tmp + alpha_tmp * x_out);
501 y_out = 2 * alpha_tmp * y_out - alpha_tmp * alpha_tmp * y_out * y_out;
507 alpha_tmp = 2 / (2 - y_out);
509 x = 2 * alpha_tmp * x - alpha_tmp * alpha_tmp * x * x;
510 y = (1 - alpha_tmp + alpha_tmp * y);
513 x_out = 2 * alpha_tmp * x_out - alpha_tmp * alpha_tmp * x_out * x_out;
514 y_out = (1 - alpha_tmp + alpha_tmp * y_out);
521 this->
VecGap[it] = 1 - x - y;
543 (x - x * x < epsilon) && (y - y * y < epsilon) &&
559 if ((estim_num_iter == -1) && (it == maxit_tmp + 1))
564 estim_num_iter = this->
maxit;
567 this->
VecPoly.resize(maxit_tmp + 1);
568 this->
VecGap.resize(maxit_tmp + 1);
569 this->
VecAlpha.resize(maxit_tmp + 1);
575 template<
typename MatrixType>
578 assert((
int)this->
VecPoly.size() > it);
579 assert((
int)this->
VecGap.size() > it);
580 assert((
int)this->
VecAlpha.size() > it);
590 template<
typename MatrixType>
597 for (
int i = it; i >= 1; i--)
606 bounds_from_it[0] = (bounds_from_it[0] - 1 + alpha_tmp) / alpha_tmp - tau;
608 bounds_from_it[1] = (bounds_from_it[1] - 1 + alpha_tmp) / alpha_tmp + tau;
610 bounds_from_it[2] = bounds_from_it[2] / (1 +
template_blas_sqrt(1 - bounds_from_it[2]));
611 bounds_from_it[2] = bounds_from_it[2] / alpha_tmp - tau;
612 bounds_from_it[3] = bounds_from_it[3] / (1 +
template_blas_sqrt(1 - bounds_from_it[3]));
613 bounds_from_it[3] = bounds_from_it[3] / alpha_tmp + tau;
617 bounds_from_it[0] = bounds_from_it[0] / (1 +
template_blas_sqrt(1 - bounds_from_it[0]));
618 bounds_from_it[0] = bounds_from_it[0] / alpha_tmp - tau;
619 bounds_from_it[1] = bounds_from_it[1] / (1 +
template_blas_sqrt(1 - bounds_from_it[1]));
620 bounds_from_it[1] = bounds_from_it[1] / alpha_tmp + tau;
623 bounds_from_it[2] = (bounds_from_it[2] - 1 + alpha_tmp) / alpha_tmp - tau;
625 bounds_from_it[3] = (bounds_from_it[3] - 1 + alpha_tmp) / alpha_tmp + tau;
631 template<
typename MatrixType>
648 fx = (1 - alpha_tmp + alpha_tmp * x) * (1 - alpha_tmp + alpha_tmp * x);
652 fx = 2 * alpha_tmp * x - alpha_tmp * alpha_tmp * x * x;
659 template<
typename MatrixType>
674 homo = 2 * alpha_tmp * homo - alpha_tmp * alpha_tmp * homo * homo;
675 lumo = (1 - alpha_tmp + alpha_tmp * lumo) * (1 - alpha_tmp + alpha_tmp * lumo);
679 homo = (1 - alpha_tmp + alpha_tmp * homo) * (1 - alpha_tmp + alpha_tmp * homo);
680 lumo = 2 * alpha_tmp * lumo - alpha_tmp * alpha_tmp * lumo * lumo;
685 template<
typename MatrixType>
700 for (
int i = 1; i <= it; i++)
708 a = ((1 - alpha) + alpha * temp) * ((1 - alpha) + alpha * temp);
709 b = 2 * alpha * ((1 - alpha) + alpha * temp);
713 a = 2 * alpha * temp - alpha * alpha * temp * temp;
714 b = 2 * alpha - 2 * alpha * alpha * temp;
723 #endif //HEADER_PURIFICATION_SP2ACC real error_per_it
Error allowed in each iteration due to truncation.
Definition: purification_general.h:422
Treal upp() const
Definition: Interval.h:145
ergo_real real
Definition: purification_general.h:114
#define C_SP2
Constant used on the stopping criterion for the SP2 method.
Definition: constants.h:42
VectorTypeReal VecAlpha
Definition: purification_sp2acc.h:96
virtual void purify_X(const int it)
Definition: purification_sp2acc.h:183
VectorTypeReal VecGap
Gap computed using inner homo and lumo bounds on each iteration.
Definition: purification_general.h:436
virtual void apply_poly_to_eigs(const int it, real &homo, real &lumo)
Definition: purification_sp2acc.h:660
Treal low() const
Definition: Interval.h:144
virtual void set_poly(const int it)
Definition: purification_sp2acc.h:109
PurificationGeneral is an abstract class which provides an interface for SP2, SP2ACC and possibly oth...
Definition: purification_general.h:111
static Interval intersect(Interval const &A, Interval const &B)
Definition: Interval.h:53
static real get_epsilon()
Get machine epsilon.
Definition: purification_general.h:198
generalVector VectorType
Definition: purification_sp2acc.h:62
real gammaStopEstim
Used on the stopping criterion for estimation of eigenvalues from purification.
Definition: purification_general.h:426
real alpha
Definition: puri_info.h:91
virtual void apply_inverse_poly_vector(const int it, VectorTypeReal &bounds_from_it)
Definition: purification_sp2acc.h:591
IntervalType homo_bounds
(1-homo) bounds for Xi in iteration i
Definition: purification_general.h:449
IntervalType lumo_bounds
Lumo bounds for Xi in iteration i.
Definition: purification_general.h:450
int check_stopping_criterion_iter
Iteration when to start to check stopping criterion.
Definition: purification_general.h:405
int poly
Definition: puri_info.h:78
#define LOG_AREA_DENSFROMF
Definition: output.h:61
virtual void set_init_params()
Definition: purification_sp2acc.h:66
std::vector< IterationInfo > Iterations
Definition: puri_info.h:203
std::vector< int > VectorTypeInt
Definition: purification_general.h:117
PurificationGeneral< MatrixType >::IntervalType IntervalType
Definition: purification_sp2acc.h:56
virtual void return_constant_C(const int it, real &Cval)
Definition: purification_sp2acc.h:316
Treal template_blas_fabs(Treal x)
int additional_iterations
Do a few more iterations after convergence.
Definition: purification_general.h:402
virtual void save_other_iter_info(IterationInfo &iter_info, int it)
Definition: purification_sp2acc.h:576
PurificationGeneral< MatrixType >::VectorTypeInt VectorTypeInt
Definition: purification_sp2acc.h:59
#define max(a, b)
Definition: integrator.cc:87
int nocc
Number of occupied orbitals.
Definition: purification_general.h:407
Purification_sp2acc is a class which provides an interface for SP2ACC recursive expansion.
Definition: purification_sp2acc.h:51
#define LOG_CAT_INFO
Definition: output.h:49
NormType normPuriStopCrit
Norm used in the stopping criterion Can be mat::frobNorm, mat::mixedNorm, or mat::euclNorm.
Definition: purification_general.h:415
symmMatrix MatrixType
Definition: recexp_diag_test.cc:66
static const real deltaTurnOffAcc
Definition: purification_sp2acc.h:99
PurificationGeneral< MatrixType >::real real
Definition: purification_sp2acc.h:55
PurificationGeneral< MatrixType >::NormType NormType
Definition: purification_sp2acc.h:57
MatrixType Xsq
Matrix X^2.
Definition: purification_general.h:250
int method
Definition: puri_info.h:171
std::vector< real > VectorTypeReal
Definition: purification_general.h:118
MatrixType X
Matrix X.
Definition: purification_general.h:248
int maxit
Maximum number of iterations.
Definition: purification_general.h:404
Recursive density matrix expansion (or density matrix purification).
NormType normPuriTrunc
Norm used for the truncation of matrices.
Definition: purification_general.h:411
Definition: puri_info.h:52
virtual void truncate_matrix(real &threshold, int it)
Definition: purification_sp2acc.h:392
PuriInfo info
Fill in during purification with useful information.
Definition: purification_general.h:246
Definition: matInclude.h:139
VectorTypeInt VecPoly
Polynomials computed in the function estimated_number_of_iterations() VecPoly[i] = 1 if we use X=X^2 ...
Definition: purification_general.h:431
virtual real apply_poly(const int it, real x)
Definition: purification_sp2acc.h:633
virtual real compute_derivative(const int it, real x, real &DDf)
Definition: purification_sp2acc.h:687
Purification_sp2acc()
Definition: purification_sp2acc.h:64
bool empty() const
Definition: Interval.h:51
void do_output(int logCategory, int logArea, const char *format,...)
Definition: output.cc:53
real gap
Definition: puri_info.h:79
virtual void estimate_number_of_iterations(int &numit)
Definition: purification_sp2acc.h:439
virtual void get_poly(const int it, int &poly, real &alpha)
Definition: purification_sp2acc.h:169
virtual void purify_bounds(const int it)
Definition: purification_sp2acc.h:253
PurificationGeneral< MatrixType >::VectorTypeReal VectorTypeReal
Definition: purification_sp2acc.h:60
Treal template_blas_sqrt(Treal x)
normType
Definition: matInclude.h:139