vnl_amoeba.cxx

来自「InsightToolkit-1.4.0(有大量的优化算法程序)」· CXX 代码 · 共 45 行

CXX
45
字号
//-*- c++ -*-------------------------------------------------------------------
// Module: Minimization of Rosenbrock banana function, downhill simplex
// Author: Andrew W. Fitzgibbon, Oxford RRG
// Created: 31 Aug 96
// Converted to vxl by Peter Vanroose, February 2000
//-----------------------------------------------------------------------------

#include <vcl_iostream.h>
#include <vnl/vnl_vector.h>
#include <vnl/vnl_cost_function.h>
#include <vnl/algo/vnl_amoeba.h>

// See rosenbrock.cxx for a description of this function.
class vnl_rosenbrock : public vnl_cost_function {
public:
  vnl_rosenbrock(): vnl_cost_function(2) {}

  double f(const vnl_vector<double>& x)
  {
    double u = 10*(x[1] - x[0]*x[0]);
    double v = 1 - x[0];
    return u*u + v*v;
  }
};

int main()
{
  // Set up a Rosenbrock compute object
  vnl_rosenbrock f;

  // Set up the initial guess
  vnl_vector<double> x(2);
  x[0] = -1.9;
  x[1] = 2.0;

  // Make a Levenberg Marquardt minimizer, attach f to it, and
  // run the minimization
  vnl_amoeba::minimize(f, x);

  // Summarize the results
  vcl_cout << "Rosenbrock min at " << x << '\n';

  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?