mirror of
				https://github.com/aportelli/LatAnalyze.git
				synced 2025-11-04 08:04:32 +00:00 
			
		
		
		
	option to dump bootstrap sequence while resampling
This commit is contained in:
		@@ -47,6 +47,8 @@ public:
 | 
			
		||||
    // resampling
 | 
			
		||||
    Sample<T> bootstrapMean(const Index nSample, const SeedType seed);
 | 
			
		||||
    Sample<T> bootstrapMean(const Index nSample);
 | 
			
		||||
    void      dumpBootstrapSeq(std::ostream &out, const Index nSample,
 | 
			
		||||
                               const SeedType seed);
 | 
			
		||||
private:
 | 
			
		||||
    // mean from pointer vector for resampling
 | 
			
		||||
    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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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>
 | 
			
		||||
void Dataset<T>::ptVectorMean(T &m, const std::vector<const T *> &v)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
    // argument parsing ////////////////////////////////////////////////////////
 | 
			
		||||
    OptParser     opt;
 | 
			
		||||
    bool          parsed;
 | 
			
		||||
    bool          parsed, dumpBoot;
 | 
			
		||||
    random_device rd;
 | 
			
		||||
    SeedType      seed = rd();
 | 
			
		||||
    string        manFileName, nameFileName, outDirName;
 | 
			
		||||
@@ -56,6 +56,8 @@ int main(int argc, char *argv[])
 | 
			
		||||
                  "output directory", ".");
 | 
			
		||||
    opt.addOption("f", "format"    , OptParser::OptType::value,   true,
 | 
			
		||||
                  "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,
 | 
			
		||||
                  "show this help message and exit");
 | 
			
		||||
    parsed = opt.parse(argc, argv);
 | 
			
		||||
@@ -75,6 +77,7 @@ int main(int argc, char *argv[])
 | 
			
		||||
    }
 | 
			
		||||
    ext          = opt.optionValue("f");
 | 
			
		||||
    outDirName   = opt.optionValue("o");
 | 
			
		||||
    dumpBoot     = opt.gotOption("d");
 | 
			
		||||
    manFileName  = opt.getArgs()[0];
 | 
			
		||||
    nameFileName = opt.getArgs()[1];
 | 
			
		||||
    
 | 
			
		||||
@@ -124,6 +127,15 @@ int main(int argc, char *argv[])
 | 
			
		||||
        
 | 
			
		||||
        cout << '\r' << ProgressBar(i + 1, name.size());
 | 
			
		||||
        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);
 | 
			
		||||
        Io::save<DMatSample>(s, outDirName + "/" + outFileName,
 | 
			
		||||
                             File::Mode::write, outFileName);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user