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",
167 G4double spend_time_of_largest = 0.0;
171 if(std::abs(it->second) >
largest)
272 G4int nonzero_till_ith = 0;
286 if(nonzero_till_ith == 0)
289 mean_till_ith = mean_till_ith / (ith + 1);
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);
310 ((ith + 1) - nonzero_till_ith) * std::pow(mean_till_ith, 2.0);
312 ((ith + 1) - nonzero_till_ith) * std::pow(mean_till_ith, 4.0);
314 G4double sum_till_ith = mean_till_ith * (ith + 1);
316 if(!(std::fabs(var_till_ith) > 0.0))
318 if(!(std::fabs(mean_till_ith) > 0.0))
320 if(!(std::fabs(sum_till_ith) > 0.0))
323 vov_till_ith = vov_till_ith / std::pow(var_till_ith, 2.0) - 1.0 / (ith + 1);
326 var_till_ith = var_till_ith / (ith + 1 - 1);
330 std::sqrt(var_till_ith) / mean_till_ith / std::sqrt(1.0 * (ith + 1));
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));
346 e_history[i] = 1.0 * nonzero_till_ith / (ith + 1);
351 r2int_history[i] = (sum_x2_till_ith) / std::pow(sum_till_ith, 2.0) -
366 out << std::setprecision(6);
369 out <<
"G4ConvergenceTester Output Result of " <<
name <<
G4endl;
370 out << std::setw(20) <<
"EFFICIENCY = " << std::setw(13) <<
efficiency
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;
380 out << std::setw(20) <<
"THE LARGEST SCORE = " << std::setw(13) <<
largest
385 out << std::setw(20) <<
"Affected Mean = " << std::setw(13) <<
mean_1
390 out << std::setw(20) <<
"Affected Mean = " << std::setw(13) <<
mean_1
395 out << std::setw(20) <<
"Affected VAR = " << std::setw(13) <<
var_1
400 out << std::setw(20) <<
"Affected VAR = " << std::setw(13) <<
var_1
405 out << std::setw(20) <<
"Affected R = " << std::setw(13) <<
r_1
406 <<
" and its ratio to original is " <<
r_1 /
r <<
G4endl;
410 out << std::setw(20) <<
"Affected R = " << std::setw(13) <<
r_1 <<
G4endl;
414 out << std::setw(20) <<
"Affected SHIFT = " << std::setw(13) <<
shift_1
419 out << std::setw(20) <<
"Affected SHIFT = " << std::setw(13) <<
shift_1
424 out << std::setw(20) <<
"Affected FOM = " << std::setw(13) <<
fom_1
429 out << std::setw(20) <<
"Affected FOM = " << std::setw(13) <<
fom_1
435 out <<
"Number of events of this run is too small to do convergence tests."
448 out <<
"SLOPE is large enough" <<
G4endl;
452 out <<
"SLOPE is not large enough" <<
G4endl;
457 out <<
"Number of non zero history too small to calculate SLOPE" <<
G4endl;
461 <<
" Convergence Test." <<
G4endl;
469 out <<
"Number of events of this run is too small to show history."
474 out << std::setprecision(6);
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)
485 out << std::setw(4) << i <<
" " << std::setw(5) <<
history_grid[i - 1]
486 << std::setw(13) <<
mean_history[i - 1] << std::setw(13)
488 << std::setw(13) <<
r_history[i - 1] << std::setw(13)
500 std::vector<G4double> first_ally;
501 std::vector<G4double> second_ally;
510 first_ally.resize(N);
511 second_ally.resize(N);
515 if(sum_of_var == 0.0)
517 out <<
"Variances in all historical grids are zero." <<
G4endl;
518 out <<
"Terminating checking behavior of statistics numbers." <<
G4endl;
524 for(i = 0; i < N; ++i)
531 t = pearson_r * std::sqrt((N - 2) / (1 - pearson_r * pearson_r));
535 out <<
"MEAN distribution is RANDOM" <<
G4endl;
540 out <<
"MEAN distribution is not RANDOM" <<
G4endl;
545 for(i = 0; i < N; ++i)
552 t = pearson_r * std::sqrt((N - 2) / (1 - pearson_r * pearson_r));
556 out <<
"r follows 1/std::sqrt(N)" <<
G4endl;
561 out <<
"r does not follow 1/std::sqrt(N)" <<
G4endl;
566 out <<
"r is monotonically decrease " <<
G4endl;
570 out <<
"r is NOT monotonically decrease " <<
G4endl;
584 for(i = 0; i < N; ++i)
591 t = pearson_r * std::sqrt((N - 2) / (1 - pearson_r * pearson_r));
595 out <<
"VOV follows 1/std::sqrt(N)" <<
G4endl;
600 out <<
"VOV does not follow 1/std::sqrt(N)" <<
G4endl;
605 out <<
"VOV is monotonically decrease " <<
G4endl;
609 out <<
"VOV is NOT monotonically decrease " <<
G4endl;
614 for(i = 0; i < N; ++i)
621 t = pearson_r * std::sqrt((N - 2) / (1 - pearson_r * pearson_r));
625 out <<
"FOM distribution is RANDOM" <<
G4endl;
630 out <<
"FOM distribution is not RANDOM" <<
G4endl;
635 std::vector<G4double> first_ally,
636 std::vector<G4double> second_ally)
642 for(i = 0; i < N; i++)
644 first_mean += first_ally[i];
645 second_mean += second_ally[i];
647 first_mean = first_mean / N;
648 second_mean = second_mean / N;
651 for(i = 0; i < N; ++i)
653 a += (first_ally[i] - first_mean) * (second_ally[i] - second_mean);
658 for(i = 0; i < N; ++i)
660 b1 += (first_ally[i] - first_mean) * (first_ally[i] - first_mean);
661 b2 += (second_ally[i] - second_mean) * (second_ally[i] - second_mean);
664 G4double rds = a / std::sqrt(b1 * b2);
670 std::vector<G4double> ally)
672 for(
auto it = ally.cbegin(); it != ally.cend() - 1; ++it)
705 std::vector<G4double> pdf_grid;
712 G4double log10_delta = log10_max - log10_min;
715 pdf_grid[i] = std::pow(10.0, log10_max - log10_delta / 10.0 * (i));
718 std::vector<G4double> pdf;
721 for(
G4int j = 0; j < last; ++j)
723 for(
G4int i = 0; i < 11; ++i)
727 pdf[i] += 1.0 / (pdf_grid[i] - pdf_grid[i + 1]) /
n;
737 f_xi[i] = (pdf_grid[i] + pdf_grid[i + 1]) / 2;
752 slope = 1 / mp[1] + 1;
770 return 3.402823466e+38;
774 return 3.402823466e+38;
783 if((1 + k *
f_xi[i] / a) < 0)
785 y += 3.402823466e+38;
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));
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define G4MUTEX_INITIALIZER
std::vector< G4double > largest_scores
std::vector< G4double > f_xi
std::vector< G4double > e_history
std::vector< G4double > vov_history
void check_stat_history(std::ostream &out=G4cout)
G4double calc_Pearson_r(G4int, std::vector< G4double >, std::vector< G4double >)
G4double slope_fitting_function(std::vector< G4double >)
void calc_slope_fit(std::vector< G4double >)
std::vector< G4double > sd_history
G4SimplexDownhill< G4ConvergenceTester > * minimizer
void calc_grid_point_of_history()
std::vector< G4int > history_grid
std::map< G4int, G4double > nonzero_histories
std::vector< G4double > r_history
void ShowResult(std::ostream &out=G4cout)
std::vector< G4double > var_history
std::vector< G4double > f_yi
G4bool is_monotonically_decrease(std::vector< G4double >)
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
void ShowHistory(std::ostream &out=G4cout)
std::vector< G4double > mean_history
G4ConvergenceTester(const G4String &theName="NONAME")
G4int largest_score_happened
std::vector< G4double > GetMinimumPoint()
G4double GetSystemElapsed() const
G4double GetUserElapsed() const
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
const char * name(G4int ptype)