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

Method gradient

dependency/densecrf/examples/dense_learning.cpp:60–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58 return p;
59 }
60 virtual double gradient( const VectorXf & x, VectorXf & dx ) {
61 int p = 0;
62 if (unary_) {
63 crf_.setUnaryParameters( x.segment( p, initial_u_param_.rows() ) );
64 p += initial_u_param_.rows();
65 }
66 if (pairwise_) {
67 crf_.setLabelCompatibilityParameters( x.segment( p, initial_lbl_param_.rows() ) );
68 p += initial_lbl_param_.rows();
69 }
70 if (kernel_)
71 crf_.setKernelParameters( x.segment( p, initial_knl_param_.rows() ) );
72
73 VectorXf du = 0*initial_u_param_, dl = 0*initial_u_param_, dk = 0*initial_knl_param_;
74 double r = crf_.gradient( NIT_, objective_, unary_?&du:NULL, pairwise_?&dl:NULL, kernel_?&dk:NULL );
75 dx.resize( unary_*du.rows() + pairwise_*dl.rows() + kernel_*dk.rows() );
76 dx << -(unary_?du:VectorXf()), -(pairwise_?dl:VectorXf()), -(kernel_?dk:VectorXf());
77 r = -r;
78 if( l2_norm_ > 0 ) {
79 dx += l2_norm_ * x;
80 r += 0.5*l2_norm_ * (x.dot(x));
81 }
82
83 return r;
84 }
85};
86
87int main( int argc, char* argv[]){

Callers

nothing calls this directly

Calls 6

setUnaryParametersMethod · 0.45
rowsMethod · 0.45
setKernelParametersMethod · 0.45
resizeMethod · 0.45
dotMethod · 0.45

Tested by

no test coverage detected