Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4ConvergenceTester Class Reference

#include <G4ConvergenceTester.hh>

Public Member Functions

void AddScore (G4double)
 
void ComputeStatistics ()
 
 G4ConvergenceTester (const G4String &theName="NONAME")
 
 G4ConvergenceTester (G4double)
 
G4double GetEfficiency ()
 
G4double GetFOM ()
 
G4double GetMean ()
 
G4double GetR ()
 
G4double GetR2eff ()
 
G4double GetR2int ()
 
G4double GetShift ()
 
G4double GetStandardDeviation ()
 
G4double GetValueOfMinimizingFunction (std::vector< G4double > x)
 
G4double GetVariance ()
 
G4double GetVOV ()
 
G4ConvergenceTesteroperator+= (G4double val)
 
void ShowHistory (std::ostream &out=G4cout)
 
void ShowResult (std::ostream &out=G4cout)
 
 ~G4ConvergenceTester ()
 

Private Member Functions

void calc_grid_point_of_history ()
 
G4double calc_Pearson_r (G4int, std::vector< G4double >, std::vector< G4double >)
 
void calc_slope_fit (std::vector< G4double >)
 
void calc_stat_history ()
 
void calStat ()
 
void check_stat_history (std::ostream &out=G4cout)
 
void CheckIsUpdated ()
 
G4bool is_monotonically_decrease (std::vector< G4double >)
 
G4double slope_fitting_function (std::vector< G4double >)
 

Private Attributes

G4bool calcSLOPE = true
 
std::vector< G4doublecpu_time
 
std::vector< G4doublee_history
 
G4double efficiency = 0.0
 
std::vector< G4doublef_xi
 
std::vector< G4doublef_yi
 
G4double fom = 0.0
 
G4double fom_1 = 0.0
 
std::vector< G4doublefom_history
 
std::vector< G4inthistory_grid
 
G4double largest = 0.0
 
G4int largest_score_happened = 0
 
std::vector< G4doublelargest_scores
 
G4double mean = 0.0
 
G4double mean_1 = 0.0
 
std::vector< G4doublemean_history
 
G4SimplexDownhill< G4ConvergenceTester > * minimizer = nullptr
 
G4int n = 0
 
G4String name
 
G4int noBinOfHistory = 16
 
G4int noBinOfPDF = 10
 
std::map< G4int, G4doublenonzero_histories
 
G4int noPass = 0
 
G4int noTotal = 8
 
G4double r = 0.0
 
G4double r2eff = 0.0
 
std::vector< G4doubler2eff_history
 
G4double r2int = 0.0
 
std::vector< G4doubler2int_history
 
G4double r_1 = 0.0
 
std::vector< G4doubler_history
 
G4double sd = 0.0
 
G4double sd_1 = 0.0
 
std::vector< G4doublesd_history
 
G4double shift = 0.0
 
G4double shift_1 = 0.0
 
std::vector< G4doubleshift_history
 
G4bool showHistory = true
 
G4double slope = 0.0
 
G4bool statsAreUpdated = true
 
G4double sum = 0.0
 
G4Timertimer = nullptr
 
G4double var = 0.0
 
G4double var_1 = 0.0
 
std::vector< G4doublevar_history
 
G4double vov = 0.0
 
G4double vov_1 = 0.0
 
std::vector< G4doublevov_history
 

Detailed Description

Definition at line 54 of file G4ConvergenceTester.hh.

Constructor & Destructor Documentation

◆ G4ConvergenceTester() [1/2]

G4ConvergenceTester::G4ConvergenceTester ( const G4String theName = "NONAME")

Definition at line 40 of file G4ConvergenceTester.cc.

41 : name(theName)
42{
43 nonzero_histories.clear();
44 largest_scores.clear();
45 largest_scores.push_back(0.0);
46
48 mean_history.resize(noBinOfHistory, 0.0);
49 var_history.resize(noBinOfHistory, 0.0);
50 sd_history.resize(noBinOfHistory, 0.0);
51 r_history.resize(noBinOfHistory, 0.0);
52 vov_history.resize(noBinOfHistory, 0.0);
53 fom_history.resize(noBinOfHistory, 0.0);
54 shift_history.resize(noBinOfHistory, 0.0);
55 e_history.resize(noBinOfHistory, 0.0);
56 r2eff_history.resize(noBinOfHistory, 0.0);
57 r2int_history.resize(noBinOfHistory, 0.0);
58
59 timer = new G4Timer();
60 timer->Start();
61 cpu_time.clear();
62 cpu_time.push_back(0.0);
63}
std::vector< G4double > largest_scores
std::vector< G4double > e_history
std::vector< G4double > vov_history
std::vector< G4double > sd_history
std::vector< G4int > history_grid
std::map< G4int, G4double > nonzero_histories
std::vector< G4double > r_history
std::vector< G4double > var_history
std::vector< G4double > shift_history
std::vector< G4double > r2eff_history
std::vector< G4double > r2int_history
std::vector< G4double > cpu_time
std::vector< G4double > fom_history
std::vector< G4double > mean_history
void Start()

References cpu_time, e_history, fom_history, history_grid, largest_scores, mean_history, noBinOfHistory, nonzero_histories, r2eff_history, r2int_history, r_history, sd_history, shift_history, G4Timer::Start(), timer, var_history, and vov_history.

◆ ~G4ConvergenceTester()

G4ConvergenceTester::~G4ConvergenceTester ( )

Definition at line 65 of file G4ConvergenceTester.cc.

66{
67 delete timer;
68}

References timer.

◆ G4ConvergenceTester() [2/2]

G4ConvergenceTester::G4ConvergenceTester ( G4double  )

Member Function Documentation

◆ AddScore()

void G4ConvergenceTester::AddScore ( G4double  x)

Definition at line 70 of file G4ConvergenceTester.cc.

