39 lines
811 B
C
39 lines
811 B
C
![]() |
#ifndef LOWESS_SMOOTHER_H
|
||
|
#define LOWESS_SMOOTHER_H
|
||
|
|
||
|
#include <vector>
|
||
|
#include <algorithm>
|
||
|
#include <cmath>
|
||
|
#include <stdexcept>
|
||
|
|
||
|
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
|