mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-11 03:20:46 +01:00
option to dump bootstrap sequence while resampling
This commit is contained in:
parent
3d514ef026
commit
98cf39efda
@ -47,6 +47,8 @@ public:
|
|||||||
// resampling
|
// resampling
|
||||||
Sample<T> bootstrapMean(const Index nSample, const SeedType seed);
|
Sample<T> bootstrapMean(const Index nSample, const SeedType seed);
|
||||||
Sample<T> bootstrapMean(const Index nSample);
|
Sample<T> bootstrapMean(const Index nSample);
|
||||||
|
void dumpBootstrapSeq(std::ostream &out, const Index nSample,
|
||||||
|
const SeedType seed);
|
||||||
private:
|
private:
|
||||||
// mean from pointer vector for resampling
|
// mean from pointer vector for resampling
|
||||||
void ptVectorMean(T &m, const std::vector<const T *> &v);
|
void ptVectorMean(T &m, const std::vector<const T *> &v);
|
||||||
@ -114,6 +116,23 @@ Sample<T> Dataset<T>::bootstrapMean(const Index nSample)
|
|||||||
return bootstrapMean(nSample, rd());
|
return bootstrapMean(nSample, rd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void Dataset<T>::dumpBootstrapSeq(std::ostream &out, const Index nSample,
|
||||||
|
const SeedType seed)
|
||||||
|
{
|
||||||
|
std::mt19937 gen(seed);
|
||||||
|
std::uniform_int_distribution<Index> dis(0, this->size() - 1);
|
||||||
|
|
||||||
|
for (Index i = 0; i < nSample; ++i)
|
||||||
|
{
|
||||||
|
for (unsigned int j = 0; j < this->size(); ++j)
|
||||||
|
{
|
||||||
|
out << dis(gen) << " " << std::endl;
|
||||||
|
}
|
||||||
|
out << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Dataset<T>::ptVectorMean(T &m, const std::vector<const T *> &v)
|
void Dataset<T>::ptVectorMean(T &m, const std::vector<const T *> &v)
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
// argument parsing ////////////////////////////////////////////////////////
|
// argument parsing ////////////////////////////////////////////////////////
|
||||||
OptParser opt;
|
OptParser opt;
|
||||||
bool parsed;
|
bool parsed, dumpBoot;
|
||||||
random_device rd;
|
random_device rd;
|
||||||
SeedType seed = rd();
|
SeedType seed = rd();
|
||||||
string manFileName, nameFileName, outDirName;
|
string manFileName, nameFileName, outDirName;
|
||||||
@ -56,6 +56,8 @@ int main(int argc, char *argv[])
|
|||||||
"output directory", ".");
|
"output directory", ".");
|
||||||
opt.addOption("f", "format" , OptParser::OptType::value, true,
|
opt.addOption("f", "format" , OptParser::OptType::value, true,
|
||||||
"output file format", DEF_FMT);
|
"output file format", DEF_FMT);
|
||||||
|
opt.addOption("d", "dump-boot" , OptParser::OptType::trigger, true,
|
||||||
|
"dump bootstrap sequence", DEF_FMT);
|
||||||
opt.addOption("" , "help" , OptParser::OptType::trigger, true,
|
opt.addOption("" , "help" , OptParser::OptType::trigger, true,
|
||||||
"show this help message and exit");
|
"show this help message and exit");
|
||||||
parsed = opt.parse(argc, argv);
|
parsed = opt.parse(argc, argv);
|
||||||
@ -75,6 +77,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
ext = opt.optionValue("f");
|
ext = opt.optionValue("f");
|
||||||
outDirName = opt.optionValue("o");
|
outDirName = opt.optionValue("o");
|
||||||
|
dumpBoot = opt.gotOption("d");
|
||||||
manFileName = opt.getArgs()[0];
|
manFileName = opt.getArgs()[0];
|
||||||
nameFileName = opt.getArgs()[1];
|
nameFileName = opt.getArgs()[1];
|
||||||
|
|
||||||
@ -124,6 +127,15 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
cout << '\r' << ProgressBar(i + 1, name.size());
|
cout << '\r' << ProgressBar(i + 1, name.size());
|
||||||
data[name[i]].bin(binSize);
|
data[name[i]].bin(binSize);
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
ofstream file(outDirName + "/" + manFileName + ".bootseq");
|
||||||
|
|
||||||
|
file << "# bootstrap sequences" << endl;
|
||||||
|
file << "# manifest file: " << manFileName << endl;
|
||||||
|
file << "# bin size: " << binSize << endl;
|
||||||
|
data[name[i]].dumpBootstrapSeq(file, nSample, seed);
|
||||||
|
}
|
||||||
s = data[name[i]].bootstrapMean(nSample, seed);
|
s = data[name[i]].bootstrapMean(nSample, seed);
|
||||||
Io::save<DMatSample>(s, outDirName + "/" + outFileName,
|
Io::save<DMatSample>(s, outDirName + "/" + outFileName,
|
||||||
File::Mode::write, outFileName);
|
File::Mode::write, outFileName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user