assert( opts.hasKey("verbose") );
assert( opts.hasKey("cavity") );
assert( opts.hasKey("updates") );
-
+
props.tol = opts.getStringAs<double>("tol");
props.maxiter = opts.getStringAs<size_t>("maxiter");
props.verbose = opts.getStringAs<size_t>("verbose");
// create pancakes
_pancakes.resize( nrVars() );
-
+
// create cavitydists
for( size_t i=0; i < nrVars(); i++ )
_cavitydists.push_back(Factor( delta(i) ));
}
-string LC::identify() const {
+string LC::identify() const {
return string(Name) + printProperties();
}
double maxdiff = 0;
if( props.verbose >= 2 )
- cout << "Initing cavity " << var(i) << "(" << delta(i).size() << " vars, " << delta(i).nrStates() << " states)" << endl;
+ cerr << "Initing cavity " << var(i) << "(" << delta(i).size() << " vars, " << delta(i).nrStates() << " states)" << endl;
if( props.cavity == Properties::CavityType::UNIFORM )
Bi = Factor(delta(i));
double tic = toc();
if( props.verbose >= 1 ) {
- cout << Name << "::InitCavityDists: ";
+ cerr << Name << "::InitCavityDists: ";
if( props.cavity == Properties::CavityType::UNIFORM )
- cout << "Using uniform initial cavity distributions" << endl;
+ cerr << "Using uniform initial cavity distributions" << endl;
else if( props.cavity == Properties::CavityType::FULL )
- cout << "Using full " << name << opts << "...";
+ cerr << "Using full " << name << opts << "...";
else if( props.cavity == Properties::CavityType::PAIR )
- cout << "Using pairwise " << name << opts << "...";
+ cerr << "Using pairwise " << name << opts << "...";
else if( props.cavity == Properties::CavityType::PAIR2 )
- cout << "Using pairwise(new) " << name << opts << "...";
+ cerr << "Using pairwise(new) " << name << opts << "...";
}
double maxdiff = 0.0;
}
if( props.verbose >= 1 ) {
- cout << Name << "::InitCavityDists used " << toc() - tic << " seconds." << endl;
+ cerr << Name << "::InitCavityDists used " << toc() - tic << " seconds." << endl;
}
return maxdiff;
long LC::SetCavityDists( std::vector<Factor> &Q ) {
- if( props.verbose >= 1 )
- cout << Name << "::SetCavityDists: Setting initial cavity distributions" << endl;
+ if( props.verbose >= 1 )
+ cerr << Name << "::SetCavityDists: Setting initial cavity distributions" << endl;
if( Q.size() != nrVars() )
return -1;
for( size_t i = 0; i < nrVars(); i++ ) {
piet.normalize();
if( piet.hasNaNs() ) {
- cout << Name << "::NewPancake(" << i << ", " << _I << "): has NaNs!" << endl;
+ cerr << Name << "::NewPancake(" << i << ", " << _I << "): has NaNs!" << endl;
hasNaNs = true;
}
double LC::run() {
if( props.verbose >= 1 )
- cout << "Starting " << identify() << "...";
+ cerr << "Starting " << identify() << "...";
if( props.verbose >= 2 )
- cout << endl;
+ cerr << endl;
double tic = toc();
Diffs diffs(nrVars(), 1.0);
for( size_t i = 0; i < nrVars(); i++ ) {
_pancakes[i] = _cavitydists[i];
-
+
foreach( const Neighbor &I, nbV(i) ) {
_pancakes[i] *= factor(I);
if( props.updates == Properties::UpdateType::SEQRND )
_pancakes[i] *= _phis[i][I.iter];
}
-
+
_pancakes[i].normalize();
CalcBelief(i);
break;
}
if( hasNaNs ) {
- cout << Name << "::run: initial _pancakes has NaNs!" << endl;
+ cerr << Name << "::run: initial _pancakes has NaNs!" << endl;
return 1.0;
}
// Sequential updates
if( props.updates == Properties::UpdateType::SEQRND )
random_shuffle( update_seq.begin(), update_seq.end() );
-
+
for( size_t t=0; t < nredges; t++ ) {
size_t i = update_seq[t].first;
size_t _I = update_seq[t].second;
}
if( props.verbose >= 3 )
- cout << Name << "::run: maxdiff " << diffs.maxDiff() << " after " << _iters+1 << " passes" << endl;
+ cerr << Name << "::run: maxdiff " << diffs.maxDiff() << " after " << _iters+1 << " passes" << endl;
}
if( diffs.maxDiff() > _maxdiff )
if( props.verbose >= 1 ) {
if( diffs.maxDiff() > props.tol ) {
if( props.verbose == 1 )
- cout << endl;
- cout << Name << "::run: WARNING: not converged within " << props.maxiter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << diffs.maxDiff() << endl;
+ cerr << endl;
+ cerr << Name << "::run: WARNING: not converged within " << props.maxiter << " passes (" << toc() - tic << " seconds)...final maxdiff:" << diffs.maxDiff() << endl;
} else {
if( props.verbose >= 2 )
- cout << Name << "::run: ";
- cout << "converged in " << _iters << " passes (" << toc() - tic << " seconds)." << endl;
+ cerr << Name << "::run: ";
+ cerr << "converged in " << _iters << " passes (" << toc() - tic << " seconds)." << endl;
}
}