https://mooseframework.inl.gov
Functions
AdaptiveMonteCarloUtils Namespace Reference

Functions

Real computeSTD (const std::vector< Real > &data, const unsigned int &start_index)
 compute the standard deviation of a data vector by only considering values from a specific index. More...
 
Real computeMean (const std::vector< Real > &data, const unsigned int &start_index)
 compute the mean of a data vector by only considering values from a specific index. More...
 
std::vector< std::vector< Real > > sortInput (const std::vector< std::vector< Real >> &inputs, const std::vector< Real > &outputs, const unsigned int samplessub, const Real subset_prob)
 return input values corresponding to the largest po percentile output values. More...
 
std::vector< RealsortOutput (const std::vector< Real > &outputs, const unsigned int samplessub, const Real subset_prob)
 return the largest po percentile output values. More...
 
Real computeMin (const std::vector< Real > &data)
 return the minimum value in a vector. More...
 
std::vector< RealcomputeVectorABS (const std::vector< Real > &data)
 return the absolute values in a vector. More...
 
unsigned int weightedResample (const std::vector< Real > &weights, Real rnd)
 return a resampled vector from a population given a weight vector. More...
 

Function Documentation

◆ computeMean()

Real AdaptiveMonteCarloUtils::computeMean ( const std::vector< Real > &  data,
const unsigned int start_index 
)

compute the mean of a data vector by only considering values from a specific index.

Parameters
thedata vector
thestarting index

Definition at line 38 of file AdaptiveMonteCarloUtils.C.

Referenced by AdaptiveImportanceSampler::computeSample(), and computeSTD().

39 {
40  if (data.size() < start_index)
41  return 0.0;
42  else
43  return std::accumulate(data.begin() + start_index, data.end(), 0.0) /
44  (data.size() - start_index);
45 }

◆ computeMin()

Real AdaptiveMonteCarloUtils::computeMin ( const std::vector< Real > &  data)

return the minimum value in a vector.

Parameters
thedata vector

Definition at line 80 of file AdaptiveMonteCarloUtils.C.

Referenced by AdaptiveMonteCarloDecision::execute().

81 {
82  return *std::min_element(data.begin(), data.end());
83 }

◆ computeSTD()

Real AdaptiveMonteCarloUtils::computeSTD ( const std::vector< Real > &  data,
const unsigned int start_index 
)

compute the standard deviation of a data vector by only considering values from a specific index.

Parameters
thedata vector
thestarting index

Definition at line 21 of file AdaptiveMonteCarloUtils.C.

Referenced by AdaptiveImportanceSampler::computeSample().

22 {
23  if (data.size() < start_index)
24  return 0.0;
25  else
26  {
27  const Real mean = computeMean(data, start_index);
28  const Real sq_diff =
29  std::accumulate(data.begin() + start_index,
30  data.end(),
31  0.0,
32  [&mean](Real x, Real y) { return x + (y - mean) * (y - mean); });
33  return std::sqrt(sq_diff / (data.size() - start_index));
34  }
35 }
const std::vector< double > y
Real computeMean(const std::vector< Real > &data, const unsigned int &start_index)
compute the mean of a data vector by only considering values from a specific index.
const std::vector< double > x
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ computeVectorABS()

std::vector< Real > AdaptiveMonteCarloUtils::computeVectorABS ( const std::vector< Real > &  data)

return the absolute values in a vector.

Parameters
thedata vector

Definition at line 86 of file AdaptiveMonteCarloUtils.C.

Referenced by AdaptiveMonteCarloDecision::execute(), and ParallelSubsetSimulation::sampleSetUp().

87 {
88  std::vector<Real> data_abs(data.size());
89  for (unsigned int i = 0; i < data.size(); ++i)
90  data_abs[i] = std::abs(data[i]);
91  return data_abs;
92 }

◆ sortInput()

std::vector< std::vector< Real > > AdaptiveMonteCarloUtils::sortInput ( const std::vector< std::vector< Real >> &  inputs,
const std::vector< Real > &  outputs,
const unsigned int  samplessub,
const Real  subset_prob 
)

return input values corresponding to the largest po percentile output values.

FOR PARALLEL SUBSET SIMULATION SAMPLER ********

Parameters
theinput vector
theoutput vector
thenumber of samples per subset
thesubset index
thesubset intermediate failure probability

Definition at line 48 of file AdaptiveMonteCarloUtils.C.

Referenced by AdaptiveMonteCarloDecision::execute(), and ParallelSubsetSimulation::sampleSetUp().

52 {
53  std::vector<size_t> ind;
54  Moose::indirectSort(outputs.begin(), outputs.end(), ind);
55 
56  std::vector<std::vector<Real>> out(inputs.size(), std::vector<Real>(samplessub * subset_prob));
57  const size_t offset = std::ceil(samplessub * (1 - subset_prob));
58  for (const auto & j : index_range(out))
59  for (const auto & i : index_range(out[j]))
60  out[j][i] = inputs[j][ind[i + offset]];
61 
62  return out;
63 }
void indirectSort(RandomAccessIterator beg, RandomAccessIterator end, std::vector< size_t > &b)
OStreamProxy out
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
auto index_range(const T &sizable)

◆ sortOutput()

std::vector< Real > AdaptiveMonteCarloUtils::sortOutput ( const std::vector< Real > &  outputs,
const unsigned int  samplessub,
const Real  subset_prob 
)

return the largest po percentile output values.

FOR PARALLEL SUBSET SIMULATION SAMPLER ********

Parameters
theoutput vector
thenumber of samples per subset
thesubset index
thesubset intermediate failure probability

Definition at line 66 of file AdaptiveMonteCarloUtils.C.

Referenced by AdaptiveMonteCarloDecision::execute().

67 {
68  std::vector<size_t> ind;
69  Moose::indirectSort(outputs.begin(), outputs.end(), ind);
70 
71  std::vector<Real> out(samplessub * subset_prob);
72  const size_t offset = std::round(samplessub * (1 - subset_prob));
73  for (const auto & i : index_range(out))
74  out[i] = outputs[ind[i + offset]];
75 
76  return out;
77 }
void indirectSort(RandomAccessIterator beg, RandomAccessIterator end, std::vector< size_t > &b)
OStreamProxy out
auto index_range(const T &sizable)

◆ weightedResample()

unsigned int AdaptiveMonteCarloUtils::weightedResample ( const std::vector< Real > &  weights,
Real  rnd 
)

return a resampled vector from a population given a weight vector.

Parameters
thegiven inputs (population)
theweight vector
thenumber of dimensions
arandom number between 0 and 1

Definition at line 95 of file AdaptiveMonteCarloUtils.C.

Referenced by IndependentMHDecision::nextSamples().

96 {
97  unsigned int req_index = 0;
98  for (unsigned int i = 0; i < weights.size(); ++i)
99  {
100  if (rnd < weights[i])
101  {
102  req_index = i;
103  break;
104  }
105  rnd -= weights[i];
106  }
107  return req_index;
108 }