1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

デノイジングには過去方向のデータ

Last updated at Posted at 2024-05-20

ウェーブレット変換で高周波成分を除去して特徴量を作るって論文があったけど、リアルタイムやスライディングウィンドウでは全く機能しなくて、要はリークじゃないかと。

ホルトウィンタース法やカルマンフィルタだと、確かに後方(過去方向)のデータにしか依存しないみたいだ。
新しいデータが追加されても、過去の解釈が変わらない様子をプロットしてみた。
良く分からんけど。

fig.png

import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.holtwinters import ExponentialSmoothing
from pykalman import KalmanFilter

np.random.seed(42)
steps = 84
time = np.linspace(0, 7, steps)
noise = np.random.randn(steps)
values = np.cumsum(noise)  

# データを正の範囲にシフト
values += abs(values.min()) + 1

# デノイジングを行う範囲
ranges = [
    (0, steps - 24),
    (12, steps - 12),
    (24, steps - 0),
]

plt.figure(figsize=(12, 10))

# ホルトウィンタース法
plt.subplot(2, 1, 1)
plt.plot(time, values, 'o-', label='Original Data', alpha=0.5)

for start, end in ranges:
    sliced_values = values[start:end]
    sliced_time = time[start:end]
    
    model = ExponentialSmoothing(sliced_values, trend='mul', seasonal=None)
    fit = model.fit(smoothing_level=0.2, smoothing_trend=0.2)
    
    trend = fit.level * fit.trend
    
    plt.plot(sliced_time, trend, linestyle='--', label=f'Trend ({start} to {end})')

plt.legend()
plt.title('Denoising using Holt-Winters Method (Multiplicative)')
plt.xlabel('Time')
plt.ylabel('Signal')

# カルマンフィルタの設定
kf = KalmanFilter(
    transition_matrices=[1],
    observation_matrices=[1],
    initial_state_mean=values[0],
    initial_state_covariance=1,
    observation_covariance= 1,
    transition_covariance=0.1
)

plt.subplot(2, 1, 2)
plt.plot(time, values, 'o-', label='Original Data', alpha=0.5)

for start, end in ranges:
    sliced_values = values[start:end]
    sliced_time = time[start:end]
    
    trend, _ = kf.filter(sliced_values)
    
    plt.plot(sliced_time, trend, linestyle='--', label=f'Trend ({start} to {end})')

plt.legend()
plt.title('Denoising using Kalman Filter')
plt.xlabel('Time')
plt.ylabel('Signal')

plt.tight_layout()
plt.show()
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?