📄 griewank.cc
字号:
//============================================================// COOOL version 1.2 --- Feb, 1996// 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.////=============================================================// Griewank function// Author: H. Lydia Deng//=============================================================#include <Griewank.hh>#include <math.h>#define R2DG 180/PIstatic const char* myNameIs = "Griewank";Griewank::Griewank(int n): ObjectiveFunction(n){;}Griewank::~Griewank(){;}double Griewank::realPerformance(const Model<double>& model){ double t=1, d=1, tt; for (int i=0; i < nparam; i++) { tt = model[i]; t += tt*tt*0.00025; d *= cos(tt/sqrt(i+1)); } return t-d;}double Griewank::realPerformance(const Model<float>& model){ Model<double> dm(model.modSize()); dm = model; return realPerformance(dm);}double Griewank::realPerformance(const Model<long>& model){ Model<double> dm(model.modSize()); dm = model; return realPerformance(dm);}Vector<double>* Griewank::getGradient(const Model<double>& model){ Vector<double> u(model.modParam()); double p=cos(u[0]); int i; for (i=1; i<nparam; i++) { u[i] /= sqrt(i+1); p *= cos(u[i]); } for (i=0; i<nparam; i++) { (*gradient)[i] = 0.0005*model[i]; (*gradient)[i] += p*tan(u[i])/sqrt(i+1); } return gradient;}Vector<double>* Griewank::getGradient(const Model<float>& model){ Model<double> dm(model.modSize()); dm = model; return getGradient(dm);}Vector<double>* Griewank::getGradient(const Model<long>& model){ Model<double> dm(model.modSize()); dm = model; return getGradient(dm);}const char* Griewank::className() const{ return(myNameIs);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -