本文整理汇总了C++中PropertySet::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ PropertySet::Set方法的具体用法?C++ PropertySet::Set怎么用?C++ PropertySet::Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertySet
的用法示例。
在下文中一共展示了PropertySet::Set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getProperties
PropertySet MF::getProperties() const {
PropertySet opts;
opts.Set( "tol", props.tol );
opts.Set( "maxiter", props.maxiter );
opts.Set( "verbose", props.verbose );
opts.Set( "damping", props.damping );
return opts;
}
示例2: getProperties
PropertySet CBP::getProperties() const {
PropertySet opts;
opts.Set( "tol", props.tol );
opts.Set( "maxiter", props.maxiter );
opts.Set( "verbose", props.verbose );
opts.Set( "logdomain", props.logdomain );
opts.Set( "updates", props.updates );
opts.Set( "damping", props.damping );
opts.Set( "inference", props.inference );
return opts;
}
示例3: getMarginals
void GI_libDAI::getMarginals(float* marginals,
const int label)
{
// Set some constants
Real tol = 1e-7;
//Real tol = 1e-9;
size_t verb = 0;
//size_t verb = 3;
size_t maxiter = 100;
// Store the constants in a PropertySet object
PropertySet opts;
#if LIBDAI_24
opts.Set("maxiter",maxiter); // Maximum number of iterations
opts.Set("tol",tol); // Tolerance for convergence
opts.Set("verbose",verb); // Verbosity (amount of output generated)
opts.Set("logdomain",false);
opts.Set("inference",string("MAXPROD"));
opts.Set("updates",string("SEQFIX"));
#else
opts.set("maxiter",maxiter); // Maximum number of iterations
opts.set("tol",tol); // Tolerance for convergence
opts.set("verbose",verb); // Verbosity (amount of output generated)
opts.set("logdomain",false);
opts.set("inference",string("MAXPROD"));
opts.set("updates",string("SEQFIX"));
#endif
FactorGraph fg( factors.begin(), factors.end(), vars.begin(), vars.end(), factors.size(), vars.size() );
BP bp(fg, opts);
bp.init();
bp.run();
for(long sid = 0; sid < slice->getNbSupernodes(); sid++) {
Factor f = bp.belief(fg.var(sid));
marginals[sid] = f[label];
}
}
示例4: getProperties
PropertySet ExactInf::getProperties() const {
PropertySet opts;
opts.Set( "verbose", props.verbose );
return opts;
}
示例5: main
//.........这里部分代码省略.........
// Set default factor type
if( !vm.count("factors") )
ft = FactorType::EXPGAUSS;
// Check validness of factor type
if( ft == FactorType::POTTS )
if( type == HOI_TYPE )
throw "For factors=='POTTS', interactions should be pairwise (type!='HOI')";
if( ft == FactorType::ISING )
if( ((states != 2) || (type == HOI_TYPE)) )
throw "For factors=='ISING', variables should be binary (states==2) and interactions should be pairwise (type!='HOI')";
// Read random seed
if( !vm.count("seed") ) {
ifstream infile;
bool success;
infile.open( "/dev/urandom" );
success = infile.is_open();
if( success ) {
infile.read( (char *)&seed, sizeof(size_t) / sizeof(char) );
success = infile.good();
infile.close();
}
if( !success )
throw "Please specify random number seed.";
}
rnd_seed( seed );
// Set default periodicity
if( !vm.count("periodic") )
periodic = false;
// Store some options in a PropertySet object
PropertySet options;
if( vm.count("mean_th") )
options.Set("mean_th", mean_th);
if( vm.count("sigma_th") )
options.Set("sigma_th", sigma_th);
if( vm.count("mean_w") )
options.Set("mean_w", mean_w);
if( vm.count("sigma_w") )
options.Set("sigma_w", sigma_w);
if( vm.count("beta") )
options.Set("beta", beta);
// Output some comments
cout << "# Factor graph made by " << argv[0] << endl;
cout << "# type = " << type << endl;
cout << "# states = " << states << endl;
// The factor graph to be constructed
FactorGraph fg;
#define NEED_ARG(name, desc) do { if(!vm.count(name)) throw "Please specify " desc " with --" name; } while(0);
if( type == FULL_TYPE || type == DREG_TYPE || type == LOOP_TYPE || type == TREE_TYPE || type == GRID_TYPE || type == GRID3D_TYPE ) {
// Pairwise interactions
// Check command line options
if( type == GRID_TYPE ) {
NEED_ARG("n1", "width of grid");
NEED_ARG("n2", "height of grid");
N = n1 * n2;
} else if( type == GRID3D_TYPE ) {
NEED_ARG("n1", "width of grid");
NEED_ARG("n2", "height of grid");
示例6: run
/**
* Run BP on a given factor graph
* @param nodeLabelsBP node inferred by BP
*/
double GI_libDAI::run(labelType* inferredLabels,
int id,
size_t maxiter,
labelType* nodeLabelsGroundTruth,
bool computeEnergyAtEachIteration,
double* _loss)
{
double energy = 0;
double loss = 0;
string paramMSRC;
Config::Instance()->getParameter("msrc", paramMSRC);
bool useMSRC = paramMSRC.c_str()[0] == '1';
bool replaceVoidMSRC = false;
if(useMSRC) {
Config::Instance()->getParameter("msrc_replace_void", paramMSRC);
replaceVoidMSRC = paramMSRC.c_str()[0] == '1';
}
// Set some constants
Real tol = 1e-7;
//Real tol = 1e-9;
size_t verb = 0;
//size_t verb = 3;
// Store the constants in a PropertySet object
PropertySet opts;
#if LIBDAI_24
opts.Set("maxiter",maxiter); // Maximum number of iterations
opts.Set("tol",tol); // Tolerance for convergence
opts.Set("verbose",verb); // Verbosity (amount of output generated)
opts.Set("logdomain",false);
opts.Set("inference",string("MAXPROD"));
opts.Set("updates",string("SEQFIX"));
#else
opts.set("maxiter",maxiter); // Maximum number of iterations
opts.set("tol",tol); // Tolerance for convergence
opts.set("verbose",verb); // Verbosity (amount of output generated)
opts.set("logdomain",false);
opts.set("inference",string("MAXPROD"));
opts.set("updates",string("SEQFIX"));
#endif
FactorGraph fg( factors.begin(), factors.end(), vars.begin(), vars.end(), factors.size(), vars.size() );
// Construct a BP (belief propagation) object from the FactorGraph fg
// using the parameters specified by opts and two additional properties,
// specifying the type of updates the BP algorithm should perform and
// whether they should be done in the real or in the logdomain
//BP bp(fg, opts("updates",string("SEQFIX"))("logdomain",true));
//BP bp(fg, opts("updates",string("SEQFIX"))("logdomain",false));
//BP bp(fg, opts("updates",string("SEQFIX"))("logdomain",false)("inference",string("MAXPROD")));
BP bp(fg, opts);
// Initialize belief propagation algorithm
bp.init();
vector<std::size_t> labels;
// Run belief propagation algorithm
if(computeEnergyAtEachIteration) {
#if OUTPUT_ENERGY
// one file per example
stringstream sEnergyMaxFile;
sEnergyMaxFile << "x_" << id;
sEnergyMaxFile << "_energyBPMax.txt";
ofstream ofsEnergyMax(sEnergyMaxFile.str().c_str(),ios::app);
#endif
int i = maxiter;
//for(int i = 1; i <= (int)maxiter; i+=10) // loop to see how energy evolves
{
//INFERENCE_PRINT("[gi_libDAI] BP Iteration %d\n", i);
#if LIBDAI_24
opts.Set("maxiter",(size_t)i); // Maximum number of iterations
#else
opts.set("maxiter",(size_t)i); // Maximum number of iterations
#endif
bp.setProperties(opts);
//Real maxDiff = bp.run();
bp.run();
labels = bp.findMaximum();
if(replaceVoidMSRC) {
if(lossPerLabel == 0) {
copyLabels_MSRC(labels, inferredLabels, bp, fg);
} else {
copy(labels.begin(),labels.end(),inferredLabels);
}
} else {
copy(labels.begin(),labels.end(),inferredLabels);
}
energy = GraphInference::computeEnergy(inferredLabels);
//.........这里部分代码省略.........