71{
73
74 timer->Stop();
76
77 if(x < 0.0)
78 {
79 std::ostringstream message;
80 message << "Expecting zero or positive number as inputs,\n"
81 << "but received a negative number.";
82 G4Exception("G4ConvergenceTester::AddScore()", "Warning",
83 JustWarning, message);
84 }
85
86 if(x == 0.0)
87 {
88 }
89 else
90 {
91 nonzero_histories.insert(std::pair<G4int, G4double>(n, x));
92 if(x > largest_scores.back())
93 {
94 // Following search should become faster if begin from bottom.
95 for(auto it = largest_scores.begin(); it != largest_scores.end(); ++it)
96 {
97 if(x > *it)
98 {
99 largest_scores.insert(it, x);
100 break;
101 }
102 }
103
104 if(largest_scores.size() > 201)
105 {
106 largest_scores.pop_back();
107 }
108 }
109 sum += x;
110 }
111
112 // Data has been added so statistics have now been updated to new values
113 statsAreUpdated = false;
114 ++n;
115 l.unlock();
116 return;
117}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
void Stop()
G4double GetSystemElapsed() const
Definition: G4Timer.cc:132
G4double GetUserElapsed() const
Definition: G4Timer.cc:143

References anonymous_namespace{G4ConvergenceTester.cc}::aMutex, cpu_time, G4Exception(), G4Timer::GetSystemElapsed(), G4Timer::GetUserElapsed(), JustWarning, largest_scores, n, nonzero_histories, statsAreUpdated, G4Timer::Stop(), sum, timer, and G4TemplateAutoLock< _Mutex_t >::unlock().

Referenced by operator+=().

◆ calc_grid_point_of_history()

void G4ConvergenceTester::calc_grid_point_of_history ( )
private

Definition at line 247 of file G4ConvergenceTester.cc.

248{
249 // histroy_grid [ 0,,,15 ]
250 // history_grid [0] 1/16 ,,, history_grid [15] 16/16
251 // if number of event is x then history_grid [15] become x-1.
252 // 16 -> noBinOfHisotry
253
254 for(G4int i = 1; i <= noBinOfHistory; ++i)
255 {
256 history_grid[i - 1] = G4int(n / (G4double(noBinOfHistory)) * i - 0.1);
257 }
258}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85

References history_grid, n, and noBinOfHistory.

Referenced by calStat().

◆ calc_Pearson_r()

G4double G4ConvergenceTester::calc_Pearson_r ( G4int  N,
std::vector< G4double first_ally,
std::vector< G4double second_ally 
)
private

Definition at line 634 of file G4ConvergenceTester.cc.

637{
638 G4double first_mean = 0.0;
639 G4double second_mean = 0.0;
640
641 G4int i;
642 for(i = 0; i < N; i++)
643 {
644 first_mean += first_ally[i];
645 second_mean += second_ally[i];
646 }
647 first_mean = first_mean / N;
648 second_mean = second_mean / N;
649
650 G4double a = 0.0;
651 for(i = 0; i < N; ++i)
652 {
653 a += (first_ally[i] - first_mean) * (second_ally[i] - second_mean);
654 }
655
656 G4double b1 = 0.0;
657 G4double b2 = 0.0;
658 for(i = 0; i < N; ++i)
659 {
660 b1 += (first_ally[i] - first_mean) * (first_ally[i] - first_mean);
661 b2 += (second_ally[i] - second_mean) * (second_ally[i] - second_mean);
662 }
663
664 G4double rds = a / std::sqrt(b1 * b2);
665
666 return rds;
667}

Referenced by check_stat_history().

◆ calc_slope_fit()

void G4ConvergenceTester::calc_slope_fit ( std::vector< G4double )
private

Definition at line 682 of file G4ConvergenceTester.cc.

683{
684 // create PDF bins
685 G4double max = largest_scores.front();
686 G4int last = G4int(largest_scores.size());
687 G4double min = 0.0;
688 if(largest_scores.back() != 0)
689 {
690 min = largest_scores.back();
691 }
692 else
693 {
694 min = largest_scores[last - 1];
695 last = last - 1;
696 }
697
698 if(max * 0.99 < min)
699 {
700 // upper limit is assumed to have been reached
701 slope = 10.0;
702 return;
703 }
704
705 std::vector<G4double> pdf_grid;
706
707 pdf_grid.resize(noBinOfPDF + 1); // no grid = no bins + 1
708 pdf_grid[0] = max;
709 pdf_grid[noBinOfPDF] = min;
710 G4double log10_max = std::log10(max);
711 G4double log10_min = std::log10(min);
712 G4double log10_delta = log10_max - log10_min;
713 for(G4int i = 1; i < noBinOfPDF; ++i)
714 {
715 pdf_grid[i] = std::pow(10.0, log10_max - log10_delta / 10.0 * (i));
716 }
717
718 std::vector<G4double> pdf;
719 pdf.resize(noBinOfPDF);
720
721 for(G4int j = 0; j < last; ++j)
722 {
723 for(G4int i = 0; i < 11; ++i)
724 {
725 if(largest_scores[j] >= pdf_grid[i + 1])
726 {
727 pdf[i] += 1.0 / (pdf_grid[i] - pdf_grid[i + 1]) / n;
728 break;
729 }
730 }
731 }
732
733 f_xi.resize(noBinOfPDF);
734 f_yi.resize(noBinOfPDF);
735 for(G4int i = 0; i < noBinOfPDF; ++i)
736 {
737 f_xi[i] = (pdf_grid[i] + pdf_grid[i + 1]) / 2;
738 f_yi[i] = pdf[i];
739 }
740
741 // number of variables ( a and k )
743 // G4double minimum = minimizer->GetMinimum();
744 std::vector<G4double> mp = minimizer->GetMinimumPoint();
745 G4double k = mp[1];
746
747 // G4cout << "SLOPE " << 1/mp[1]+1 << G4endl;
748 // G4cout << "SLOPE a " << mp[0] << G4endl;
749 // G4cout << "SLOPE k " << mp[1] << G4endl;
750 // G4cout << "SLOPE minimum " << minimizer->GetMinimum() << G4endl;
751
752 slope = 1 / mp[1] + 1;
753 if(k < 1.0 / 9) // Please look Pareto distribution with "sigma=a" and "k"
754 {
755 slope = 10;
756 }
757 if(slope > 10)
758 {
759 slope = 10;
760 }
761}
std::vector< G4double > f_xi
G4SimplexDownhill< G4ConvergenceTester > * minimizer
std::vector< G4double > f_yi
std::vector< G4double > GetMinimumPoint()
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments

