/usr/include/shogun/structure/MAPInference.h is in libshogun-dev 3.2.0-7.3build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | /*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2013 Shell Hu
* Copyright (C) 2013 Shell Hu
*/
#ifndef __MAP_INFERENCE_H__
#define __MAP_INFERENCE_H__
#include <shogun/base/SGObject.h>
#include <shogun/lib/SGVector.h>
#include <shogun/structure/FactorGraph.h>
#include <shogun/labels/FactorGraphLabels.h>
namespace shogun
{
/** the following inference methods are acceptable:
* Tree Max Product, Loopy Max Product, LP Relaxation,
* Sequential Tree Reweighted Max Product (TRW-S),
* Iterated Conditional Mode (ICM), Naive Mean Field,
* Structured Mean Field.
*/
enum EMAPInferType
{
TREE_MAX_PROD = 0,
LOOPY_MAX_PROD = 1,
LP_RELAXATION = 2,
TRWS_MAX_PROD = 3,
ITER_COND_MODE = 4,
NAIVE_MEAN_FIELD = 5,
STRUCT_MEAN_FIELD = 6,
};
class CMAPInferImpl;
/** @brief Class CMAPInference performs MAP inference on a factor graph.
* Briefly, given a factor graph model, with features \f$\bold{x}\f$,
* the prediction is obtained by \f$ {\arg\max} _{\bold{y}} P(\bold{Y}
* = \bold{y} | \bold{x}; \bold{w}) \f$.
*/
class CMAPInference : public CSGObject
{
public:
/** default constructor */
CMAPInference();
/** constructor
*
* @param fg pointer of factor graph, i.e. structured inputs
* @param inference_method name of MAP inference method
*/
CMAPInference(CFactorGraph* fg, EMAPInferType inference_method);
/** destructor */
virtual ~CMAPInference();
/** @return class name */
virtual const char* get_name() const { return "MAPInference"; }
/** perform inference */
virtual void inference();
/** get structured outputs
*
* @return CFactorGraphObservation pointer
*/
CFactorGraphObservation* get_structured_outputs() const;
/** @return minimized energy */
float64_t get_energy() const;
private:
/** register parameters and initialize members */
void init();
protected:
/** pointer of factor graph */
CFactorGraph* m_fg;
/** structured outputs */
CFactorGraphObservation* m_outputs;
/** minimized energy */
float64_t m_energy;
/** opaque pointer to hide implementation */
CMAPInferImpl* m_infer_impl;
};
/** @brief Class CMAPInferImpl abstract class
* of MAP inference implementation
*/
class CMAPInferImpl : public CSGObject
{
public:
/** default constructor */
CMAPInferImpl();
/** constructor
*
* @param fg pointer of factor graph, i.e. structured inputs
*/
CMAPInferImpl(CFactorGraph* fg);
/** destructor */
virtual ~CMAPInferImpl();
/** @return class name */
virtual const char* get_name() const { return "MAPInferImpl"; }
/** perform inference (need to be implemented)
*
* @param assignment outputs of inference results
*/
virtual float64_t inference(SGVector<int32_t> assignment) = 0;
private:
/** register parameters */
void register_parameters();
protected:
/** pointer of factor graph */
CFactorGraph* m_fg;
};
}
#endif
|