47 return "Creates a randomly simulated workspace by sampling from the input data.";
56 "Input Workspace containing data to be simulated");
57 declareProperty(
"Seed", 32,
"Integer seed that initialises the random-number generator, for reproducibility");
59 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
60 mustBePositive->setLower(1);
61 declareProperty(
"NumberOfReplicas", 100, mustBePositive,
"Number of Bootstrap workspaces to simulate.");
63 std::vector<std::string> bootstrapOptions{
"ErrorSampling",
"SpectraSampling"};
65 "BootstrapType",
"ErrorSampling", std::make_shared<StringListValidator>(bootstrapOptions),
66 "Type of bootstrap sampling to use. "
67 "ErrorSampling samples at each data point, while SpectraSampling samples each spectra with repetition.");
71 "Name of output workspace.");
79 auto &ADS = AnalysisDataService::Instance();
83 std::mt19937 gen(
static_cast<unsigned int>(inputSeed));
86 std::string bootType =
getProperty(
"BootstrapType");
87 std::string prefix =
getProperty(
"OutputWorkspaceGroup");
90 std::vector<std::string> bootNames;
92 for (
int i = 1; i <= numReplicas; i++) {
95 ADS.addOrReplace(wsName, bootWs);
96 bootNames.push_back(std::move(wsName));
98 for (
size_t index = 0;
index < bootWs->getNumberHistograms();
index++) {
99 bootWs->setSharedX(
index, inputWs->sharedX(
index));
101 if (bootType ==
"ErrorSampling") {
103 bootWs->mutableE(
index) = 0;
105 }
else if (bootType ==
"SpectraSampling") {
108 size_t randomIndex = dist(gen);
109 bootWs->mutableY(
index) = inputWs->y(randomIndex);
110 bootWs->mutableE(
index) = inputWs->e(randomIndex);
113 progress.report(
"Creating Bootstrap Samples...");
116 alg->setProperty(
"InputWorkspaces", bootNames);
117 alg->executeAsChildAlg();
126 const HistogramData::HistogramE &dataE,
128 HistogramData::HistogramY outputY(dataY.size(), 0.0);
132 outputY[
index] = dist(gen);
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Helper class for reporting progress from algorithms.
A property class for workspaces.
CreateBootstrapWorkspaces: The algorithm generates several simulated workspaces by sampling randomly ...
void init() override
Initialize the algorithm's properties.
static HistogramData::HistogramY sampleHistogramFromGaussian(const HistogramData::HistogramY &dataY, const HistogramData::HistogramE &dataE, std::mt19937 &gen)
Helpers.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void exec() override
Execute the algorithm.
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::string to_string(const wide_integer< Bits, Signed > &n)
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.