This file is indexed.

/usr/include/opengm/inference/auxiliary/fusion_move/high_level_fusion_mover.hxx is in libopengm-dev 2.3.6-2.

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
template<class T>
struct MaybeSetValue{
    T val_;
    bool isSet_;
    
};



template<class INDEX_TYPE>
class IntegralUnorderedMaxSizeSet{
public:
    IntegralUnorderedMaxSizeSet(const size_t maxIndex)
    :   maxSize_(maxIndex+1),
        indexInSet_(maxIndex+1,0),
        setSize_(0){
    }


    typedef INDEX_TYPE IndexType;
    void insert(const IndexType index){
        if(indexInSet_[index]==0){
            setElements_[setSize_]=index;
            indexInSet_[index]=1;
        }
    }
    bool hasIndex()const{
        return indexInSet_[index]!=0;
    }

    void removeAll()const{
        for(size_t i=0;i<setSize_;++i){
            indexInSet_[setElements_[i]]=0;
        }
    }

private:
    std::vector<unsigned  char> indexInSet_;
    std::vector<INDEX_TYPE    > setElements_;
    size_t setSize_;
};





template<class GM,class ACC>
class HighLevelFusionMover{
public:
    typedef ACC AccumulationType;
    typedef GM GmType;
    typedef GM GraphicalModelType;
    typedef INF InfType;
    typedef double QpboValueType
    OPENGM_GM_TYPE_TYPEDEFS;


    // function types
    typedef detail_fusion::ViewFixVariablesFunction<GM> FixFunction;
    typedef detail_fusion::FuseViewFunction<GM> FuseViewingFunction;
    typedef detail_fusion::FuseViewFixFunction<GM> FuseViewingFixingFunction;
    typedef ExplicitFunction<ValueType, IndexType, LabelType> ArrayFunction;




    #ifdef WITH_QPBO
    typedef kolmogorov::qpbo::QPBO<QpboValueType> QpboType;
    #endif 


    typedef std::vector<LabelType> StateVector;


    enum FusionSolver{
        QpboFusionSolver,
        CplexFusionSolver,
        BpFusionSolver,
        Ad3FusionSolver,
        LfFusionSolver,
        DefaultFusionSolver
    };


    struct ReductionParameter
    {
    public:
        bool Persistency_;
        bool Tentacle_;
        bool ConnectedComponents_;
        Parameter(
            const bool Persistency=false,
            const bool Tentacle=false,
            const bool ConnectedComponents=true
        ),
        :
            Persistency_ (Persistency),
            Tentacle_ (Tentacle),
            ConnectedComponents_ (ConnectedComponents)
        {
        };
    };

    
    struct FusionSolverParam{
        FusionSolverParam(
            const size_t subgraphSize=3,
            const size_t steps=0,
            const double damping=0.75
        ) 
        :   
            subgraphSize_(subgraphSize),
            steps_(steps),
            damping_(damping)
    {
        size_t subgraphSize_;
        size_t steps_;
        double damping_;
    };


    enum UnknownStateBehavior{
        TakeA,
        TakeB,
        TakeBest,
        Random
    };



    struct Parameter{
        Parameter(
            const FusionSolver fusionSolver                 = DefaultFusionSolver,
            const bool useReduction                         = true,
            const ReductionParameter & reductionParameter   = ReductionParameter(),
            const UnknownStateBehavior unknownStateBehavior = TakeA
        ) 
        :   fusionSolver_(fusionSolver),
            useReduction_(useReduction),
            reductionParameter_(reductionParameter),
            unknownStateBehavior_(unknownStateBehavior){
        }

        FusionSolver fusionSolver_;
        bool useReduction_;
        ReductionParameter reductionParameter_;
        UnknownStateBehavior unknownStateBehavior_;
    };


    struct FusionMoveResult{
        bool changeOrImprovement_;

    };

    HighLevelFusionMover(const GM & gm,const Parameter & parameter)
    :   gm_(gm),
        parameter_(parameter){

            this->setUpParameter();

    }


    FusionMoveResult fuse(
        const StateVector & proposalLabelsA,
        const StateVector & proposalLabelsB,
        StateVector       & resultLabels
    ){
        // mapping from local <=> global vi
        this->getForwardBackwardMapping(proposalLabelsA,proposalLabelsB);

        return fuse2Impl(proposalLabelsA,proposalLabelsB,resultLabels);
    }

    // fuse inplace
    FusionMoveResult fuse(
        const StateVector & proposalLabelsA,
        StateVector & proposalLabelsBAndResult,
    ){
        // mapping from local <=> global vi
        this->getForwardBackwardMapping(proposalLabelsA,proposalLabelsB);

        return fuse2Impl(proposalLabelsA,proposalLabelsBAndResult,proposalLabelsBAndResult);
    }

