// Simple classifier that is 50% certain that the annotation is correct Eigen::MatrixXf computeUnary( const VectorXs & lbl, int M ){ const float u_energy = -log( 1.0 / M ); const float n_energy = -log( (1.0 - GT_PROB) / (M-1) ); const float p_energy = -log( GT_PROB ); Eigen::MatrixXf r( M, lbl.rows() ); r.fill(u_energy); //printf("%d %d %d \n",im[0],im[1],im[2]); for( int k=0; k<lbl.rows(); k++ ){ // Set the energy if (lbl[k]>=0){ r.col(k).fill( n_energy ); r(lbl[k],k) = p_energy; } } return r; }
Hamming::Hamming( const VectorXs & gt, float class_weight_pow ):gt_( gt ) { int M=0,N=gt.rows();; for( int i=0; i<N; i++ ) if( gt[i] >= M ) M = gt[i]+1; VectorXf cnt = VectorXf::Zero( M ); for( int i=0; i<N; i++ ) if( gt[i] >= 0 ) cnt[gt[i]] += 1; class_weight_ = cnt.array() / cnt.array().sum(); class_weight_ = class_weight_.array().pow( -class_weight_pow ); class_weight_ = class_weight_.array() / (cnt.array()*class_weight_.array()).sum(); }