References f_xi, f_yi, G4SimplexDownhill< T >::GetMinimumPoint(), largest_scores, G4INCL::Math::max(), G4INCL::Math::min(), minimizer, n, noBinOfPDF, and slope.

Referenced by calStat().

◆ calc_stat_history()

void G4ConvergenceTester::calc_stat_history ( )
private

Definition at line 260 of file G4ConvergenceTester.cc.

261{
262 if(history_grid[0] == 0)
263 {
264 showHistory = false;
265 return;
266 }
267
268 for(G4int i = 0; i < noBinOfHistory; ++i)
269 {
270 G4int ith = history_grid[i];
271
272 G4int nonzero_till_ith = 0;
273 G4double xi;
274 G4double mean_till_ith = 0.0;
275
276 for(const auto& itr : nonzero_histories)
277 {
278 if(itr.first <= ith)
279 {
280 xi = itr.second;
281 mean_till_ith += xi;
282 ++nonzero_till_ith;
283 }
284 }
285
286 if(nonzero_till_ith == 0)
287 continue;
288
289 mean_till_ith = mean_till_ith / (ith + 1);
290 mean_history[i] = mean_till_ith;
291
292 G4double sum_x2_till_ith = 0.0;
293 G4double var_till_ith = 0.0;
294 G4double vov_till_ith = 0.0;
295 G4double shift_till_ith = 0.0;
296
297 for(const auto& itr : nonzero_histories)
298 {
299 if(itr.first <= ith)
300 {
301 xi = itr.second;
302 sum_x2_till_ith += std::pow(xi, 2.0);
303 var_till_ith += std::pow(xi - mean_till_ith, 2.0);
304 shift_till_ith += std::pow(xi - mean_till_ith, 3.0);
305 vov_till_ith += std::pow(xi - mean_till_ith, 4.0);
306 }
307 }
308
309 var_till_ith +=
310 ((ith + 1) - nonzero_till_ith) * std::pow(mean_till_ith, 2.0);
311 vov_till_ith +=
312 ((ith + 1) - nonzero_till_ith) * std::pow(mean_till_ith, 4.0);
313
314 G4double sum_till_ith = mean_till_ith * (ith + 1);
315
316 if(!(std::fabs(var_till_ith) > 0.0))
317 continue;
318 if(!(std::fabs(mean_till_ith) > 0.0))
319 continue;
320 if(!(std::fabs(sum_till_ith) > 0.0))
321 continue;
322
323 vov_till_ith = vov_till_ith / std::pow(var_till_ith, 2.0) - 1.0 / (ith + 1);
324 vov_history[i] = vov_till_ith;
325
326 var_till_ith = var_till_ith / (ith + 1 - 1);
327 var_history[i] = var_till_ith;
328 sd_history[i] = std::sqrt(var_till_ith);
329 r_history[i] =
330 std::sqrt(var_till_ith) / mean_till_ith / std::sqrt(1.0 * (ith + 1));
331
332 if(std::fabs(cpu_time[ith]) > 0.0 && std::fabs(r_history[i]) > 0.0)
333 {
334 fom_history[i] = 1.0 / std::pow(r_history[i], 2.0) / cpu_time[ith];
335 }
336 else
337 {
338 fom_history[i] = 0.0;
339 }
340
341 shift_till_ith +=
342 ((ith + 1) - nonzero_till_ith) * std::pow(mean_till_ith, 3.0) * (-1.0);
343 shift_till_ith = shift_till_ith / (2 * var_till_ith * (ith + 1));
344 shift_history[i] = shift_till_ith;
345
346 e_history[i] = 1.0 * nonzero_till_ith / (ith + 1);
347 if(std::fabs(e_history[i]) > 0.0)
348 {
349 r2eff_history[i] = (1 - e_history[i]) / (e_history[i] * (ith + 1));
350
351 r2int_history[i] = (sum_x2_till_ith) / std::pow(sum_till_ith, 2.0) -
352 1 / (e_history[i] * (ith + 1));
353 }
354 }
355}

References cpu_time, e_history, fom_history, history_grid, mean_history, noBinOfHistory, nonzero_histories, r2eff_history, r2int_history, r_history, sd_history, shift_history, showHistory, var_history, and vov_history.

Referenced by calStat().

◆ calStat()

void G4ConvergenceTester::calStat ( )
private

Definition at line 119 of file G4ConvergenceTester.cc.