    // fuse vector
    template<class PROPOSAL_LABEL_ITERATOR>
    FusionMoveResult fuse(
        PROPOSAL_LABEL_ITERATOR proposalLabelsBegin,
        PROPOSAL_LABEL_ITERATOR proposalLabelsEnd,
        StateVector       & resultLabels
    ){
        //
        raise RuntimeError("not yet implemented");
    }

private:    
    template<class PROPOSAL_LABELS_A,class PROPOSAL_LABELS_B>
    void  getForwardBackwardMapping(
        const PROPOSAL_LABELS_A &       proposalLabelsA,
        const PROPOSAL_LABELS_B &       proposalLabelsB
    ){
        nLocalVar_ = 0;
        for (IndexType vi = 0; vi < gm_.numberOfVariables(); ++vi)
        {
            if (proposalLabelsA[vi] != proposalLabelsB[vi])
            {
                localToGlobalVi_[nLocalVar_] = vi;
                globalToLocalVi_[vi] = nLocalVar_;
                ++nLocalVar_;
            }
        }   
    }

    template<class PROPOSAL_LABELS_A,class PROPOSAL_LABELS_B,class MODEL_PROXY>
    void  setupSubmodelProxy(
        const PROPOSAL_LABELS_A & proposalLabelsA,
        const PROPOSAL_LABELS_B & proposalLabelsB
              MODEL_PROXY       & modelProxy
    )
    {
        for (IndexType lvi = 0; lvi < nLocalVar_; ++lvi)
        {
            const IndexType fi      = gm_.factorOfVariable(vi, f);
            const IndexType fOrder  = gm_.numberOfVariables(fi);

            // first order
            if (fOrder == 1)
            {
                OPENGM_CHECK_OP( localToGlobalVi_[lvi], == , gm_[fi].variableIndex(0), "internal error");
                OPENGM_CHECK_OP( globalToLocalVi_[gm_[fi].variableIndex(0)], == , lvi, "internal error");

                const IndexType vis[] = {lvi};
                const IndexType globalVi = localToGlobalVi_[lvi];

                // preallocate me!!!
                const float aTwo=2;
                ArrayFunction f(&aTwo,&aTwo+1);
                const LabelType c[] = { proposalLabelsA[globalVi],proposalLabelsB[globalVi]};
                f(0) = gm_[fi](c  );
                f(1) = gm_[fi](c + 1);
                modelProxy.addFactor(f, vis, vis + 1);
            }
            // high order
            else if ( addedFactors_.hasIndex(fi) == false )
            {
                addedFactors_.insert(fi);
                IndexType fixedVar      = 0;
                IndexType notFixedVar   = 0;

                for (IndexType vf = 0; vf < fOrder; ++vf)
                {
                    const IndexType viFactor = gm_[fi].variableIndex(vf);
                    if (proposalLabelsA[viFactor] != proposalLabelsB[viFactor])
                        notFixedVar += 1;
                    else
                        fixedVar += 1;
                }
                OPENGM_CHECK_OP(notFixedVar, > , 0, "internal error");

                if (fixedVar == 0)
                {
                    OPENGM_CHECK_OP(notFixedVar, == , fOrder, "interal error");
                    // preallocate me
                    std::vector<IndexType> lvis(fOrder);
                    for (IndexType vf = 0; vf < fOrder; ++vf)
                        lvis[vf] = globalToLocalVi_[gm_[fi].variableIndex(vf)];

                    FuseViewingFunction f(gm_[fi], *argA_, *argB_);
                    modelProxy.addFactor(f, lvis.begin(), lvis.end());
                }
                else
                {
                    OPENGM_CHECK_OP(notFixedVar + fixedVar, == , fOrder, "interal error")

                    // get local vis
                    std::vector<IndexType> lvis;
                    lvis.reserve(notFixedVar);
                    for (IndexType vf = 0; vf < fOrder; ++vf)
                    {
                        const IndexType gvi = gm_[fi].variableIndex(vf);
                        if ( proposalLabelsA[gvi] != proposalLabelsB[gvi])
                            lvis.push_back(globalToLocalVi_[gvi]);
                    }
                    OPENGM_CHECK_OP(lvis.size(), == , notFixedVar, "internal error");
                    FuseViewingFixingFunction f(gm_[fi], *argA_, *argB_);
                    modelProxy.addFactor(f, lvis.begin(), lvis.end());
                }
            }
        }
        addedFactors_.removeAll();
    } 

    template<class PROPOSAL_LABELS_A,class PROPOSAL_LABELS_B,class PROPOSAL_LABELS_RESULT>
    FusionMoveResult  fuse2Impl(
        const PROPOSAL_LABELS_A &       proposalLabelsA,
        const PROPOSAL_LABELS_B &       proposalLabelsB,
              PROPOSAL_LABELS_RESULT &  proposalLabelsResult
    ){



        // do the basic fusion 
        if(param_.fusionSolver_==QpboFusionSolver)
            return this->fuse2Qpbo(proposalLabelsA,proposalLabelsB,proposalLabelsResult);

        // do some kind of improvement?

    }

    template<class PROPOSAL_LABELS_A,class PROPOSAL_LABELS_B,class PROPOSAL_LABELS_RESULT>
    FusionMoveResult  fuse2Qpbo(
        const PROPOSAL_LABELS_A &       proposalLabelsA,
        const PROPOSAL_LABELS_B &       proposalLabelsB,
              PROPOSAL_LABELS_RESULT &  proposalLabelsResult
    ){
        if(maxFactorOrder_<=2)
            return this->fuse2QpboImproment2Order(proposalLabelsA,proposalLabelsB,proposalLabelsResult);
        else
            return this->fuse2QpboAnyOrder(proposalLabelsA,proposalLabelsB,proposalLabelsResult);
    } 

    template<class PROPOSAL_LABELS_A,class PROPOSAL_LABELS_B,class PROPOSAL_LABELS_RESULT>
    FusionMoveResult  fuse2Native(
        const PROPOSAL_LABELS_A &       proposalLabelsA,
        const PROPOSAL_LABELS_B &       proposalLabelsB,
              PROPOSAL_LABELS_RESULT &  proposalLabelsResult
    ){
        
    }

    template<class PROPOSAL_LABELS_A,class PROPOSAL_LABELS_B,class PROPOSAL_LABELS_RESULT>
    FusionMoveResult  fuse2QpboImproment2Order(
        const PROPOSAL_LABELS_A &       proposalLabelsA,
        const PROPOSAL_LABELS_B &       proposalLabelsB,
              PROPOSAL_LABELS_RESULT &  proposalLabelsResult
    ){

        #ifdef WITH_QPBO
        // set up qpbo problem
        setupSubmodelProxy(proposalLabelsA,proposalLabelsB,qpboModelProxy_);

        // solve qpbo with improvement 
        srand( 42 );
        qpboModelProxy_.model_->Improve();

        // get result arg
        if(param_.unknownStateBehavior_==TakeA || param_.unknownStateBehavior_==TakeB){
            for (IndexType lvi = 0; lvi < nLocalVar_; ++lvi)
            {
                const IndexType globalVi = localToGlobalVi_[lvi];
                const LabelType l = modelProxy.model_->GetLabel(lvi);
                if (l == 0)
                    proposalLabelsResult[globalVi] = proposalLabelsA)[globalVi] ;
                if (l == 1)
                    proposalLabelsResult[globalVi] = proposalLabelsB[globalVi] ;
                else
                {
                    if(param_.unknownStateBehavior_==TakeA )
                        proposalLabelsResult[globalVi] = proposalLabelsA)[globalVi] ;
                    else
                        proposalLabelsResult[globalVi] = proposalLabelsB)[globalVi] ;
                }
            }
        }
        else{
            throw RuntimeError("not yet implemented");
        }


        //reset the qpbo solver proxy
        qpboModelProxy_.reset();

        return FusionMoveResult();

        #else 
        throw RuntimeError("fuse2QpboImproment2Order needs WITH_QPBO to be enabled");
        return FusionMoveResult();
        #endif 
    }

    template<class PROPOSAL_LABELS_A,class PROPOSAL_LABELS_B,class PROPOSAL_LABELS_RESULT>
    FusionMoveResult  fuse2QpboAnyOrder(
        const PROPOSAL_LABELS_A &       proposalLabelsA,
        const PROPOSAL_LABELS_B &       proposalLabelsB,
              PROPOSAL_LABELS_RESULT &  proposalLabelsResult
    ){
        

    }






    void setUpParameter(){

    }

    // input data
    const GM & gm_;
    const Parameter parameter_;



    // working data
    IntegralUnorderedMaxSizeSet<IndexType> addedFactors_;
    size_t maxFactorOrder_;

    std::vector<IndexType> localToGlobalVi_;
    std::vector<IndexType> globalToLocalVi_;
    IndexType nLocalVar_;


    ValueType valueA_;
    ValueType valueB_;
    bool evaluatedA_;
    bool evaluatedB_;

    // QPBO RELATED DATA
    #ifdef WITH_QPBO
    detail_fusion::QpboModelProxy<QpboType> qpboModelProxy_;
    #endif 

};