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

Function minimizeLBFGS

dependency/densecrf/src/optimization.cpp:68–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66 return 0;
67}
68VectorXf minimizeLBFGS( EnergyFunction & efun, int restart, bool verbose ) {
69 VectorXf x0 = efun.initialValue();
70 const int n = x0.rows();
71
72 lbfgsfloatval_t *x = lbfgs_malloc(n);
73 if (x == NULL) {
74 printf("ERROR: Failed to allocate a memory block for variables.\n");
75 return x0;
76 }
77 std::copy( x0.data(), x0.data()+n, x );
78
79 lbfgs_parameter_t param;
80 lbfgs_parameter_init(&param);
81 // You might want to adjust the parameters to your problem
82 param.epsilon = 1e-6;
83 param.max_iterations = 50;
84
85 double last_f = 1e100;
86 int ret;
87 for( int i=0; i<=restart; i++ ) {
88 lbfgsfloatval_t fx;
89 ret = lbfgs(n, x, &fx, evaluate, verbose?progress:NULL, &efun, &param);
90 if( last_f > fx )
91 last_f = fx;
92 else
93 break;
94 }
95
96 if ( verbose ) {
97 printf("L-BFGS optimization terminated with status code = %d\n", ret);
98 }
99
100 std::copy( x, x+n, x0.data() );
101 lbfgs_free(x);
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++ ) {

Callers 4

mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls 7

lbfgs_mallocFunction · 0.50
lbfgs_parameter_initFunction · 0.50
lbfgsFunction · 0.50
lbfgs_freeFunction · 0.50
initialValueMethod · 0.45
rowsMethod · 0.45
dataMethod · 0.45

Tested by 3

mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40