23 template<
class GM,
class ACC>
42 const std::vector<LabelType>& startPoint
50 const std::vector<LabelType>& startPoint
67 ICM(
const GraphicalModelType&);
69 std::string
name()
const;
73 template<
class VisitorType>
81 const GraphicalModelType& gm_;
82 MovemakerType movemaker_;
88 template<
class GM,
class ACC>
94 template<
class GM,
class ACC>
106 template<
class GM,
class ACC>
117 if(parameter.
startPoint_.size() == gm.numberOfVariables()) {
118 movemaker_.initialize(parameter.
startPoint_.begin() );
125 template<
class GM,
class ACC>
129 if(param_.startPoint_.size() == gm_.numberOfVariables()) {
130 movemaker_.initialize(param_.startPoint_.begin() );
132 else if(param_.startPoint_.size() != 0) {
140 template<
class GM,
class ACC>
146 movemaker_.initialize(begin);
149 template<
class GM,
class ACC>
156 template<
class GM,
class ACC>
163 template<
class GM,
class ACC>
172 template<
class GM,
class ACC>
173 template<
class VisitorType>
180 visitor.begin(*
this);
183 std::vector<bool> isLocalOptimal(gm_.numberOfVariables());
184 std::vector<opengm::RandomAccessSet<IndexType> >variableAdjacencyList;
185 gm_.variableAdjacencyList(variableAdjacencyList);
187 while(updates && exitInf==
false) {
189 for(v=0; v<gm_.numberOfVariables() && exitInf==
false; ++v) {
190 if(isLocalOptimal[v]==
false) {
191 for(s=0; s<gm_.numberOfLabels(v); ++s) {
192 if(s != movemaker_.state(v)) {
193 if(AccumulationType::bop(movemaker_.valueAfterMove(&v, &v+1, &s), movemaker_.value())) {
194 movemaker_.move(&v, &v+1, &s);
195 for(n=0;n<variableAdjacencyList[v].size();++n) {
196 isLocalOptimal[variableAdjacencyList[v][n]]=
false;
205 isLocalOptimal[v]=
true;
210 if(param_.moveType_==
FACTOR) {
214 std::vector<bool> isLocalOptimal(gm_.numberOfFactors(),
false);
216 opengm::BufferVector<LabelType> stateBuffer;
217 stateBuffer.reserve(10);
220 while(updates && exitInf==
false) {
222 for(f=0; f<gm_.numberOfFactors() && exitInf==
false; ++f) {
223 if(isLocalOptimal[f]==
false && gm_[f].numberOfVariables()>1) {
225 stateBuffer.resize(gm_[f].numberOfVariables());
226 for(v=0;v<gm_[f].numberOfVariables();++v) {
227 stateBuffer[v]=movemaker_.state(gm_[f].variableIndex(v));
230 ValueType newValue=movemaker_.
template moveOptimally<ACC>(gm_[f].variableIndicesBegin(),gm_[f].variableIndicesEnd());
231 if(ACC::bop(newValue,oldValue)) {
237 for(v=0;v<gm_[f].numberOfVariables();++v) {
238 const size_t varIndex=gm_[f].variableIndex(v);
239 if(stateBuffer[v]!=movemaker_.state(varIndex)) {
240 for(ff=0;ff<gm_.numberOfFactors(varIndex);++ff) {
241 isLocalOptimal[gm_.factorOfVariable(varIndex,ff)]=
false;
246 isLocalOptimal[f]=
true;
255 template<
class GM,
class ACC>
259 std::vector<LabelType>& x,
264 x.resize(gm_.numberOfVariables());
265 for(
size_t j=0; j<x.size(); ++j) {
266 x[j] = movemaker_.state(j);
277 #endif // #ifndef OPENGM_ICM_HXX
virtual ValueType value() const
return the solution (value)
Movemaker< GraphicalModelType > MovemakerType
std::vector< LabelType > startPoint_
void setStartingPoint(typename std::vector< LabelType >::const_iterator)
set initial labeling
Parameter(MoveType moveType=SINGLE_VARIABLE)
virtual InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
output a solution
opengm::visitors::TimingVisitor< ICM< GM, ACC > > TimingVisitorType
Parameter(const std::vector< LabelType > &startPoint)
const GraphicalModelType & graphicalModel() const
GraphicalModelType::ValueType ValueType
Inference algorithm interface.
Iterated Conditional Modes Algorithm J. E. Besag, "On the Statistical Analysis of Dirty Pictures"...
opengm::visitors::VerboseVisitor< ICM< GM, ACC > > VerboseVisitorType
opengm::visitors::EmptyVisitor< ICM< GM, ACC > > EmptyVisitorType
ICM(const GraphicalModelType &)
GraphicalModelType::LabelType LabelType
InferenceTermination infer()
static const size_t ContinueInf
Parameter(MoveType moveType, const std::vector< LabelType > &startPoint)
size_t currentMoveType() const