⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multitest.cc

📁 COOOL:CWP面向对象最优化库(CWP Object Oriented Optimization Library) COOOL是C++类的一个集合
💻 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.////=============================================================// Author: H. Lydia Deng// Definition of a objective function class// Definition of the analytic objective function differentiation class// a simple 2-D multimodal function//=============================================================#include <MultiTest.hh>#include <math.h>MultiTest::MultiTest(int n):ObjectiveFunction(n){   acoeff = new Vector<double>(n);   bcoeff = new Vector<double>(n);   freq = new Vector<double>(n);   acoeff[0] = 1.;   bcoeff[0] = 1.;   freq[0] = 0.;   offset = 0.;}MultiTest::MultiTest(int n, Vector<double>& a, Vector<double>& b , Vector<double>& f, double c):ObjectiveFunction(n){   acoeff = new Vector<double>(n);   bcoeff = new Vector<double>(n);   freq = new Vector<double>(n);   acoeff[0] = a;   bcoeff[0] = b;   freq[0] = f;   offset = c;}MultiTest::~MultiTest(){      if (acoeff != NULL) acoeff = NULL;      if (bcoeff != NULL) acoeff = NULL;      if (freq != NULL) freq = NULL;}const char* MultiTest::className() const{ return(myNameIs);}int MultiTest::mySize() const { return nparam;}Vector<double> MultiTest::wigle(const Vector<double>& f, const Model<double>& m){   Vector<double> v(m.modParam()), u(nparam);   for (int i=0; i<nparam; i++)      u[i] = -cos(PI*f[i]*v[i]);      return u;}double MultiTest::realPerformance(const Model<double>& m){   DiagMatrix<double> a(acoeff[0]);   Vector<double> v(m.modParam());   double value = bcoeff[0] * wigle(freq[0],m);   value += v * (a * v);   value += offset;      return value;}double MultiTest::realPerformance(const Model<long>& m){;}Vector<double>* MultiTest::getGradient(const Model<double>& m){   Vector<double>* g = new Vector<double>(nparam);   double temp;      for (int i=0; i < nparam; i++)   {      temp = sin(freq[0][i] * m[i]);      g[0][i] = 2*acoeff[0][i]*m[i] + bcoeff[0][i]*freq[0][i]*temp;   }         return g;}Vector<double>* MultiTest::getGradient(const Model<long>& m){;}

⌨️ 快捷键说明

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