120{
122
123 mean = sum / n;
124
125 G4double sum_x2 = 0.0;
126 var = 0.0;
127 shift = 0.0;
128 vov = 0.0;
129
130 G4double xi;
131 for(auto it = nonzero_histories.cbegin(); it != nonzero_histories.cend();
132 ++it)
133 {
134 xi = it->second;
135 sum_x2 += xi * xi;
136 var += (xi - mean) * (xi - mean);
137 shift += (xi - mean) * (xi - mean) * (xi - mean);
138 vov += (xi - mean) * (xi - mean) * (xi - mean) * (xi - mean);
139 }
140
141 var += (n - nonzero_histories.size()) * mean * mean;
142 shift += (n - nonzero_histories.size()) * mean * mean * mean * (-1);
143 vov += (n - nonzero_histories.size()) * mean * mean * mean * mean;
144
145 if(var != 0.0)
146 {
147 vov = vov / (var * var) - 1.0 / n;
148
149 var = var / (n - 1);
150
151 sd = std::sqrt(var);
152
153 r = sd / mean / std::sqrt(G4double(n));
154
155 r2eff = (1 - efficiency) / (efficiency * n);
156 r2int = sum_x2 / (sum * sum) - 1 / (efficiency * n);
157
158 shift = shift / (2 * var * n);
159
160 fom = 1 / (r * r) / cpu_time.back();
161 }
162
163 // Find Largest History
164 // G4double largest = 0.0;
165 largest = 0.0;
167 G4double spend_time_of_largest = 0.0;
168 for(auto it = nonzero_histories.cbegin(); it != nonzero_histories.cend();
169 ++it)
170 {
171 if(std::abs(it->second) > largest)
172 {
173 largest = it->second;
174 largest_score_happened = it->first;
175 spend_time_of_largest = cpu_time[it->first + 1] - cpu_time[it->first];
176 }
177 }
178
179 mean_1 = 0.0;
180 var_1 = 0.0;
181 shift_1 = 0.0;
182 vov_1 = 0.0;
183 sd_1 = 0.0;
184 r_1 = 0.0;
185 vov_1 = 0.0;
186
187 mean_1 = (sum + largest) / (n + 1);
188
189 for(auto it = nonzero_histories.cbegin(); it != nonzero_histories.cend();
190 ++it)
191 {
192 xi = it->second;
193 var_1 += (xi - mean_1) * (xi - mean_1);
194 shift_1 += (xi - mean_1) * (xi - mean_1) * (xi - mean_1);
195 vov_1 += (xi - mean_1) * (xi - mean_1) * (xi - mean_1) * (xi - mean_1);
196 }
197 xi = largest;
198 var_1 += (xi - mean_1) * (xi - mean_1);
199 shift_1 += (xi - mean_1) * (xi - mean_1) * (xi - mean_1);
200 vov_1 += (xi - mean_1) * (xi - mean_1) * (xi - mean_1) * (xi - mean_1);
201
202 var_1 += (n - nonzero_histories.size()) * mean_1 * mean_1;
203
204 if(var_1 != 0.0)
205 {
206 shift_1 += (n - nonzero_histories.size()) * mean_1 * mean_1 * mean_1 * (-1);
207 vov_1 += (n - nonzero_histories.size()) * mean_1 * mean_1 * mean_1 * mean_1;
208
209 vov_1 = vov_1 / (var_1 * var_1) - 1.0 / (n + 1);
210
211 var_1 = var_1 / n;
212
213 sd_1 = std::sqrt(var_1);
214
215 r_1 = sd_1 / mean_1 / std::sqrt(G4double(n + 1));
216
217 shift_1 = shift_1 / (2 * var_1 * (n + 1));
218
219 fom_1 = 1 / (r * r) / (cpu_time.back() + spend_time_of_largest);
220 }
221
222 if(nonzero_histories.size() < 500)
223 {
224 calcSLOPE = false;
225 }
226 else
227 {
228 G4int i = G4int(nonzero_histories.size());
229
230 // 5% criterion
231 G4int j = G4int(i * 0.05);
232 while(G4int(largest_scores.size()) > j)
233 {
234 largest_scores.pop_back();
235 }
237 }
238
241
242 // statistics have been calculated and this function does not need
243 // to be called again until data has been added
244 statsAreUpdated = true;
245}
void calc_slope_fit(std::vector< G4double >)

References calc_grid_point_of_history(), calc_slope_fit(), calc_stat_history(), calcSLOPE, cpu_time, efficiency, fom, fom_1, largest, largest_score_happened, largest_scores, mean, mean_1, n, nonzero_histories, r, r2eff, r2int, r_1, sd, sd_1, shift, shift_1, statsAreUpdated, sum, var, var_1, vov, and vov_1.

Referenced by CheckIsUpdated(), ComputeStatistics(), and ShowResult().

◆ check_stat_history()

void G4ConvergenceTester::check_stat_history ( std::ostream &  out = G4cout)
private

Definition at line 496 of file G4ConvergenceTester.cc.

