用法:
class cusignal.estimation.filters.KalmanFilter(dim_x, dim_z, dim_u=0, points=1, dtype=<class 'numpy.float32'>)
這是一個multi-point卡爾曼濾波器實現https://github.com/rlabbe/filterpy/blob/master/filterpy/kalman/kalman_filter.py,具有函數的子集。
所有卡爾曼濾波器矩陣都堆疊在 X 軸上。這是為了在 GPU 上實現最佳的全局訪問。
- dim_x:int
卡爾曼濾波器的狀態變量數。例如,如果您在二維中跟蹤對象的位置和速度,dim_x 將為 4。這用於設置 P、Q 和 u 的默認大小
- dim_z:int
測量輸入的數量。例如,如果傳感器為您提供 (x,y) 中的位置,則 dim_z 將為 2。
- dim_u:int(可選)
控製輸入的大小(如果正在使用)。默認值 0 表示不使用。
- points:int(可選)
要跟蹤的卡爾曼濾波器點數。
- dtype:dtype(可選)
計算的數據類型。
參數:
參考:
- 1
Dan Simon. “Optimal State Estimation.” John Wiley & Sons. p. 208-212. (2006)
- 2
Roger Labbe. “Kalman and Bayesian Filters in Python” https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python
例子:
這是一個使用僅讀取位置的傳感器跟蹤位置和速度的過濾器。
首先構造具有所需維度、點數和數據類型的對象。
import cupy as cp import numpy as np from cusignal import KalmanFilter points = 1024 kf = KalmanFilter(dim_x=4, dim_z=2, points=points, dtype=cp.float64)
為所有卡爾曼濾波器點分配狀態(位置和速度)的初始值。
initial_location = np.array( [[10.0, 10.0, 0.0, 0.0]], dtype=dt ).T # x, y, v_x, v_y kf.x = cp.repeat( cp.asarray(initial_location[cp.newaxis, :, :]), points, axis=0 )
定義所有卡爾曼濾波器點的狀態轉移矩陣:
F = np.array( [ [1.0, 0.0, 1.0, 0.0], # x = x0 + v_x*dt [0.0, 1.0, 0.0, 1.0], # y = y0 + v_y*dt [0.0, 0.0, 1.0, 0.0], # dx = v_x [1.0, 0.0, 0.0, 1.0], ], # dy = v_y dtype=dt, ) kf.F = cp.repeat(cp.asarray(F[cp.newaxis, :, :]), points, axis=0)
定義所有卡爾曼濾波器點的測量函數:
H = np.array( [[1.0, 0.0, 1.0, 0.0], [0.0, 1.0, 0.0, 1.0]], dtype=dt, # x_0 # y_0 ) kf.H = cp.repeat(cp.asarray(H[cp.newaxis, :, :]), points, axis=0)
定義所有卡爾曼濾波器點的協方差矩陣:
initial_estimate_error = np.eye(dim_x, dtype=dt) * np.array( [1.0, 1.0, 2.0, 2.0], dtype=dt ) kf.P = cp.repeat( cp.asarray(initial_estimate_error[cp.newaxis, :, :]), points, axis=0, )
定義所有卡爾曼濾波器點的測量噪聲:
measurement_noise = np.eye(dim_z, dtype=dt) * 0.01 kf.R = cp.repeat( cp.asarray(measurement_noise[cp.newaxis, :, :]), points, axis=0 )
定義所有卡爾曼濾波器點的過程噪聲:
現在隻需執行標準的預測/更新循環: 注意:此示例僅對所有點使用相同的傳感器讀數
kf.predict() z = get_sensor_reading() (dim_z, 1) kf.z = cp.repeat(z[cp.newaxis, :, :], points, axis=0) kf.update()
結果在:
相關用法
- Python cusignal.windows.windows.hann用法及代碼示例
- Python cusignal.windows.windows.general_gaussian用法及代碼示例
- Python cusignal.waveforms.waveforms.chirp用法及代碼示例
- Python cusignal.windows.windows.gaussian用法及代碼示例
- Python cusignal.windows.windows.hamming用法及代碼示例
- Python cusignal.windows.windows.get_window用法及代碼示例
- Python cusignal.waveforms.waveforms.gausspulse用法及代碼示例
- Python cusignal.peak_finding.peak_finding.argrelmin用法及代碼示例
- Python cusignal.windows.windows.bartlett用法及代碼示例
- Python cusignal.spectral_analysis.spectral.welch用法及代碼示例
- Python cusignal.windows.windows.chebwin用法及代碼示例
- Python cusignal.windows.windows.general_cosine用法及代碼示例
- Python cusignal.peak_finding.peak_finding.argrelextrema用法及代碼示例
- Python cusignal.convolution.convolve.convolve2d用法及代碼示例
- Python cusignal.filtering.resample.resample_poly用法及代碼示例
- Python cusignal.convolution.correlate.correlate用法及代碼示例
- Python cusignal.convolution.convolve.fftconvolve用法及代碼示例
- Python cusignal.waveforms.waveforms.unit_impulse用法及代碼示例
- Python cusignal.convolution.convolve.convolve1d3o用法及代碼示例
- Python cusignal.spectral_analysis.spectral.spectrogram用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cusignal.estimation.filters.KalmanFilter。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。