HepLib
ErrMin.cpp
Go to the documentation of this file.
1 
6 #include "SD.h"
7 
8 
9 namespace HepLib::SD {
10 
11 IntegratorBase *ErrMin::Integrator = NULL;
12 MinimizeBase *ErrMin::miner = NULL;
13 qREAL *ErrMin::paras = NULL;
15 dREAL ErrMin::err_min = -0.001;
16 size_t ErrMin::MaxRND = 50;
17 size_t ErrMin::RunRND = 0;
18 dREAL *ErrMin::lambda = NULL;
19 dREAL ErrMin::hjRHO = 0.75;
21 
22 dREAL ErrMin::IntError(int nvars, dREAL *las, dREAL *n1, dREAL *n2) {
23  RunRND++;
24  dREAL dlas[nvars];
25  qREAL qlas[nvars];
26  mpREAL mplas[nvars];
27  for(int i=0; i<nvars; i++) {
28  dlas[i] = las[i];
29  qlas[i] = las[i];
30  mplas[i] = las[i];
31  }
32  Integrator->qLambda = qlas;
33  Integrator->dLambda = dlas;
34  Integrator->mpLambda = mplas;
35  auto res = Integrator->Integrate();
36  if(res.has(NaN)) return 1.E100L;
37 
38  auto err = res.subs(VE(w0, w1)==w1);
39  numeric nerr = numeric(1.E100);
40  try {
41  nerr = ex_to<numeric>(NN(abs(err)));
42  if(nerr > numeric(1.E100)) nerr = numeric(1.E100);
43  if(err_max > ex2q(nerr)) {
44  auto diff = VESimplify(lastResErr - res);
45  diff = diff.subs(VE(0,0)==0);
46  exset ves;
47  diff.find(VE(w0, w1), ves);
48  for(auto ve : ves) {
49  if(abs(ve.op(0)) > ve.op(1)) return 1.E100L;
50  }
51  if(Verbose > 3) {
52  cout << "\r \r";
53  cout << Color_HighLight << " " << RunRND << ": " << RESET;
54  for(int i=0; i<nvars; i++) cout << las[i] << " ";
55  cout << endl << " " << res.subs(VE(0,0)==0).subs(VE(w1,w2)==VEO(w1,w2)) << endl;
56  }
57  err_max = (dREAL)ex2q(nerr);
58  for(int i=0; i<nvars; i++) lambda[i] = las[i];
59  if(err_max<=err_min) {
60  cout << "\r \r";
61  cout << " ------------------------------" << endl;
62  miner->ForceStop();
63  return 0.;
64  }
65  } else {
66  if(Verbose > 3) {
67  cout << "\r \r";
68  cout << Color_HighLight << " [ " << RunRND << " / " << MaxRND << " ] ..." << RESET << flush;
69  }
70  }
71  } catch(domain_error &ex) {
72  throw ex;
73  } catch(...) { }
74  if(RunRND>=MaxRND) {
75  cout << "\r \r";
76  cout << " ------------------------------" << endl;
77  miner->ForceStop();
78  return 0.;
79  }
80 
81  auto pid = getpid();
82  ostringstream fn;
83  fn << pid << ".las.done";
84  if(file_exists(fn.str().c_str())) {
85  ostringstream cmd;
86  cmd << "rm " << fn.str();
87  auto rc = system(cmd.str().c_str());
88  cout << "\r \r";
89  if(Verbose>3) cout << " Exit: " << fn.str() << endl;
90  cout << " ------------------------------" << endl;
91  miner->ForceStop();
92  return 0.;
93  }
94  dREAL ret = (dREAL)ex2q(nerr);
95  return ret;
96 }
97 
98 
99 }
#define RESET
Definition: BASIC.h:79
long double dREAL
Definition: HCubature.cpp:17
__float128 qREAL
Definition: HCubature.cpp:15
SecDec header file.
static ex lastResErr
Definition: SD.h:380
static IntegratorBase * Integrator
Definition: SD.h:371
static size_t RunRND
Definition: SD.h:376
static dREAL err_max
Definition: SD.h:373
static MinimizeBase * miner
Definition: SD.h:377
static qREAL * paras
Definition: SD.h:372
static dREAL IntError(int nvars, dREAL *las, dREAL *n1, dREAL *n2)
Definition: ErrMin.cpp:22
static dREAL * lambda
Definition: SD.h:378
static size_t MaxRND
Definition: SD.h:375
static dREAL hjRHO
Definition: SD.h:379
static dREAL err_min
Definition: SD.h:374
const dREAL * dLambda
Definition: SD.h:145
const mpREAL * mpLambda
Definition: SD.h:149
virtual ex Integrate(size_t n=0)=0
const qREAL * qLambda
Definition: SD.h:147
virtual void ForceStop()=0
namespace for Numerical integration with Sector Decomposition method
Definition: AsyMB.cpp:10
__float128 qREAL
Definition: SD.h:123
long double dREAL
Definition: SD.h:121
ex VESimplify(ex expr)
Definition: Helpers.cpp:92
mpfr::mpreal mpREAL
Definition: SD.h:125
const char * Color_HighLight
Definition: BASIC.cpp:248
__float128 ex2q(ex num)
ex of numeric to __float128
Definition: BASIC.cpp:879
ex NN(ex expr, int digits)
the nuerical evaluation
Definition: BASIC.cpp:1278
ex w0
Definition: BASIC.h:499
bool file_exists(string fn)
Definition: BASIC.h:289
int Verbose
Definition: Init.cpp:139
ex w1
Definition: BASIC.h:499
ex w2
Definition: BASIC.h:499
const Symbol NaN