c_cpp dlib bobyqa

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp dlib bobyqa相关的知识,希望对你有一定的参考价值。

#include "pch.h"
#include <dlib/optimization.h>
#include <dlib/global_optimization.h>
#include <iostream>

using namespace std;
using namespace dlib;

// variable length column vector
typedef matrix<double, 0, 1> column_vector;

class cost_fuction
{
public:
	cost_fuction(double a, double b, double c, double d) 
	{ // run all variable initialisation here
		target = { a, b, c, d };
	}

	double operator()(const column_vector &arg) const  
	{ // this will be called repeatedly during the optimization process
		return mean(squared(arg - target));
	}
private:
	column_vector target;
};

int main()
{

	// ----------------------- find_min_bobyqa() --------------------------- //
	column_vector starting_point = { -4, 5, 99, 3 };
	find_min_bobyqa(	cost_fuction(3, 5, 1, 7),
						starting_point,
						9,												// number of interpolation points
						uniform_matrix<double>(4, 1, -1e100), 			// lower bound constraint
						uniform_matrix<double>(4, 1, 1e100),  			// upper bound constraint
						10,												// initial trust region radius
						1e-6,											// stopping trust region radius
						100												// max number of objective function evaluations
	);
	
	cout << "find_min_bobyqa() solution:\n" << starting_point << endl;

	// --------------------- find_min_global() ---------------------------- //
	auto result = find_min_global(	cost_fuction(3, 49, 1, 7), 
									{ -50, -50, -50, -50 }, // lower bounds
									{ 100, 100, 100, 100},	// upper bounds
									max_function_calls(300));

	cout << "find_min_global() solution:\n" << result.x << endl;
}

以上是关于c_cpp dlib bobyqa的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp dlib图样本

c_cpp dlib矩阵运算

c_cpp 转换为dlib垫

c_cpp dlib_LearnSVM

c_cpp dlib_utils

c_cpp dlib min_cut