SHOGUN
v3.2.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2013 Shell Hu 00008 * Copyright (C) 2013 Shell Hu 00009 */ 00010 00011 #ifndef __MAP_INFERENCE_H__ 00012 #define __MAP_INFERENCE_H__ 00013 00014 #include <shogun/base/SGObject.h> 00015 #include <shogun/lib/SGVector.h> 00016 #include <shogun/structure/FactorGraph.h> 00017 #include <shogun/labels/FactorGraphLabels.h> 00018 00019 namespace shogun 00020 { 00021 00028 enum EMAPInferType 00029 { 00030 TREE_MAX_PROD = 0, 00031 LOOPY_MAX_PROD = 1, 00032 LP_RELAXATION = 2, 00033 TRWS_MAX_PROD = 3, 00034 ITER_COND_MODE = 4, 00035 NAIVE_MEAN_FIELD = 5, 00036 STRUCT_MEAN_FIELD = 6, 00037 }; 00038 00039 class CMAPInferImpl; 00040 00046 class CMAPInference : public CSGObject 00047 { 00048 public: 00050 CMAPInference(); 00051 00057 CMAPInference(CFactorGraph* fg, EMAPInferType inference_method); 00058 00060 virtual ~CMAPInference(); 00061 00063 virtual const char* get_name() const { return "MAPInference"; } 00064 00066 virtual void inference(); 00067 00072 CFactorGraphObservation* get_structured_outputs() const; 00073 00075 float64_t get_energy() const; 00076 00077 private: 00079 void init(); 00080 00081 protected: 00083 CFactorGraph* m_fg; 00084 00086 CFactorGraphObservation* m_outputs; 00087 00089 float64_t m_energy; 00090 00092 CMAPInferImpl* m_infer_impl; 00093 }; 00094 00098 class CMAPInferImpl : public CSGObject 00099 { 00100 public: 00102 CMAPInferImpl(); 00103 00108 CMAPInferImpl(CFactorGraph* fg); 00109 00111 virtual ~CMAPInferImpl(); 00112 00114 virtual const char* get_name() const { return "MAPInferImpl"; } 00115 00120 virtual float64_t inference(SGVector<int32_t> assignment) = 0; 00121 00122 private: 00124 void register_parameters(); 00125 00126 protected: 00128 CFactorGraph* m_fg; 00129 }; 00130 00131 } 00132 00133 #endif