497{
498 // 1 sigma rejection for null hypothesis
499
500 std::vector<G4double> first_ally;
501 std::vector<G4double> second_ally;
502
503 // use 2nd half of hisories
504 G4int N = mean_history.size() / 2;
505 G4int i;
506
507 G4double pearson_r;
508 G4double t;
509
510 first_ally.resize(N);
511 second_ally.resize(N);
512
513 G4double sum_of_var =
514 std::accumulate(var_history.begin(), var_history.end(), 0.0);
515 if(sum_of_var == 0.0)
516 {
517 out << "Variances in all historical grids are zero." << G4endl;
518 out << "Terminating checking behavior of statistics numbers." << G4endl;
519 return;
520 }
521
522 // Mean
523
524 for(i = 0; i < N; ++i)
525 {
526 first_ally[i] = history_grid[N + i];
527 second_ally[i] = mean_history[N + i];
528 }
529
530 pearson_r = calc_Pearson_r(N, first_ally, second_ally);
531 t = pearson_r * std::sqrt((N - 2) / (1 - pearson_r * pearson_r));
532
533 if(t < 0.429318) // Student t of (Degree of freedom = N-2 )
534 {
535 out << "MEAN distribution is RANDOM" << G4endl;
536 noPass++;
537 }
538 else
539 {
540 out << "MEAN distribution is not RANDOM" << G4endl;
541 }
542
543 // R
544
545 for(i = 0; i < N; ++i)
546 {
547 first_ally[i] = 1.0 / std::sqrt(G4double(history_grid[N + i]));
548 second_ally[i] = r_history[N + i];
549 }
550
551 pearson_r = calc_Pearson_r(N, first_ally, second_ally);
552 t = pearson_r * std::sqrt((N - 2) / (1 - pearson_r * pearson_r));
553
554 if(t > 1.090546)
555 {
556 out << "r follows 1/std::sqrt(N)" << G4endl;
557 noPass++;
558 }
559 else
560 {
561 out << "r does not follow 1/std::sqrt(N)" << G4endl;
562 }
563
564 if(is_monotonically_decrease(second_ally) == true)
565 {
566 out << "r is monotonically decrease " << G4endl;
567 }
568 else
569 {
570 out << "r is NOT monotonically decrease " << G4endl;
571 }
572
573 if(r_history.back() < 0.1)
574 {
575 out << "r is less than 0.1. r = " << r_history.back() << G4endl;
576 noPass++;
577 }
578 else
579 {
580 out << "r is NOT less than 0.1. r = " << r_history.back() << G4endl;
581 }
582
583 // VOV
584 for(i = 0; i < N; ++i)
585 {
586 first_ally[i] = 1.0 / history_grid[N + i];
587 second_ally[i] = vov_history[N + i];
588 }
589
590 pearson_r = calc_Pearson_r(N, first_ally, second_ally);
591 t = pearson_r * std::sqrt((N - 2) / (1 - pearson_r * pearson_r));
592
593 if(t > 1.090546)
594 {
595 out << "VOV follows 1/std::sqrt(N)" << G4endl;
596 noPass++;
597 }
598 else
599 {
600 out << "VOV does not follow 1/std::sqrt(N)" << G4endl;
601 }
602
603 if(is_monotonically_decrease(second_ally) == true)
604 {
605 out << "VOV is monotonically decrease " << G4endl;
606 }
607 else
608 {
609 out << "VOV is NOT monotonically decrease " << G4endl;
610 }
611
612 // FOM
613
614 for(i = 0; i < N; ++i)
615 {
616 first_ally[i] = history_grid[N + i];
617 second_ally[i] = fom_history[N + i];
618 }
619
620 pearson_r = calc_Pearson_r(N, first_ally, second_ally);
621 t = pearson_r * std::sqrt((N - 2) / (1 - pearson_r * pearson_r));
622
623 if(t < 0.429318)
624 {
625 out << "FOM distribution is RANDOM" << G4endl;
626 noPass++;
627 }
628 else
629 {
630 out << "FOM distribution is not RANDOM" << G4endl;
631 }
632}
#define G4endl
Definition: G4ios.hh:57
G4double calc_Pearson_r(G4int, std::vector< G4double >, std::vector< G4double >)
G4bool is_monotonically_decrease(std::vector< G4double >)

References calc_Pearson_r(), fom_history, G4endl, history_grid, is_monotonically_decrease(), mean_history, noPass, r_history, var_history, and vov_history.

Referenced by ShowResult().

◆ CheckIsUpdated()

void G4ConvergenceTester::CheckIsUpdated ( )
inlineprivate

◆ ComputeStatistics()

void G4ConvergenceTester::ComputeStatistics ( )
inline

Definition at line 79 of file G4ConvergenceTester.hh.

79{ calStat(); }

References calStat().

◆ GetEfficiency()

G4double G4ConvergenceTester::GetEfficiency ( )
inline

Definition at line 88 of file G4ConvergenceTester.hh.

References CheckIsUpdated(), and efficiency.

◆ GetFOM()

G4double G4ConvergenceTester::GetFOM ( )
inline

Definition at line 93 of file G4ConvergenceTester.hh.

93{ CheckIsUpdated(); return fom; }

References CheckIsUpdated(), and fom.

◆ GetMean()

G4double G4ConvergenceTester::GetMean ( )
inline

Definition at line 84 of file G4ConvergenceTester.hh.

84{ CheckIsUpdated(); return mean; }

References CheckIsUpdated(), and mean.

◆ GetR()

G4double G4ConvergenceTester::GetR ( )
inline

Definition at line 87 of file G4ConvergenceTester.hh.

87{ CheckIsUpdated(); return r; }

References CheckIsUpdated(), and r.

◆ GetR2eff()

G4double G4ConvergenceTester::GetR2eff ( )
inline

Definition at line 89 of file G4ConvergenceTester.hh.

89{ CheckIsUpdated(); return r2eff; }

References CheckIsUpdated(), and r2eff.

◆ GetR2int()

G4double G4ConvergenceTester::GetR2int ( )
inline

Definition at line 90 of file G4ConvergenceTester.hh.

90{ CheckIsUpdated(); return r2int; }

References CheckIsUpdated(), and r2int.

◆ GetShift()

G4double G4ConvergenceTester::GetShift ( )
inline

Definition at line 91 of file G4ConvergenceTester.hh.

91{ CheckIsUpdated(); return shift; }

References CheckIsUpdated(), and shift.

◆ GetStandardDeviation()

G4double G4ConvergenceTester::GetStandardDeviation ( )
inline

Definition at line 85 of file G4ConvergenceTester.hh.

85{ CheckIsUpdated(); return sd; }

References CheckIsUpdated(), and sd.

◆ GetValueOfMinimizingFunction()

G4double G4ConvergenceTester::GetValueOfMinimizingFunction ( std::vector< G4double x)
inline

Definition at line 74 of file G4ConvergenceTester.hh.

75 {
76 return slope_fitting_function(x);
77 }
G4double slope_fitting_function(std::vector< G4double >)

References slope_fitting_function().

◆ GetVariance()

G4double G4ConvergenceTester::GetVariance ( )
inline

