Пример #1
0
  void HCholOptimizer<PG>::bottomToTop(int iterations, double lambda, bool initWithObservations){
    if (! _lowerOptimizer)
      return;
    if (_lowerOptimizer){
      _lowerOptimizer->bottomToTop(iterations, lambda,initWithObservations);
    }
    annotateHiearchicalEdges(iterations, lambda, initWithObservations);
    if (this->verbose())
      cerr << "_upperOptimizer="  << _upperOptimizer << endl;
    if (! _upperOptimizer){
      if (this->verbose())
	cerr << "Optimizing the top level" << endl;
      HVertex* rootVertex=_MY_CAST_<HVertex*>(this->vertices().begin()->second);
      this->initialize(rootVertex->id());
      //ofstream oss("topLevel.graph");
      //save(oss);
      //oss.close();
      Graph::VertexSet vset;
      for (Graph::VertexIDMap::const_iterator it=this->vertices().begin(); it!=this->vertices().end(); it++){
	vset.insert(it->second);
      }
      this->optimizeSubset(rootVertex, vset, iterations*3, lambda, true);
      if (this->verbose()) {
	cerr << "Done";
	//ofstream os("topLevel.dat");
	//saveAsGnuplot(os);
	//os.close();
	cerr << "done" << endl;
      }

    }
  }
 int CholOptimizer<PG>::optimize(int iterations, bool online){
   Graph::VertexSet vset;
   for (Graph::VertexIDMap::const_iterator it=vertices().begin(); it!=vertices().end(); it++){
     vset.insert(it->second);
   }
   
   typename PG::Vertex* root=dynamic_cast<typename PG::Vertex*>(vertex(_rootNode));
   if (! root)
     root=_MY_CAST_<typename PG::Vertex*>(vertices().begin()->second);
   if (verbose())
     cerr << "# root id " << root->id() << endl;
   bool initFromObservations = _guessOnEdges;
   optimizeSubset(root, vset, iterations, 0., initFromObservations);
   return iterations;
 }