本文整理汇总了C++中Energy::SetOneHOP方法的典型用法代码示例。如果您正苦于以下问题:C++ Energy::SetOneHOP方法的具体用法?C++ Energy::SetOneHOP怎么用?C++ Energy::SetOneHOP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Energy
的用法示例。
在下文中一共展示了Energy::SetOneHOP方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: robustpn
//.........这里部分代码省略.........
mexErrMsgIdAndTxt("robustpn:inputs","hop must be a struct array");
nHigher = mxGetNumberOfElements(pin[2]);
// expecting HOP_N_OF_FIELDS fieds
if ( mxGetNumberOfFields(pin[2]) != HOP_N_OF_FIELDS )
mexErrMsgIdAndTxt("robustpn:inputs","hop must have %d fields", HOP_N_OF_FIELDS);
// chack that we have the right fields
for ( ii = 0; ii < HOP_N_OF_FIELDS ; ii++ ) {
hop_fields_indices[ii] = mxGetFieldNumber(pin[2], HOP_FIELDS[ii]);
if ( hop_fields_indices[ii] < 0 )
mexErrMsgIdAndTxt("robustpn:inputs","hop is missing %s field", HOP_FIELDS[ii]);
}
Energy<termType> *energy = new Energy<termType>(nLabel, nVar, nPair, nHigher);
energy->SetUnaryCost( (termType*)mxGetData(pin[1]) );
energy->SetPairCost(pairs, sc);
delete[] pairs; // were copied into energy
delete[] sc;
// Add the HO potentials
mxArray *xind, *xw, *xgamma, *xQ;
int * ind, n;
termType* w;
termType* gamma;
termType Q;
for ( ii = 0 ; ii < nHigher; ii++ ) {
xind = mxGetFieldByNumber(pin[2], ii, hop_fields_indices[0]);
n = mxGetNumberOfElements(xind);
ind = new int[n]; // allocation for energy
GetArr(xind, ind, -1); // bias = -1 convert from 1-ind of matlab to 0-ind of C
xw = mxGetFieldByNumber(pin[2], ii, hop_fields_indices[1]);
if ( mxGetNumberOfElements(xw) != n ) {
delete energy;
delete[] ind;
mexErrMsgIdAndTxt("robustpn:inputs","hop %d: number of indices is different than number of weights", ii);
}
w = new termType[n]; // allocation for energy
GetArr(xw, w);
xgamma = mxGetFieldByNumber(pin[2], ii, hop_fields_indices[2]);
if ( mxGetNumberOfElements(xgamma) != nLabel+1 ) {
delete energy;
delete[] ind;
delete[] w;
mexErrMsgIdAndTxt("robustpn:inputs","hop %d: must have exactly %d gamma values", ii, nLabel+1);
}
gamma = new termType[nLabel+1];
GetArr(xgamma, gamma);
xQ = mxGetFieldByNumber(pin[2], ii, hop_fields_indices[3]);
Q = (termType)mxGetScalar(xQ);
if ( energy->SetOneHOP(n, ind, w, gamma, Q) < 0 ) {
delete energy;
delete[] gamma;
mexErrMsgIdAndTxt("robustpn:inputs","failed to load hop #%d", ii);
}
delete[] gamma; // this array is being allocated inside energy
// mexPrintf("Done reading hop(%d) / %d\n", ii, nHigher);
}
// mexPrintf("Done reading hops\n");
/*
*********************************************************
* Minimize energy
**********************************************************
*/
//initialize alpha expansion - max MAX_ITER iterations
AExpand<termType> *expand = new AExpand<termType>(energy, MAX_ITER);
// must have at least one output for the labels
pout[0] = mxCreateNumericMatrix(1, nVar, mxINT32_CLASS, mxREAL);
int *solution = (int*)mxGetData(pout[0]);
// Do we have an initial guess of labeling ?
if ( nin == 4 ) {
if ( mxGetNumberOfElements(pin[3]) != nVar )
mexErrMsgIdAndTxt("robustpn:inputs","Initial guess of labeling must have exactly %d elements", nVar);
GetArr(pin[3], solution, -1); // convert Matlab's 1-ind labeling to C's 0-ind labeling
} else {
// default initial labeling
memset(solution, 0, nVar*sizeof(int));
}
termType ee[3];
termType E(0);
E = expand->minimize(solution, ee);
if (nout>1) {
pout[1] = mxCreateNumericMatrix(1, 4, mxGetClassID(pin[1]), mxREAL);
termType *pE = (termType*)mxGetData(pout[1]);
pE[0] = ee[0];
pE[1] = ee[1];
pE[2] = ee[2];
pE[3] = E;
}
// de-allocate
delete expand;
delete energy;
}