File indexing completed on 2025-01-18 09:58:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #ifndef G4ConvergenceTester_hh
0045 #define G4ConvergenceTester_hh 1
0046
0047 #include "G4SimplexDownhill.hh"
0048 #include "G4Timer.hh"
0049 #include "globals.hh"
0050
0051 #include <map>
0052 #include <vector>
0053
0054 class G4ConvergenceTester
0055 {
0056 public:
0057
0058 G4ConvergenceTester(const G4String& theName = "NONAME");
0059 ~G4ConvergenceTester();
0060 G4ConvergenceTester(G4double);
0061
0062 void AddScore(G4double);
0063
0064 inline G4ConvergenceTester& operator+=(G4double val)
0065 {
0066 this->AddScore(val);
0067 return *this;
0068 }
0069
0070 void ShowHistory(std::ostream& out = G4cout);
0071 void ShowResult(std::ostream& out = G4cout);
0072
0073
0074 inline G4double GetValueOfMinimizingFunction(std::vector<G4double> x)
0075 {
0076 return slope_fitting_function(x);
0077 }
0078
0079 void ComputeStatistics() { calStat(); }
0080
0081
0082
0083
0084 inline G4double GetMean() { CheckIsUpdated(); return mean; }
0085 inline G4double GetStandardDeviation() { CheckIsUpdated(); return sd; }
0086 inline G4double GetVariance() { CheckIsUpdated(); return var; }
0087 inline G4double GetR() { CheckIsUpdated(); return r; }
0088 inline G4double GetEfficiency() { CheckIsUpdated(); return efficiency; }
0089 inline G4double GetR2eff() { CheckIsUpdated(); return r2eff; }
0090 inline G4double GetR2int() { CheckIsUpdated(); return r2int; }
0091 inline G4double GetShift() { CheckIsUpdated(); return shift; }
0092 inline G4double GetVOV() { CheckIsUpdated(); return vov; }
0093 inline G4double GetFOM() { CheckIsUpdated(); return fom; }
0094
0095 private:
0096
0097 void calStat();
0098
0099
0100
0101
0102
0103 inline void CheckIsUpdated()
0104 {
0105 if(!statsAreUpdated) { calStat(); }
0106 }
0107
0108 void calc_grid_point_of_history();
0109 void calc_stat_history();
0110 void check_stat_history(std::ostream& out = G4cout);
0111 G4double calc_Pearson_r(G4int,std::vector<G4double>,std::vector<G4double>);
0112 G4bool is_monotonically_decrease(const std::vector<G4double>&);
0113 void calc_slope_fit(const std::vector<G4double>&);
0114 G4double slope_fitting_function(std::vector<G4double>);
0115
0116 private:
0117
0118 G4String name;
0119 std::map<G4int, G4double> nonzero_histories;
0120 G4int n = 0;
0121 G4double sum = 0.0;
0122
0123 G4Timer* timer = nullptr;
0124 std::vector<G4double> cpu_time;
0125
0126 G4double mean = 0.0;
0127 G4double var = 0.0;
0128 G4double sd = 0.0;
0129 G4double r = 0.0;
0130 G4double efficiency = 0.0;
0131 G4double r2eff = 0.0;
0132 G4double r2int = 0.0;
0133 G4double shift = 0.0;
0134 G4double vov = 0.0;
0135 G4double fom = 0.0;
0136
0137 G4double largest = 0.0;
0138 G4int largest_score_happened = 0;
0139
0140 G4double mean_1 = 0.0;
0141 G4double var_1 = 0.0;
0142 G4double sd_1 = 0.0;
0143 G4double r_1 = 0.0;
0144 G4double shift_1 = 0.0;
0145 G4double vov_1 = 0.0;
0146 G4double fom_1 = 0.0;
0147
0148 G4int noBinOfHistory = 16;
0149 std::vector<G4int> history_grid;
0150 std::vector<G4double> mean_history;
0151 std::vector<G4double> var_history;
0152 std::vector<G4double> sd_history;
0153 std::vector<G4double> r_history;
0154 std::vector<G4double> vov_history;
0155 std::vector<G4double> fom_history;
0156 std::vector<G4double> shift_history;
0157 std::vector<G4double> e_history;
0158 std::vector<G4double> r2eff_history;
0159 std::vector<G4double> r2int_history;
0160
0161 G4double slope = 0.0;
0162 std::vector<G4double> largest_scores;
0163 std::vector<G4double> f_xi;
0164 std::vector<G4double> f_yi;
0165 G4int noBinOfPDF = 10;
0166 G4SimplexDownhill<G4ConvergenceTester>* minimizer = nullptr;
0167
0168 G4int noPass = 0;
0169 G4int noTotal = 8;
0170
0171 G4bool statsAreUpdated = true;
0172 G4bool showHistory = true;
0173 G4bool calcSLOPE = true;
0174 };
0175
0176 #endif