📄 optimizermethod.cpp
字号:
//#include "StdAfx.h"
#include "OptimizerMethod.h"
using namespace std;
COptimizerMethod::COptimizerMethod(void)
{
m_fAmplitudeGain=1.2;
m_fDecreaseGain=0.5;
m_fStepAmplitudeMax=0.9;
m_fStepAmplitudeMin=1e-6;
}
COptimizerMethod::COptimizerMethod(float AmplitudeGain,float DecreaseGain,float StepAmplitudeMax)
{
m_fAmplitudeGain=AmplitudeGain;
m_fDecreaseGain=DecreaseGain;
m_fStepAmplitudeMax=StepAmplitudeMax;
m_fStepAmplitudeMin=1e-6;
}
COptimizerMethod::~COptimizerMethod(void)
{
}
float COptimizerMethod::RPPOP_DeltaStepSeek(double& CurrentErrorDif,double& PreErrorDif,double& PreDeltaStep)
{
float AdjustStep;//最后结果,即本此调整步长
float DeltaStep;//步长调整值的变化量
if (CurrentErrorDif*PreErrorDif>0)//%误差单调(上升或下降)
{
DeltaStep=min(float(m_fAmplitudeGain*PreDeltaStep),m_fStepAmplitudeMax);
PreDeltaStep=DeltaStep;//;%步长调整的幅值,当前计算的结果传出去下次用
AdjustStep=-DeltaStep*sign(CurrentErrorDif);
PreErrorDif=CurrentErrorDif;//%为下一次准备
}
else if (CurrentErrorDif*PreErrorDif<0)//%误差经过极值
{
AdjustStep=-PreDeltaStep;
PreDeltaStep=max(float(m_fDecreaseGain*PreDeltaStep),m_fStepAmplitudeMin);//%当前计算的结果传出去下次用
PreErrorDif=0;//关键在此处,必须把0传出去
}
else if (CurrentErrorDif*PreErrorDif==0)//%误差曾经过极值
{
AdjustStep=-sign(CurrentErrorDif)*PreDeltaStep;
PreErrorDif=CurrentErrorDif;//%为下一次准备
}
return AdjustStep;
}
inline float COptimizerMethod::sign(double &number)
{
float Sign=number>=0?1.0:-1.0;
return Sign;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -