15 template <
typename InType,
typename OutType>
16 std::vector<std::vector<OutType>>
18 const bool is_distributed)
21 const auto values = this->computeBootstrapEstimates(data, is_distributed);
24 std::vector<std::vector<OutType>> output;
25 if (this->processor_id() == 0)
26 for (
const Real & level : this->_levels)
28 long unsigned int index = std::lrint(level * (this->_replicates - 1));
29 output.push_back(values[index]);
35 template <
typename InType,
typename OutType>
36 std::vector<std::vector<OutType>>
38 const std::vector<InType> & data,
bool is_distributed)
41 const std::vector<std::vector<OutType>> values =
42 this->computeBootstrapEstimates(data, is_distributed);
45 const std::vector<OutType>
value = this->_calc.compute(data, is_distributed);
46 std::vector<Real> bias(
value.size());
50 for (
const auto & val : values)
52 if (val[i] <
value[i])
61 const std::vector<OutType> acc =
62 data.empty() ? std::vector<OutType>(
value.size()) :
acceleration(data, is_distributed);
65 std::vector<std::vector<OutType>> output(this->_levels.size(),
66 std::vector<OutType>(
value.size()));
72 const OutType
x = bias[i] + (bias[i] + (bias[i] + z) / (1 - acc[i] * (bias[i] + z)));
75 long unsigned int index = std::lrint(
alpha * (this->_replicates - 1));
76 output[l][i] = values[index][i];
82 template <
typename InType,
typename OutType>
85 const std::vector<InType> & data,
const bool is_distributed)
87 const std::size_t local_size = data.size();
88 std::vector<std::size_t> local_sizes = {local_size};
90 this->_communicator.allgather(local_sizes);
91 const std::size_t count = std::accumulate(local_sizes.begin(), local_sizes.end(), 0);
95 std::vector<std::vector<OutType>> theta_i(local_size);
99 for (std::size_t i = 0; i < local_sizes[r]; ++i)
101 this->_calc.initializeCalculator();
102 for (std::size_t il = 0; il < local_size; ++il)
103 if (i != il || r != rank)
104 this->_calc.updateCalculator(data[il]);
105 this->_calc.finalizeCalculator(is_distributed);
107 theta_i[i] = this->_calc.getValue();
111 const std::size_t nval = theta_i.size() > 0 ? theta_i[0].size() : 0;
112 std::vector<OutType> theta_dot(nval, 0.);
113 for (
const auto & ti : theta_i)
115 theta_dot[i] += ti[i] / count;
117 this->_communicator.sum(theta_dot);
120 std::vector<OutType> num_den(2 * nval);
121 for (
const auto & jk : theta_i)
128 this->_communicator.sum(num_den);
130 mooseAssert(std::find(num_den.begin() + nval, num_den.end(), OutType()) == num_den.end(),
131 "The acceleration denomenator must not be zero.");
132 std::vector<OutType> acc(nval);
134 acc[i] = num_den[i] / (6 *
std::pow(num_den[nval + i], 3. / 2.));
138 template <
typename InType,
typename OutType>
139 std::unique_ptr<Calculator<std::vector<InType>, std::vector<OutType>>>
144 return std::make_unique<VectorCalculator<InType, OutType, Min>>(other, item);
146 else if (item ==
"max")
147 return std::make_unique<VectorCalculator<InType, OutType, Max>>(other, item);
149 else if (item ==
"sum")
150 return std::make_unique<VectorCalculator<InType, OutType, Sum>>(other, item);
152 else if (item ==
"mean" || item ==
"average")
153 return std::make_unique<VectorCalculator<InType, OutType, Mean>>(other, item);
155 else if (item ==
"stddev")
156 return std::make_unique<VectorCalculator<InType, OutType, StdDev>>(other, item);
158 else if (item ==
"stderr")
159 return std::make_unique<VectorCalculator<InType, OutType, StdErr>>(other, item);
161 else if (item ==
"norm2")
162 return std::make_unique<VectorCalculator<InType, OutType, L2Norm>>(other, item);
164 else if (item ==
"ratio")
165 return std::make_unique<VectorCalculator<InType, OutType, Ratio>>(other, item);
167 else if (item ==
"median")
168 return std::make_unique<VectorCalculator<InType, OutType, Median>>(other, item);
170 else if (item ==
"meanabs")
171 return std::make_unique<VectorCalculator<InType, OutType, MeanAbsoluteValue>>(other, item);
173 ::mooseError(
"Failed to create Statistics::Calculator object for ", item);
177 template <
typename InType,
typename OutType>
178 std::unique_ptr<BootstrapCalculator<std::vector<InType>, std::vector<OutType>>>
182 const std::vector<Real> & levels,
183 unsigned int replicates,
187 std::unique_ptr<BootstrapCalculator<std::vector<InType>, std::vector<OutType>>> ptr =
nullptr;
188 if (item ==
"percentile")
189 ptr = std::make_unique<Percentile<std::vector<InType>, std::vector<OutType>>>(
190 other, item, levels, replicates, seed, calc);
191 else if (item ==
"bca")
192 ptr = std::make_unique<BiasCorrectedAccelerated<std::vector<InType>, std::vector<OutType>>>(
193 other, item, levels, replicates, seed, calc);
195 ::mooseError(
"Failed to create Statistics::BootstrapCalculator object for ", item);
200 #define createVectorCalculators(InType, OutType) \ 201 template class Percentile<std::vector<InType>, std::vector<OutType>>; \ 202 template class BiasCorrectedAccelerated<std::vector<InType>, std::vector<OutType>>; \ 203 template struct CalculatorBuilder<std::vector<InType>, std::vector<OutType>>; \ 204 template struct BootstrapCalculatorBuilder<std::vector<InType>, std::vector<OutType>> static const std::string acceleration
virtual Real cdf(const Real &x) const override
uint8_t processor_id_type
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::vector< double > x
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string alpha
IntRange< T > make_range(T beg, T end)
virtual Real quantile(const Real &p) const override
MooseUnits pow(const MooseUnits &, int)
auto index_range(const T &sizable)