You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Include/nmNum/nmCalculation/nmPsoAcceleration.h

57 lines
2.8 KiB
C

#ifndef NMPSOACCELERATION_H
#define NMPSOACCELERATION_H
#include "nmFitTypes.h"
// PSO粒子结构
// 这里的 position / velocity / bestPosition 只保存“用户勾选参与拟合的参数”,
// 拟合参数为 k/skin/wellboreC/phi/Dfc/裂缝半长。包含固定储层输入的物理参数向量在写 trace 或调用代理模型时
// 通过 buildTraceParameterVector() 重新组装。
//
// surrogate* 和 screeningDecision 是 PSO 加速筛选的辅助字段。真实 pbest / gbest
// 始终只由求解器更新;T1-T5 可另外维护不参与最终结果的 guideBestPosition 来修正速度方向。
struct AutoFitParticle
{
QVector<QVector<double>> currentLogLogData;
QVector<QVector<double>> bestLogLogData;
QVector<double> position; ///< 当前位置(参数值)
QVector<double> velocity; ///< 速度
QVector<double> bestPosition; ///< 真实求解器确认的个体最优位置
QVector<double> guideBestPosition; ///< 仅用于速度更新的引导位置;不会参与真实 gbest/最终结果
double fitness; ///< 当前适应度
double bestFitness; ///< 真实求解器确认的个体最优适应度
double guideBestObjective; ///< guideBestPosition 对应的真实或代理目标值
bool guideBestFromSurrogate; ///< true 表示当前引导位置尚未经过真实求解器验证
double pbestRelativeImprovementThisIteration; ///< 本代真实评价相对旧 pbest 的改善幅度
bool evaluatedThisIteration;
bool lastEvaluationSuccess;
int lastEvaluationElapsedMs;
double surrogateObjective;
bool selectedForSolver;
bool selectedByAudit;
QString screeningDecision;
AutoFitParticle()
: fitness(1e10), bestFitness(1e10), guideBestObjective(1e10), guideBestFromSurrogate(false),
pbestRelativeImprovementThisIteration(0.0), evaluatedThisIteration(false), lastEvaluationSuccess(false),
lastEvaluationElapsedMs(-1), surrogateObjective(1e10), selectedForSolver(true), selectedByAudit(false),
screeningDecision("full_solver")
{
}
};
/** @brief 可选 PSO 加速策略;通过值快照返回筛选和引导建议,不持有算法对象。 */
class nmPsoAcceleration
{
public:
virtual ~nmPsoAcceleration() {}
/** @brief 在首次真实评价前准备可选加速资源。 */
virtual void begin() {}
virtual QVector<AutoFitParticle> select(const QVector<AutoFitParticle>& particles, int iteration,
unsigned int seed) = 0;
virtual bool preserveGuide(const AutoFitParticle& particle, bool beatsGlobalBest) const = 0;
};
#endif // NMPSOACCELERATION_H