Definition at line 86 of file G4ConvergenceTester.hh.

86{ CheckIsUpdated(); return var; }

References CheckIsUpdated(), and var.

◆ GetVOV()

G4double G4ConvergenceTester::GetVOV ( )
inline

Definition at line 92 of file G4ConvergenceTester.hh.

92{ CheckIsUpdated(); return vov; }

References CheckIsUpdated(), and vov.

◆ is_monotonically_decrease()

G4bool G4ConvergenceTester::is_monotonically_decrease ( std::vector< G4double ally)
private

Definition at line 669 of file G4ConvergenceTester.cc.

671{
672 for(auto it = ally.cbegin(); it != ally.cend() - 1; ++it)
673 {
674 if(*it < *(it + 1))
675 return FALSE;
676 }
677
678 ++noPass;
679 return TRUE;
680}
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23

References FALSE, noPass, and TRUE.

Referenced by check_stat_history().

◆ operator+=()

G4ConvergenceTester & G4ConvergenceTester::operator+= ( G4double  val)
inline

Definition at line 64 of file G4ConvergenceTester.hh.

65 {
66 this->AddScore(val);
67 return *this;
68 }

References AddScore().

◆ ShowHistory()

void G4ConvergenceTester::ShowHistory ( std::ostream &  out = G4cout)

Definition at line 465 of file G4ConvergenceTester.cc.

466{
467 if(!showHistory)
468 {
469 out << "Number of events of this run is too small to show history."
470 << G4endl;
471 return;
472 }
473
474 out << std::setprecision(6);
475
476 out << G4endl;
477 out << "G4ConvergenceTester Output History of " << name << G4endl;
478 out << "i/" << noBinOfHistory << " till_ith mean" << std::setw(13)
479 << "var" << std::setw(13) << "sd" << std::setw(13) << "r" << std::setw(13)
480 << "vov" << std::setw(13) << "fom" << std::setw(13) << "shift"
481 << std::setw(13) << "e" << std::setw(13) << "r2eff" << std::setw(13)
482 << "r2int" << G4endl;
483 for(G4int i = 1; i <= noBinOfHistory; i++)
484 {
485 out << std::setw(4) << i << " " << std::setw(5) << history_grid[i - 1]
486 << std::setw(13) << mean_history[i - 1] << std::setw(13)
487 << var_history[i - 1] << std::setw(13) << sd_history[i - 1]
488 << std::setw(13) << r_history[i - 1] << std::setw(13)
489 << vov_history[i - 1] << std::setw(13) << fom_history[i - 1]
490 << std::setw(13) << shift_history[i - 1] << std::setw(13)
491 << e_history[i - 1] << std::setw(13) << r2eff_history[i - 1]
492 << std::setw(13) << r2int_history[i - 1] << G4endl;
493 }
494}

References e_history, fom_history, G4endl, history_grid, mean_history, name, noBinOfHistory, r2eff_history, r2int_history, r_history, sd_history, shift_history, showHistory, var_history, and vov_history.

◆ ShowResult()

void G4ConvergenceTester::ShowResult ( std::ostream &  out = G4cout)

Definition at line 357 of file G4ConvergenceTester.cc.

358{
359 // if data has been added since the last computation of the statistical values
360 // (not statsAreUpdated) call calStat to recompute the statistical values
361 if(!statsAreUpdated)
362 {
363 calStat();
364 }
365
366 out << std::setprecision(6);
367
368 out << G4endl;
369 out << "G4ConvergenceTester Output Result of " << name << G4endl;
370 out << std::setw(20) << "EFFICIENCY = " << std::setw(13) << efficiency
371 << G4endl;
372 out << std::setw(20) << "MEAN = " << std::setw(13) << mean << G4endl;
373 out << std::setw(20) << "VAR = " << std::setw(13) << var << G4endl;
374 out << std::setw(20) << "SD = " << std::setw(13) << sd << G4endl;
375 out << std::setw(20) << "R = " << std::setw(13) << r << G4endl;
376 out << std::setw(20) << "SHIFT = " << std::setw(13) << shift << G4endl;
377 out << std::setw(20) << "VOV = " << std::setw(13) << vov << G4endl;
378 out << std::setw(20) << "FOM = " << std::setw(13) << fom << G4endl;
379
380 out << std::setw(20) << "THE LARGEST SCORE = " << std::setw(13) << largest
381 << " and it happened at " << largest_score_happened << "th event"
382 << G4endl;
383 if(mean != 0)
384 {
385 out << std::setw(20) << "Affected Mean = " << std::setw(13) << mean_1
386 << " and its ratio to original is " << mean_1 / mean << G4endl;
387 }
388 else
389 {
390 out << std::setw(20) << "Affected Mean = " << std::setw(13) << mean_1
391 << G4endl;
392 }
393 if(var != 0)
394 {
395 out << std::setw(20) << "Affected VAR = " << std::setw(13) << var_1
396 << " and its ratio to original is " << var_1 / var << G4endl;
397 }
398 else
399 {
400 out << std::setw(20) << "Affected VAR = " << std::setw(13) << var_1
401 << G4endl;
402 }
403 if(r != 0)
404 {
405 out << std::setw(20) << "Affected R = " << std::setw(13) << r_1
406 << " and its ratio to original is " << r_1 / r << G4endl;
407 }
408 else
409 {
410 out << std::setw(20) << "Affected R = " << std::setw(13) << r_1 << G4endl;
411 }
412 if(shift != 0)
413 {
414 out << std::setw(20) << "Affected SHIFT = " << std::setw(13) << shift_1
415 << " and its ratio to original is " << shift_1 / shift << G4endl;
416 }
417 else
418 {
419 out << std::setw(20) << "Affected SHIFT = " << std::setw(13) << shift_1
420 << G4endl;
421 }
422 if(fom != 0)
423 {
424 out << std::setw(20) << "Affected FOM = " << std::setw(13) << fom_1
425 << " and its ratio to original is " << fom_1 / fom << G4endl;
426 }
427 else
428 {
429 out << std::setw(20) << "Affected FOM = " << std::setw(13) << fom_1
430 << G4endl;
431 }
432
433 if(!showHistory)
434 {
435 out << "Number of events of this run is too small to do convergence tests."
436 << G4endl;
437 return;
438 }
439
441
442 // check SLOPE and output result
443 if(calcSLOPE)
444 {
445 if(slope >= 3)
446 {
447 noPass++;
448 out << "SLOPE is large enough" << G4endl;
449 }
450 else
451 {
452 out << "SLOPE is not large enough" << G4endl;
453 }
454 }
455 else
456 {
457 out << "Number of non zero history too small to calculate SLOPE" << G4endl;
458 }
459
460 out << "This result passes " << noPass << " / " << noTotal
461 << " Convergence Test." << G4endl;
462 out << G4endl;
463}
void check_stat_history(std::ostream &out=G4cout)

