23 template<
class GM,
class ACC>
44 template<
class _GM,
class _ACC>
55 startPoint_(startPoint)
58 : moveType_(moveType),
59 startPoint_(startPoint)
63 : moveType_(moveType),
71 startPoint_(otherParameter.startPoint_);
78 ICM(
const GraphicalModelType&);
80 std::string
name()
const;
84 template<
class VisitorType>
92 const GraphicalModelType& gm_;
93 MovemakerType movemaker_;
99 template<
class GM,
class ACC>
105 template<
class GM,
class ACC>
117 template<
class GM,
class ACC>
128 if(parameter.
startPoint_.size() == gm.numberOfVariables()) {
129 movemaker_.initialize(parameter.
startPoint_.begin() );
136 template<
class GM,
class ACC>
140 if(param_.startPoint_.size() == gm_.numberOfVariables()) {
141 movemaker_.initialize(param_.startPoint_.begin() );
143 else if(param_.startPoint_.size() != 0) {
151 template<
class GM,
class ACC>
157 movemaker_.initialize(begin);
160 template<
class GM,
class ACC>
167 template<
class GM,
class ACC>
174 template<
class GM,
class ACC>
183 template<
class GM,
class ACC>
184 template<
class VisitorType>
191 visitor.begin(*
this);
194 std::vector<bool> isLocalOptimal(gm_.numberOfVariables());
195 std::vector<opengm::RandomAccessSet<IndexType> >variableAdjacencyList;
196 gm_.variableAdjacencyList(variableAdjacencyList);
198 while(updates && exitInf==
false) {
200 for(v=0; v<gm_.numberOfVariables() && exitInf==
false; ++v) {
201 if(isLocalOptimal[v]==
false) {
202 for(s=0; s<gm_.numberOfLabels(v); ++s) {
203 if(s != movemaker_.state(v)) {
204 if(AccumulationType::bop(movemaker_.valueAfterMove(&v, &v+1, &s), movemaker_.value())) {
205 movemaker_.move(&v, &v+1, &s);
206 for(n=0;n<variableAdjacencyList[v].size();++n) {
207 isLocalOptimal[variableAdjacencyList[v][n]]=
false;
216 isLocalOptimal[v]=
true;
221 if(param_.moveType_==
FACTOR) {
225 std::vector<bool> isLocalOptimal(gm_.numberOfFactors(),
false);
227 opengm::BufferVector<LabelType> stateBuffer;
228 stateBuffer.reserve(10);
231 while(updates && exitInf==
false) {
233 for(f=0; f<gm_.numberOfFactors() && exitInf==
false; ++f) {
234 if(isLocalOptimal[f]==
false && gm_[f].numberOfVariables()>1) {
236 stateBuffer.resize(gm_[f].numberOfVariables());
237 for(v=0;v<gm_[f].numberOfVariables();++v) {
238 stateBuffer[v]=movemaker_.state(gm_[f].variableIndex(v));
241 ValueType newValue=movemaker_.
template moveOptimally<ACC>(gm_[f].variableIndicesBegin(),gm_[f].variableIndicesEnd());
242 if(ACC::bop(newValue,oldValue)) {
248 for(v=0;v<gm_[f].numberOfVariables();++v) {
249 const size_t varIndex=gm_[f].variableIndex(v);
250 if(stateBuffer[v]!=movemaker_.state(varIndex)) {
251 for(ff=0;ff<gm_.numberOfFactors(varIndex);++ff) {
252 isLocalOptimal[gm_.factorOfVariable(varIndex,ff)]=
false;
257 isLocalOptimal[f]=
true;
266 template<
class GM,
class ACC>
270 std::vector<LabelType>& x,
275 x.resize(gm_.numberOfVariables());
276 for(
size_t j=0; j<x.size(); ++j) {
277 x[j] = movemaker_.state(j);
288 #endif // #ifndef OPENGM_ICM_HXX
virtual ValueType value() const
return the solution (value)
virtual InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
output a solution
Movemaker< GraphicalModelType > MovemakerType
std::vector< LabelType > startPoint_
void setStartingPoint(typename std::vector< LabelType >::const_iterator)
set initial labeling
Parameter(MoveType moveType=SINGLE_VARIABLE)
opengm::visitors::TimingVisitor< ICM< GM, ACC > > TimingVisitorType
Parameter(const std::vector< LabelType > &startPoint)
size_t currentMoveType() const
GraphicalModelType::ValueType ValueType
Inference algorithm interface.
Iterated Conditional Modes Algorithm J. E. Besag, "On the Statistical Analysis of Dirty Pictures"...
const GraphicalModelType & graphicalModel() const
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)
Parameter(const OP &otherParameter)