trws_trws.hxx

Go to the documentation of this file.
00001 #ifndef TRWS_INTERFACE_HXX_
00002 #define TRWS_INTERFACE_HXX_
00003 #include <opengm/inference/inference.hxx>
00004 #include <opengm/inference/trws/trws_base.hxx>
00005 
00006 namespace opengm{
00007 
00008 template<class GM>
00009 struct TRWSi_Parameter : public trws_base::MaxSumTRWS_Parameters<typename GM::ValueType>
00010 {
00011    typedef typename GM::ValueType ValueType;
00012    typedef trws_base::MaxSumTRWS_Parameters<ValueType> parent;
00013    typedef trws_base::DecompositionStorage<GM> Storage;
00014 
00015    TRWSi_Parameter(size_t maxIternum=0,
00016                  typename Storage::StructureType decompositionType=Storage::GENERALSTRUCTURE,
00017                  ValueType precision=1.0,
00018                  bool absolutePrecision=true,
00019                  bool verbose=false)
00020    :parent(maxIternum,precision,absolutePrecision),
00021     decompositionType_(decompositionType),
00022     verbose_(verbose){}
00023 
00024    typename Storage::StructureType decompositionType_;
00025    bool verbose_;
00026 
00027    size_t& maxNumberOfIterations(){return parent::maxNumberOfIterations_;}
00028    ValueType& precision(){return parent::precision_;}
00029    bool& isAbsolutePrecision(){return parent::absolutePrecision_;};//true for absolute precision, false for relative w.r.t. dual value
00030    ValueType& minRelativeDualImprovement(){return parent::minRelativeDualImprovement_;}
00031    bool& fastComputations(){return parent::fastComputations_;}
00032    bool& canonicalNormalization(){return parent::canonicalNormalization_;};
00033    typename Storage::StructureType& decompositionType(){return decompositionType_;}
00034    bool& verbose(){return verbose_;};
00035 };
00036 
00053 
00054 template<class GM, class ACC>
00055 class TRWSi : public Inference<GM, ACC>
00056 {
00057 public:
00058   typedef ACC AccumulationType;
00059   typedef GM GraphicalModelType;
00060   OPENGM_GM_TYPE_TYPEDEFS;
00061   typedef trws_base::MaxSumTRWS<GM, ACC> Solver;
00062   typedef trws_base::DecompositionStorage<GM> Storage;
00063   typedef VerboseVisitor<TRWSi<GM, ACC> > VerboseVisitorType;
00064   typedef TimingVisitor<TRWSi<GM, ACC> > TimingVisitorType;
00065   typedef EmptyVisitor< TRWSi<GM, ACC> > EmptyVisitorType;
00066 
00067   typedef TRWSi_Parameter<GM> Parameter;
00068 
00069   TRWSi(const GraphicalModelType& gm, const Parameter& param
00070 #ifdef TRWS_DEBUG_OUTPUT
00071         ,std::ostream& fout=std::cout
00072 #endif
00073   ):
00074                     _storage(gm,param.decompositionType_),
00075                     _solver(_storage,param
00076 #ifdef TRWS_DEBUG_OUTPUT
00077                           ,(param.verbose_ ? fout : *OUT::nullstream::Instance()) //fout
00078 #endif
00079                     ){
00080      if (param.maxNumberOfIterations_==0) throw
00081            std::runtime_error("TRWSi: Maximal number of iterations (> 0) has to be specified!");
00082   }
00083   std::string name() const{ return "TRWSi"; }
00084   const GraphicalModelType& graphicalModel() const { return _storage.masterModel(); }
00085   InferenceTermination infer(){
00086      _solver.infer();
00087      return NORMAL;
00088   };
00089 
00090   template<class VISITOR> InferenceTermination infer(VISITOR & visitor){
00091      trws_base::VisitorWrapper<VISITOR,TRWSi<GM, ACC> > visiwrap(&visitor,this);
00092      _solver.infer(visiwrap);
00093      return NORMAL;
00094   };
00095 
00096   InferenceTermination arg(std::vector<LabelType>& out, const size_t = 1) const
00097      {
00098      out = _solver.arg();
00099      return opengm::NORMAL;}
00100   virtual ValueType bound() const{return _solver.bound();}
00101   virtual ValueType value() const{return _solver.value();}
00102   void getTreeAgreement(std::vector<bool>& out,std::vector<LabelType>* plabeling=0){_solver.getTreeAgreement(out,plabeling);}
00103   //const Storage& getDecompositionStorage()const{return _storage;}
00104   Storage& getDecompositionStorage(){return _storage;}
00105   const typename Solver::FactorProperties& getFactorProperties()const {return _solver.getFactorProperties();}
00106   private:
00107    Storage _storage;
00108    Solver _solver;
00109 };
00110 
00111 }
00112 #endif
00113 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:07 2013 for OpenGM by  doxygen 1.6.3