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

Function numericGradient

dependency/densecrf/src/optimization.cpp:104–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102 return x0;
103}
104VectorXf numericGradient( EnergyFunction & efun, const VectorXf & x, float EPS ) {
105 VectorXf g( x.rows() ), tmp;
106 for( int i=0; i<x.rows(); i++ ) {
107 VectorXf xx = x;
108 xx[i] = x[i]+EPS;
109 double v1 = efun.gradient( xx, tmp );
110 xx[i] = x[i]-EPS;
111 double v0 = efun.gradient( xx, tmp );
112 g[i] = (v1-v0)/(2*EPS);
113 }
114 return g;
115}
116VectorXf gradient( EnergyFunction & efun, const VectorXf & x ) {
117 VectorXf r( x.rows() );
118 efun.gradient( x, r );

Callers 3

gradCheckFunction · 0.70
mainFunction · 0.50
mainFunction · 0.50

Calls 2

rowsMethod · 0.45
gradientMethod · 0.45

Tested by 2

mainFunction · 0.40
mainFunction · 0.40