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

Method featureGradient

dependency/densecrf3d/src/pairwise.cpp:88–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86 return g;
87 }
88 MatrixXf featureGradient( const MatrixXf & a, const MatrixXf & b ) const {
89 if (ntype_ == NO_NORMALIZATION )
90 return kernelGradient( a, b );
91 else if (ntype_ == NORMALIZE_SYMMETRIC ) {
92 MatrixXf fa = lattice_.compute( a*norm_.asDiagonal(), true );
93 MatrixXf fb = lattice_.compute( b*norm_.asDiagonal() );
94 MatrixXf ones = MatrixXf::Ones( a.rows(), a.cols() );
95 VectorXf norm3 = norm_.array()*norm_.array()*norm_.array();
96 MatrixXf r = kernelGradient( 0.5*( a.array()*fb.array() + fa.array()*b.array() ).matrix()*norm3.asDiagonal(), ones );
97 return - r + kernelGradient( a*norm_.asDiagonal(), b*norm_.asDiagonal() );
98 }
99 else if (ntype_ == NORMALIZE_AFTER ) {
100 MatrixXf fb = lattice_.compute( b );
101
102 MatrixXf ones = MatrixXf::Ones( a.rows(), a.cols() );
103 VectorXf norm2 = norm_.array()*norm_.array();
104 MatrixXf r = kernelGradient( ( a.array()*fb.array() ).matrix()*norm2.asDiagonal(), ones );
105 return - r + kernelGradient( a*norm_.asDiagonal(), b );
106 }
107 else /*if (ntype_ == NORMALIZE_BEFORE )*/ {
108 MatrixXf fa = lattice_.compute( a, true );
109
110 MatrixXf ones = MatrixXf::Ones( a.rows(), a.cols() );
111 VectorXf norm2 = norm_.array()*norm_.array();
112 MatrixXf r = kernelGradient( ( fa.array()*b.array() ).matrix()*norm2.asDiagonal(), ones );
113 return -r+kernelGradient( a, b*norm_.asDiagonal() );
114 }
115 }
116public:
117 DenseKernel(const MatrixXf & f, KernelType ktype, NormalizationType ntype):f_(f), ktype_(ktype), ntype_(ntype) {
118 if (ktype_ == DIAG_KERNEL) {

Callers

nothing calls this directly

Calls 6

computeMethod · 0.45
asDiagonalMethod · 0.45
rowsMethod · 0.45
colsMethod · 0.45
arrayMethod · 0.45
matrixMethod · 0.45

Tested by

no test coverage detected