MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / klDivergence

Method klDivergence

dependency/densecrf/src/densecrf.cpp:214–235  ·  view source on GitHub ↗

Compute the KL-divergence of a set of marginals

Source from the content-addressed store, hash-verified

212
213// Compute the KL-divergence of a set of marginals
214double DenseCRF::klDivergence( const MatrixXf & Q ) const {
215 double kl = 0;
216 // Add the entropy term
217 for( int i=0; i<Q.cols(); i++ )
218 for( int l=0; l<Q.rows(); l++ )
219 kl += Q(l,i)*log(std::max( Q(l,i), 1e-20f) );
220 // Add the unary term
221 if( unary_ ) {
222 MatrixXf unary = unary_->get();
223 for( int i=0; i<Q.cols(); i++ )
224 for( int l=0; l<Q.rows(); l++ )
225 kl += unary(l,i)*Q(l,i);
226 }
227
228 // Add all pairwise terms
229 MatrixXf tmp;
230 for( unsigned int k=0; k<pairwise_.size(); k++ ) {
231 pairwise_[k]->apply( tmp, Q );
232 kl += (Q.array()*tmp.array()).sum();
233 }
234 return kl;
235}
236
237// Gradient computations
238double DenseCRF::gradient( int n_iterations, const ObjectiveFunction & objective, VectorXf * unary_grad, VectorXf * lbl_cmp_grad, VectorXf * kernel_grad) const {

Callers

nothing calls this directly

Calls 8

logFunction · 0.50
colsMethod · 0.45
rowsMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
applyMethod · 0.45
sumMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected