更新progress回调函数
增加了lbfgs_parameter_t参数以监控反演进度
This commit is contained in:
		| @@ -505,7 +505,7 @@ int lbfgs( | ||||
|         /* Report the progress. */ | ||||
|         if (cd.proc_progress) { | ||||
|             // 如果监控函数返回值不为0 则退出迭过程 | ||||
|             if ((ret = cd.proc_progress(cd.instance, x, g, fx, xnorm, gnorm, step, cd.n, k, ls))) { | ||||
|             if ((ret = cd.proc_progress(cd.instance, x, g, fx, xnorm, gnorm, step, param, cd.n, k, ls))) { | ||||
|                 goto lbfgs_exit; | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -441,6 +441,7 @@ typedef lbfgsfloatval_t (*lbfgs_evaluate_t)( | ||||
|  *  @param  xnorm       The Euclidean norm of the variables. | ||||
|  *  @param  gnorm       The Euclidean norm of the gradients. | ||||
|  *  @param  step        The line-search step used for this iteration. | ||||
|  *  @param  param       这是我们添加了一个指针以使用参数类型来监控迭代流程 | ||||
|  *  @param  n           The number of variables. | ||||
|  *  @param  k           The iteration count. | ||||
|  *  @param  ls          The number of evaluations called for this iteration. | ||||
| @@ -455,6 +456,7 @@ typedef int (*lbfgs_progress_t)( | ||||
|     const lbfgsfloatval_t xnorm, | ||||
|     const lbfgsfloatval_t gnorm, | ||||
|     const lbfgsfloatval_t step, | ||||
|     const lbfgs_parameter_t param, | ||||
|     int n, | ||||
|     int k, | ||||
|     int ls | ||||
|   | ||||
| @@ -30,6 +30,7 @@ static int progress( | ||||
|     const lbfgsfloatval_t xnorm, | ||||
|     const lbfgsfloatval_t gnorm, | ||||
|     const lbfgsfloatval_t step, | ||||
|     const lbfgs_parameter_t param, | ||||
|     int n, | ||||
|     int k, | ||||
|     int ls | ||||
|   | ||||
| @@ -87,12 +87,13 @@ protected: | ||||
|         const lbfgsfloatval_t xnorm, | ||||
|         const lbfgsfloatval_t gnorm, | ||||
|         const lbfgsfloatval_t step, | ||||
|         const lbfgs_parameter_t param, | ||||
|         int n, | ||||
|         int k, | ||||
|         int ls | ||||
|         ) | ||||
|     { | ||||
|         return reinterpret_cast<objective_function*>(instance)->progress(x, g, fx, xnorm, gnorm, step, n, k, ls); | ||||
|         return reinterpret_cast<objective_function*>(instance)->progress(x, g, fx, xnorm, gnorm, step, param, n, k, ls); | ||||
|     } | ||||
|  | ||||
|     int progress( | ||||
| @@ -102,6 +103,7 @@ protected: | ||||
|         const lbfgsfloatval_t xnorm, | ||||
|         const lbfgsfloatval_t gnorm, | ||||
|         const lbfgsfloatval_t step, | ||||
|         const lbfgs_parameter_t param, | ||||
|         int n, | ||||
|         int k, | ||||
|         int ls | ||||
|   | ||||
| @@ -20,14 +20,14 @@ public: | ||||
| 		const int n, const lbfgsfloatval_t step); | ||||
|  | ||||
| 	static int _Progress(void *instance, const lbfgsfloatval_t *x, const lbfgsfloatval_t *g, const lbfgsfloatval_t fx, | ||||
| 		const lbfgsfloatval_t xnorm, const lbfgsfloatval_t gnorm, const lbfgsfloatval_t step, | ||||
| 		const lbfgsfloatval_t xnorm, const lbfgsfloatval_t gnorm, const lbfgsfloatval_t step, const lbfgs_parameter_t param, | ||||
| 		int n, int k, int ls) | ||||
| 	{ | ||||
| 		return reinterpret_cast<TEST_FUNC*>(instance)->Progress(x, g, fx, xnorm, gnorm, step, n, k, ls); | ||||
| 		return reinterpret_cast<TEST_FUNC*>(instance)->Progress(x, g, fx, xnorm, gnorm, step, param, n, k, ls); | ||||
| 	} | ||||
|  | ||||
| 	int Progress(const lbfgsfloatval_t *x, const lbfgsfloatval_t *g, const lbfgsfloatval_t fx, | ||||
| 		const lbfgsfloatval_t xnorm, const lbfgsfloatval_t gnorm, const lbfgsfloatval_t step, | ||||
| 		const lbfgsfloatval_t xnorm, const lbfgsfloatval_t gnorm, const lbfgsfloatval_t step, const lbfgs_parameter_t param, | ||||
| 		int n, int k, int ls); | ||||
|  | ||||
| 	int Routine(); | ||||
| @@ -67,7 +67,7 @@ lbfgsfloatval_t TEST_FUNC::Func(const lbfgsfloatval_t *x, lbfgsfloatval_t *g, | ||||
| } | ||||
|  | ||||
| int TEST_FUNC::Progress(const lbfgsfloatval_t *x, const lbfgsfloatval_t *g, const lbfgsfloatval_t fx, | ||||
| 		const lbfgsfloatval_t xnorm, const lbfgsfloatval_t gnorm, const lbfgsfloatval_t step, | ||||
| 		const lbfgsfloatval_t xnorm, const lbfgsfloatval_t gnorm, const lbfgsfloatval_t step, const lbfgs_parameter_t param, | ||||
| 		int n, int k, int ls) | ||||
| { | ||||
| 	clog << "iteration times: " << k << " fx = " << fx << " gnorm/xnorm = " << gnorm/xnorm << endl; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user