本文整理汇总了C++中ArgumentParser::retrieve方法的典型用法代码示例。如果您正苦于以下问题:C++ ArgumentParser::retrieve方法的具体用法?C++ ArgumentParser::retrieve怎么用?C++ ArgumentParser::retrieve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArgumentParser
的用法示例。
在下文中一共展示了ArgumentParser::retrieve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char** argv) {
// Load the command line config
ArgumentParser parser;
parser.addArgument("-e", "--epochs", 1);
parser.addArgument("-s", "--seed", 1);
parser.addArgument("-l", "--layers", 1);
parser.addArgument("-S", "--samples", 1);
parser.addArgument("-c", "--corpus", 1);
parser.addArgument("--nlayers", 1);
parser.addArgument("--ifbradius", 1);
parser.addArgument("--lw", 1);
parser.addArgument("--lh", 1);
parser.addArgument("--ssize", 1);
parser.addArgument("--sseednoise", 1);
parser.addArgument("--sprednoise", 1);
parser.parse(argc, argv);
// RNG
unsigned int seed = std::atoi(parser.retrieve("seed", std::to_string(time(nullptr))).c_str());
std::mt19937 generator(seed);
std::uniform_real_distribution<float> dist01(0.0f, 1.0f);
// ---------------------------------- Load the Corpus ----------------------------------
std::string corpusPath = parser.retrieve("corpus", "corpus.txt");
std::ifstream fromFile(corpusPath);
fromFile.seekg(0, std::ios::end);
size_t size = fromFile.tellg();
std::string test(size, ' ');
fromFile.seekg(0);
fromFile.read(&test[0], size);
// ---------------------------------- Find Character Set ----------------------------------
VectorCodec textcodec(test);
int numInputs = textcodec.N;
int inputsRoot = std::ceil(std::sqrt(static_cast<float>(numInputs)));
// ---------------------------------- Create Hierarchy ----------------------------------
// Fill out layer descriptions
int nLayers = std::atoi(parser.retrieve("nlayers", "3").c_str());
int layerW = std::atoi(parser.retrieve("lw", "16").c_str());
int layerH = std::atoi(parser.retrieve("lh", "16").c_str());
int inFeedBackRadius = std::atoi(parser.retrieve("ifbradius", "16").c_str());
std::vector<neo::PredictiveHierarchy::LayerDesc> layerDescs(nLayers);
for (int i = 0; i < nLayers; i++) {
layerDescs[i]._width = layerW;
layerDescs[i]._height = layerH;
}
neo::PredictiveHierarchy ph;
ph.createRandom(inputsRoot, inputsRoot, inFeedBackRadius, layerDescs, -0.01f, 0.01f, 0.01f, 0.05f, 0.1f, generator);
// ---------------------------------- Iterate Over Corpus ----------------------------------
int numEpochs = std::atoi(parser.retrieve("epochs", "10").c_str());
int numSamples = std::atoi(parser.retrieve("samples", "10").c_str());
int sampleSize = std::atoi(parser.retrieve("ssize", std::to_string(test.length())).c_str());
float sampleSeedNoise = std::atof(parser.retrieve("sseednoise", "0.5").c_str());
float samplePredNoise = std::atof(parser.retrieve("sprednoise", "0.05").c_str());
std::cout << "NeoRL text prediction experiment" << std::endl;
std::cout << "Corpus: " << corpusPath << " size: " << test.length() << " alphabet size: " << textcodec.nSymbols << std::endl;
std::cout << "Model: nLayers: " << nLayers << " layerW: " << layerW << " layerH: " << layerH << " inFeedbackRadius: " << inFeedBackRadius
<< " input: " << inputsRoot << "x" << inputsRoot << std::endl;
std::cout << "Training: epochs: " << numEpochs << std::endl;
std::cout << "Sampling: samples: " << numSamples << " size: " << sampleSize << " seed noise: " << sampleSeedNoise << " pred noise " << samplePredNoise << std::endl;
std::cout << "--[ Start training ]--" << std::endl;
train(ph, generator, test, numEpochs, textcodec);
std::cout << "--[ Start sampling ]--" << std::endl;
for (int i = 0; i < numSamples; i++) {
sample(ph, generator, textcodec.getRandomSymbol(generator), sampleSize, textcodec, sampleSeedNoise, samplePredNoise);
}
return 0;
}