References calcSLOPE, calStat(), check_stat_history(), efficiency, fom, fom_1, G4endl, largest, largest_score_happened, mean, mean_1, name, noPass, noTotal, r, r_1, sd, shift, shift_1, showHistory, slope, statsAreUpdated, var, var_1, and vov.

◆ slope_fitting_function()

G4double G4ConvergenceTester::slope_fitting_function ( std::vector< G4double x)
private

Definition at line 763 of file G4ConvergenceTester.cc.

764{
765 G4double a = x[0];
766 G4double k = x[1];
767
768 if(a <= 0)
769 {
770 return 3.402823466e+38; // FLOAT_MAX
771 }
772 if(k == 0)
773 {
774 return 3.402823466e+38; // FLOAT_MAX
775 }
776
777 // f_xi and f_yi is filled at "calc_slope_fit"
778
779 G4double y = 0.0;
780 for(G4int i = 0; i < G4int(f_yi.size()); ++i)
781 {
782 // if ( 1/a * ( 1 + k * f_xi [ i ] / a ) < 0 )
783 if((1 + k * f_xi[i] / a) < 0)
784 {
785 y += 3.402823466e+38; // FLOAT_MAX
786 }
787 else
788 {
789 y += (f_yi[i] - 1 / a * std::pow(1 + k * f_xi[i] / a, -1 / k - 1)) *
790 (f_yi[i] - 1 / a * std::pow(1 + k * f_xi[i] / a, -1 / k - 1));
791 }
792 }
793
794 return y;
795}

References f_xi, and f_yi.

Referenced by GetValueOfMinimizingFunction().

Field Documentation

◆ calcSLOPE

G4bool G4ConvergenceTester::calcSLOPE = true
private

Definition at line 173 of file G4ConvergenceTester.hh.

Referenced by calStat(), and ShowResult().

◆ cpu_time

std::vector<G4double> G4ConvergenceTester::cpu_time
private

Definition at line 124 of file G4ConvergenceTester.hh.

Referenced by AddScore(), calc_stat_history(), calStat(), and G4ConvergenceTester().

◆ e_history

std::vector<G4double> G4ConvergenceTester::e_history
private

Definition at line 157 of file G4ConvergenceTester.hh.

Referenced by calc_stat_history(), G4ConvergenceTester(), and ShowHistory().

◆ efficiency

G4double G4ConvergenceTester::efficiency = 0.0
private

Definition at line 130 of file G4ConvergenceTester.hh.

Referenced by calStat(), GetEfficiency(), and ShowResult().

◆ f_xi

std::vector<G4double> G4ConvergenceTester::f_xi
private

Definition at line 163 of file G4ConvergenceTester.hh.

Referenced by calc_slope_fit(), and slope_fitting_function().

◆ f_yi

std::vector<G4double> G4ConvergenceTester::f_yi
private

Definition at line 164 of file G4ConvergenceTester.hh.

Referenced by calc_slope_fit(), and slope_fitting_function().

◆ fom

G4double G4ConvergenceTester::fom = 0.0
private

Definition at line 135 of file G4ConvergenceTester.hh.

Referenced by calStat(), GetFOM(), and ShowResult().

◆ fom_1

G4double G4ConvergenceTester::fom_1 = 0.0
private

Definition at line 146 of file G4ConvergenceTester.hh.

Referenced by calStat(), and ShowResult().

◆ fom_history

std::vector<G4double> G4ConvergenceTester::fom_history
private

◆ history_grid

std::vector<G4int> G4ConvergenceTester::history_grid
private

◆ largest

G4double G4ConvergenceTester::largest = 0.0
private

Definition at line 137 of file G4ConvergenceTester.hh.

Referenced by calStat(), and ShowResult().

◆ largest_score_happened

G4int G4ConvergenceTester::largest_score_happened = 0
private

Definition at line 138 of file G4ConvergenceTester.hh.

Referenced by calStat(), and ShowResult().

◆ largest_scores

std::vector<G4double> G4ConvergenceTester::largest_scores
private

Definition at line 162 of file G4ConvergenceTester.hh.

Referenced by AddScore(), calc_slope_fit(), calStat(), and G4ConvergenceTester().

◆ mean

G4double G4ConvergenceTester::mean = 0.0
private

Definition at line 126 of file G4ConvergenceTester.hh.

Referenced by calStat(), GetMean(), and ShowResult().

◆ mean_1

G4double G4ConvergenceTester::mean_1 = 0.0
private

Definition at line 140 of file G4ConvergenceTester.hh.

Referenced by calStat(), and ShowResult().

◆ mean_history

std::vector<G4double> G4ConvergenceTester::mean_history
private

◆ minimizer

