📄 misfit.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//=============================================================#include <MisFit.hh>static const char* myNameIs = "MisFit function";const char* MisFitFcn::className() const { return (myNameIs);}const char* MisFitFcn::forwardName() const { return forOp->className();}MisFitFcn::MisFitFcn(int n, Forward* forwardOp, Vector<double>* input, int lpnorm): ObjectiveFunction(n){ isUpdated = 0; lp = lpnorm; forOp = forwardOp; ndata = input->size(); errData = new Vector<double>(ndata); refData = new Vector<double>(ndata); *refData = *input;}MisFitFcn::~MisFitFcn(){ delete errData; delete refData; forOp = NULL;}Vector<double> MisFitFcn::modeling(const Model<double>& p){ List<double> ldat = forOp->dataList(p); Vector<double> calData(ndata); calData = ldat.ToVect(ndata); return calData;}Vector<double> MisFitFcn::modeling(const Model<long>& p){ List<double> ldat = forOp->dataList(p); Vector<double> calData(ndata); calData = ldat.ToVect(ndata); return calData;}Vector<double>* MisFitFcn::getGradient(const Model<double>&){ cerr << "Numerical derivatives are used!" << endl; delete gradient; gradient = NULL; return gradient;}Vector<double>* MisFitFcn::getGradient(const Model<long>&){ cerr << "Numerical derivatives are used!" << endl; delete gradient; gradient = NULL; return gradient;}Vector<double> MisFitFcn::updateError(const Model<double>& p){ Vector<double> calData(ndata); calData = modeling(p); *errData = *refData - calData; isUpdated = 1; return *errData;}Vector<double> MisFitFcn::updateError(const Model<long>& p){ Vector<double> calData(ndata); calData = modeling(p); *errData = *refData - calData; isUpdated = 1; return *errData;}double MisFitFcn::realPerformance(const Model<double>& p){ if (!isUpdated) updateError(p); isUpdated = 0; return errData->norm(lp);}double MisFitFcn::realPerformance(const Model<long>& p){ if (!isUpdated) updateError(p); isUpdated = 0; return errData->norm(lp);}Vector<double> MisFitFcn::adjointOperation(const Vector<double>& v){ return forOp->adjointOp(v);}Vector<double> MisFitFcn::operateOn(const Vector<double>& v){ return forOp->forwardOp(v);}Vector<double> MisFitFcn::operateOn(const Vector<long>& v){ return forOp->forwardOp(v);}double MisFitFcn::operateOn(int k, const Vector<double>& v){ return forOp->forwardOp(k, v);}double MisFitFcn::operateOn(int k, const Vector<long>& v){ return forOp->forwardOp(k, v);}Vector<double> MisFitFcn::getOneOperator(int i){ return forOp->oneOperator(i);}Vector<double> MisFitFcn::getRefData(){ return refData[0];}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -