Geant4-11
G4ConvergenceTester.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4ConvergenceTester
27//
28// Class description:
29//
30// Convergence Tests for Monte Carlo results.
31//
32// Reference
33// MCNP(TM) -A General Monte Carlo N-Particle Transport Code
34// Version 4B
35// Judith F. Briesmeister, Editor
36// LA-12625-M, Issued: March 1997, UC 705 and UC 700
37// CHAPTER 2. GEOMETRY, DATA, PHYSICS, AND MATHEMATICS
38// VI. ESTIMATION OF THE MONTE CARLO PRECISION
39//
40// Positive numbers are assumed for input values
41
42// Author: Tatsumi Koi (SLAC/SCCS)
43// --------------------------------------------------------------------
44#ifndef G4ConvergenceTester_hh
45#define G4ConvergenceTester_hh 1
46
47#include "G4SimplexDownhill.hh"
48#include "G4Timer.hh"
49#include "globals.hh"
50
51#include <map>
52#include <vector>
53
55{
56 public:
57
58 G4ConvergenceTester(const G4String& theName = "NONAME");
61
62 void AddScore(G4double);
63
65 {
66 this->AddScore(val);
67 return *this;
68 }
69
70 void ShowHistory(std::ostream& out = G4cout);
71 void ShowResult(std::ostream& out = G4cout);
72 // Default to G4cout but can be redirected to another ostream
73
74 inline G4double GetValueOfMinimizingFunction(std::vector<G4double> x)
75 {
76 return slope_fitting_function(x);
77 }
78
80 // Explicitly calculate statistics
81
82 // All accessors check to make sure value is current before returning
83
84 inline G4double GetMean() { CheckIsUpdated(); return mean; }
86 inline G4double GetVariance() { CheckIsUpdated(); return var; }
87 inline G4double GetR() { CheckIsUpdated(); return r; }
89 inline G4double GetR2eff() { CheckIsUpdated(); return r2eff; }
90 inline G4double GetR2int() { CheckIsUpdated(); return r2int; }
91 inline G4double GetShift() { CheckIsUpdated(); return shift; }
92 inline G4double GetVOV() { CheckIsUpdated(); return vov; }
93 inline G4double GetFOM() { CheckIsUpdated(); return fom; }
94
95 private:
96
97 void calStat();
98 // Boolean value of 'statsAreUpdated' is set to TRUE at end of calStat
99 // and set to FALSE at end of AddScore().
100 // NOTE: A thread lock needs to be put in AddScore() so calStat()
101 // is not executed in one thread while AddScore() is adding data
102
103 inline void CheckIsUpdated()
104 {
105 if(!statsAreUpdated) { calStat(); }
106 }
107
109 void calc_stat_history();
110 void check_stat_history(std::ostream& out = G4cout);
111 G4double calc_Pearson_r(G4int,std::vector<G4double>,std::vector<G4double>);
112 G4bool is_monotonically_decrease(std::vector<G4double>);
113 void calc_slope_fit(std::vector<G4double>);
114 G4double slope_fitting_function(std::vector<G4double>);
115
116 private:
117
119 std::map<G4int, G4double> nonzero_histories; // (ith-history, score value)
120 G4int n = 0; // number of history
121 G4double sum = 0.0; // sum of scores;
122
123 G4Timer* timer = nullptr;
124 std::vector<G4double> cpu_time;
125
129 G4double r = 0.0; // relative err sd/mean/sqrt(n)
130 G4double efficiency = 0.0; // rate of non zero score
136
139
143 G4double r_1 = 0.0; // relative err sd/mean/sqrt(n)
147
149 std::vector<G4int> history_grid;
150 std::vector<G4double> mean_history;
151 std::vector<G4double> var_history;
152 std::vector<G4double> sd_history;
153 std::vector<G4double> r_history;
154 std::vector<G4double> vov_history;
155 std::vector<G4double> fom_history;
156 std::vector<G4double> shift_history;
157 std::vector<G4double> e_history;
158 std::vector<G4double> r2eff_history;
159 std::vector<G4double> r2int_history;
160
162 std::vector<G4double> largest_scores;
163 std::vector<G4double> f_xi;
164 std::vector<G4double> f_yi;
167
169 G4int noTotal = 8; // Total number of tests
170
174};
175
176#endif
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
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)
G4ConvergenceTester & operator+=(G4double val)
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
std::vector< G4int > history_grid
std::map< G4int, G4double > nonzero_histories
std::vector< G4double > r_history
void ShowResult(std::ostream &out=G4cout)
G4double GetValueOfMinimizingFunction(std::vector< G4double > x)
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(G4double)
G4ConvergenceTester(const G4String &theName="NONAME")