G4SimplexDownhill<G4ConvergenceTester>* G4ConvergenceTester::minimizer = nullptr
private

Definition at line 166 of file G4ConvergenceTester.hh.

Referenced by calc_slope_fit().

◆ n

G4int G4ConvergenceTester::n = 0
private

◆ name

G4String G4ConvergenceTester::name
private

◆ noBinOfHistory

G4int G4ConvergenceTester::noBinOfHistory = 16
private

◆ noBinOfPDF

G4int G4ConvergenceTester::noBinOfPDF = 10
private

Definition at line 165 of file G4ConvergenceTester.hh.

Referenced by calc_slope_fit().

◆ nonzero_histories

std::map<G4int, G4double> G4ConvergenceTester::nonzero_histories
private

Definition at line 119 of file G4ConvergenceTester.hh.

Referenced by AddScore(), calc_stat_history(), calStat(), and G4ConvergenceTester().

◆ noPass

G4int G4ConvergenceTester::noPass = 0
private

◆ noTotal

G4int G4ConvergenceTester::noTotal = 8
private

Definition at line 169 of file G4ConvergenceTester.hh.

Referenced by ShowResult().

◆ r

G4double G4ConvergenceTester::r = 0.0
private

Definition at line 129 of file G4ConvergenceTester.hh.

Referenced by calStat(), GetR(), and ShowResult().

◆ r2eff

G4double G4ConvergenceTester::r2eff = 0.0
private

Definition at line 131 of file G4ConvergenceTester.hh.

Referenced by calStat(), and GetR2eff().

◆ r2eff_history

std::vector<G4double> G4ConvergenceTester::r2eff_history
private

Definition at line 158 of file G4ConvergenceTester.hh.

Referenced by calc_stat_history(), G4ConvergenceTester(), and ShowHistory().

◆ r2int

G4double G4ConvergenceTester::r2int = 0.0
private

Definition at line 132 of file G4ConvergenceTester.hh.

Referenced by calStat(), and GetR2int().

◆ r2int_history

std::vector<G4double> G4ConvergenceTester::r2int_history
private

Definition at line 159 of file G4ConvergenceTester.hh.

Referenced by calc_stat_history(), G4ConvergenceTester(), and ShowHistory().

◆ r_1

G4double G4ConvergenceTester::r_1 = 0.0
private

Definition at line 143 of file G4ConvergenceTester.hh.

Referenced by calStat(), and ShowResult().

◆ r_history

std::vector<G4double> G4ConvergenceTester::r_history
private

◆ sd

G4double G4ConvergenceTester::sd = 0.0
private

Definition at line 128 of file G4ConvergenceTester.hh.

Referenced by calStat(), GetStandardDeviation(), and ShowResult().

◆ sd_1

G4double G4ConvergenceTester::sd_1 = 0.0
private

Definition at line 142 of file G4ConvergenceTester.hh.

Referenced by calStat().

◆ sd_history

std::vector<G4double> G4ConvergenceTester::sd_history
private

Definition at line 152 of file G4ConvergenceTester.hh.

Referenced by calc_stat_history(), G4ConvergenceTester(), and ShowHistory().

◆ shift

G4double G4ConvergenceTester::shift = 0.0
private

Definition at line 133 of file G4ConvergenceTester.hh.

Referenced by calStat(), GetShift(), and ShowResult().

◆ shift_1

G4double G4ConvergenceTester::shift_1 = 0.0
private

Definition at line 144 of file G4ConvergenceTester.hh.

Referenced by calStat(), and ShowResult().

◆ shift_history

std::vector<G4double> G4ConvergenceTester::shift_history
private

Definition at line 156 of file G4ConvergenceTester.hh.

Referenced by calc_stat_history(), G4ConvergenceTester(), and ShowHistory().

◆ showHistory

G4bool G4ConvergenceTester::showHistory = true
private

Definition at line 172 of file G4ConvergenceTester.hh.

Referenced by calc_stat_history(), ShowHistory(), and ShowResult().

◆ slope

G4double G4ConvergenceTester::slope = 0.0
private

Definition at line 161 of file G4ConvergenceTester.hh.

Referenced by calc_slope_fit(), and ShowResult().

◆ statsAreUpdated

G4bool G4ConvergenceTester::statsAreUpdated = true
private

Definition at line 171 of file G4ConvergenceTester.hh.

Referenced by AddScore(), calStat(), CheckIsUpdated(), and ShowResult().

◆ sum

G4double G4ConvergenceTester::sum = 0.0
private

Definition at line 121 of file G4ConvergenceTester.hh.

Referenced by AddScore(), and calStat().

◆ timer

G4Timer* G4ConvergenceTester::timer = nullptr
private

Definition at line 123 of file G4ConvergenceTester.hh.

Referenced by AddScore(), G4ConvergenceTester(), and ~G4ConvergenceTester().

◆ var

G4double G4ConvergenceTester::var = 0.0
private

Definition at line 127 of file G4ConvergenceTester.hh.

Referenced by calStat(), GetVariance(), and ShowResult().

◆ var_1

G4double G4ConvergenceTester::var_1 = 0.0
private

Definition at line 141 of file G4ConvergenceTester.hh.

Referenced by calStat(), and ShowResult().

◆ var_history

std::vector<G4double> G4ConvergenceTester::var_history
private

◆ vov

G4double G4ConvergenceTester::vov = 0.0
private

Definition at line 134 of file G4ConvergenceTester.hh.

Referenced by calStat(), GetVOV(), and ShowResult().

◆ vov_1

G4double G4ConvergenceTester::vov_1 = 0.0
private

Definition at line 145 of file G4ConvergenceTester.hh.

Referenced by calStat().

◆ vov_history

std::vector<G4double> G4ConvergenceTester::vov_history
private

The documentation for this class was generated from the following files: