You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中分段回归载荷-位移曲线的尖角与跳变平滑处理

载荷-位移曲线分段回归后的平滑处理

问题说明

需要平滑分段回归载荷-位移曲线中的尖角与跳变(这类跳变无法被仿真软件认可)。现有位移、载荷、损伤随步长/时间变化的数据集,需针对指定断点位置附近的载荷与损伤曲线做平滑处理。

数据导入与绘图代码

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("ExampleforStack.txt") # 读取数据
x = df["Displacement"] # 获取位移数据
y = df["Load"] # 获取载荷数据
d = df["Damage"] # 获取损伤数据

# 绘图
plt.figure()
plt.subplot(3,1,1)
plt.plot(x)
plt.grid()
plt.ylabel("Displacement")
plt.subplot(3,1,2)
plt.plot(y)
plt.grid()
plt.ylabel("Load")
plt.subplot(3,1,3)
plt.plot(d)
plt.grid()
plt.ylabel("Damage")
plt.xlabel("Step")
plt.gcf().align_ylabels()
plt.tight_layout()

断点位置

将载荷、损伤与位移关联绘图时,曲线存在断点,对应位移区间为 [0.005806195310298627, 0.02801208361344569],需对该区间附近的载荷与损伤曲线进行平滑。

已尝试的平滑方法

  • statsmodels的lowess方法(效果不佳)
  • 高斯回归模型
  • 奇异谱分析
  • Savitzky-Golay滤波器
  • 三次样条

尚未尝试曲线拟合方法。

背景信息

  • 位移:DIC分析结果
  • 载荷:试验机实测数据
  • 损伤:由位移、载荷及弹性区材料刚度计算得出

期望效果

平滑后曲线需符合指定参考效果,且平滑后数据的导数必须无跳变、保持平滑。

后续尝试的有效方法

后续尝试了Martin Brown建议的BoxCar卷积平滑及高斯滤波方法,其中高斯滤波效果更优:

BoxCar卷积平滑函数

from scipy.signal import convolve
import numpy as np

def boxCar(data, winSize):
    kernel = np.ones(winSize) / winSize # 生成均匀卷积核
    dataSmoothed = convolve(data, kernel, mode='same') # 执行卷积平滑
    # 修正数组首尾的平滑偏差
    dataSmoothed[0:winSize] = data[0:winSize] # 保留前winSize个原始数据点
    dataSmoothed[-winSize:] = data[-winSize:] # 保留后winSize个原始数据点
    return dataSmoothed

高斯滤波函数

from scipy.ndimage import gaussian_filter1d
import numpy as np

def gaussian(data, sigma):
    dataSmoothed = gaussian_filter1d(data, sigma=sigma)
    dataSmoothed[0:50] = data[0:50] # 保留前50个原始数据点
    dataSmoothed[-50:] = data[-50:] # 保留后50个原始数据点
    return dataSmoothed

内容的提问来源于stack exchange,提问作者Tino D

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 16:47:43