📄 rosenbrock.cc
字号:
//============================================================// COOOL version 1.1 --- Nov, 1995// Center for Wave Phenomena, Colorado School of Mines//============================================================//// This code is part of a preliminary release of COOOL (CWP// Object-Oriented Optimization Library) and associated class // libraries. //// The COOOL library is a free software. You can do anything you want// with it including make a fortune. However, neither the authors,// the Center for Wave Phenomena, nor anyone else you can think of// makes any guarantees about anything in this package or any aspect// of its functionality.//// Since you've got the source code you can also modify the// library to suit your own purposes. We would appreciate it // if the headers that identify the authors are kept in the // source code.////=============================================================// Rosenbrock's function// Authors: H. Lydia Deng, Wences Gouveia//=============================================================#include <RosenBrock.hh>static const char* myNameIs = "RosenBrock";RosenBrock::RosenBrock(int n): ObjectiveFunction(n){ ;}RosenBrock::~RosenBrock(){ ; }double RosenBrock::temp1(double d1, double d0){ return (d1 - d0*d0);}double RosenBrock::temp2(double d0){ return (1. - d0);}double RosenBrock::realPerformance(const Model<double>& model){ double t0=model[0], tt, t1, d=0; for (int i=1; i < nparam; i++) { t1 = model[i]; tt = temp2(t0); d += tt*tt; tt = temp1(t1,t0); d += 100*tt*tt; t0 = t1; } return d;}double RosenBrock::realPerformance(const Model<long>& model){ Model<double> dm(model.modSize()); dm = model; return realPerformance(dm);}Vector<double>* RosenBrock::getGradient(const Model<double>& model){ double t0 = model[0]; double t1 = model[1]; double tt = 200*temp1(t1,t0); (*gradient)[0] = -2*t0*tt-2*temp2(t0); for (int i=1; i<nparam-1; i++) { (*gradient)[i] = tt; t0 = t1; t1 = model[i+1]; tt = 200*temp1(t1,t0); (*gradient)[i] += -2*t0*tt-2*temp2(t0); } (*gradient)[nparam-1] = tt; return gradient;}Vector<double>* RosenBrock::getGradient(const Model<long>& model){ Model<double> dm(model.modSize()); dm = model; return getGradient(dm);}const char* RosenBrock::className() const{ return(myNameIs);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -