2025-06-04 09:29:37 +00:00
|
|
|
#ifndef LOWESS_SMOOTHER_H
|
|
|
|
#define LOWESS_SMOOTHER_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cmath>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2025-06-27 09:22:07 +00:00
|
|
|
// lowess
|
2025-06-04 09:29:37 +00:00
|
|
|
namespace Lowess {
|
|
|
|
|
|
|
|
// 配置参数结构体
|
|
|
|
struct Config {
|
|
|
|
double smoothingFactor = 0.25;
|
|
|
|
int robustnessIterations = 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
// 验证参数有效性
|
|
|
|
void validateConfig(const Config& config);
|
|
|
|
|
|
|
|
// 三次权重函数
|
|
|
|
double weightFunction(double x);
|
|
|
|
|
|
|
|
// 计算中位数绝对偏差
|
|
|
|
double medianAbsoluteDeviation(const std::vector<double>& residuals);
|
|
|
|
|
|
|
|
// 计算带宽
|
|
|
|
std::vector<double> computeBandwidths(const std::vector<double>& x, double smoothingFactor);
|
|
|
|
|
|
|
|
// 核心平滑函数
|
|
|
|
std::vector<double> smooth(
|
|
|
|
const std::vector<double>& x,
|
|
|
|
const std::vector<double>& y,
|
|
|
|
const Config& config = Config()
|
|
|
|
);
|
|
|
|
|
|
|
|
} // namespace Lowess
|
|
|
|
|
|
|
|
#endif // LOWESS_SMOOTHER_H
|