MATLAB实现卡尔曼滤波理论与实践第三版详解

需积分: 5 1 下载量 66 浏览量 更新于2024-06-29 收藏 5.11MB PDF 举报
《卡尔曼滤波理论与实践:MATLAB应用教程(第三版)》是一本由Mohinder Grewal教授和Angus Andrews共同编写的著作,出版于2008年,由John Wiley & Sons, Inc. 出版。本书主要聚焦于卡尔曼滤波这一关键的信号处理技术,该技术在许多领域,如导航、控制系统、信号估计和预测等方面发挥着重要作用。卡尔曼滤波是一种递归最小二乘方法,用于估计动态系统的状态,并考虑到观测数据中的噪声不确定性。 本书的核心内容包括以下几个方面: 1. **理论基础**:深入讲解卡尔曼滤波的原理,包括随机过程、线性系统理论、状态空间模型、预测与更新步骤、协方差矩阵和信息增益等概念。读者将理解滤波器如何通过结合系统的动态模型和观测数据来实时估计状态并减小误差。 2. **MATLAB实现**:作者以MATLAB为例,详细介绍了如何在实际项目中使用这个强大的工具进行滤波器设计和仿真。书中提供了大量的代码示例,帮助读者掌握如何编写和调试卡尔曼滤波算法。 3. **应用实例**:书中包含多个实例,涵盖航空导航、自动驾驶、遥感、通信系统等领域,展示了卡尔曼滤波在实际问题中的应用效果和优化策略。 4. **扩展话题**:除了基本的无迹卡尔曼滤波(UKF)和粒子滤波(PF),本书还可能探讨了自适应滤波、非线性滤波和其他高级主题,以满足不同读者的专业需求。 版权信息表明,任何未经许可的复制、存储、传输行为均需获得John Wiley & Sons, Inc. 的明确授权。如果你对本书的内容感兴趣,可通过指定的联系方式申请许可。 《卡尔曼滤波理论与实践:MATLAB应用教程(第三版)》是一本实用的教材,不仅适合工程学生和研究人员学习卡尔曼滤波理论,也适用于需要在实际项目中应用该技术的专业人士。通过本书,读者将获得深入理解卡尔曼滤波的精髓以及如何利用MATLAB进行高效实现和优化。

帮我给每一行代码添加注释 class DeepKalmanFilter(nn.Module): def __init__(self, config): super(DeepKalmanFilter, self).__init__() self.emitter = Emitter(config.z_dim, config.emit_hidden_dim, config.obs_dim) self.transition = Transition(config.z_dim, config.trans_hidden_dim) self.posterior = Posterior( config.z_dim, config.post_hidden_dim, config.obs_dim ) self.z_q_0 = nn.Parameter(torch.zeros(config.z_dim)) self.emit_log_sigma = nn.Parameter(config.emit_log_sigma * torch.ones(config.obs_dim)) self.config = config @staticmethod def reparametrization(mu, sig): return mu + torch.randn_like(sig) * sig @staticmethod def kl_div(mu0, sig0, mu1, sig1): return -0.5 * torch.sum(1 - 2 * sig1.log() + 2 * sig0.log() - (mu1 - mu0).pow(2) / sig1.pow(2) - (sig0 / sig1).pow(2)) def loss(self, obs): time_step = obs.size(1) batch_size = obs.size(0) overshoot_len = self.config.overshooting kl = torch.Tensor([0]).to(self.config.device) reconstruction = torch.Tensor([0]).to(self.config.device) emit_sig = self.emit_log_sigma.exp() for s in range(self.config.sampling_num): z_q_t = self.z_q_0.expand((batch_size, self.config.z_dim)) for t in range(time_step): trans_loc, trans_sig = self.transition(z_q_t) post_loc, post_sig = self.posterior(trans_loc, trans_sig, obs[:, t]) z_q_t = self.reparametrization(post_loc, post_sig) emit_loc = self.emitter(z_q_t) reconstruction += ((emit_loc - obs[:, t]).pow(2).sum(dim=0) / 2 / emit_sig + self.emit_log_sigma * batch_size / 2).sum() if t > 0: over_loc, over_sig = self.transition(overshooting[:overshoot_len - 1]) over_loc = torch.cat([trans_loc.unsqueeze(0), over_loc], dim=0) over_sig = torch.cat([trans_sig.unsqueeze(0), over_sig], dim=0) else: over_loc = trans_loc.unsqueeze(0) over_sig = trans_sig.unsqueeze(0) overshooting = self.reparametrization(over_loc, over_sig) kl = kl + self.kl_div(post_loc.expand_as(over_loc), post_sig.expand_as(over_sig), over_loc, over_sig) / min(t + 1, self.config.overshooting) reconstruction = reconstruction / self.config.sampling_num kl = kl / self.config.sampling_num return reconstruction, kl

2023-02-22 上传

C:\Users\adminstor\anaconda3\envs\python39\python.exe D:\daima\KalmanNet_TSP-main\main_lor_DT_NLobs.py Pipeline Start Current Time = 07.24.23_12:19:44 Using GPU 1/r2 [dB]: tensor(30.) 1/q2 [dB]: tensor(30.) Start Data Gen Data Load data_lor_v0_rq3030_T20.pt no chopping trainset size: torch.Size([1000, 3, 20]) cvset size: torch.Size([100, 3, 20]) testset size: torch.Size([200, 3, 20]) Evaluate EKF full Extended Kalman Filter - MSE LOSS: tensor(-26.4659) [dB] Extended Kalman Filter - STD: tensor(1.6740) [dB] Inference Time: 37.115127086639404 KalmanNet start Number of trainable parameters for KNet: 19938 Composition Loss: True Traceback (most recent call last): File "D:\daima\KalmanNet_TSP-main\main_lor_DT_NLobs.py", line 146, in <module> [MSE_cv_linear_epoch, MSE_cv_dB_epoch, MSE_train_linear_epoch, MSE_train_dB_epoch] = KalmanNet_Pipeline.NNTrain(sys_model, cv_input, cv_target, train_input, train_target, path_results) File "D:\daima\KalmanNet_TSP-main\Pipelines\Pipeline_EKF.py", line 150, in NNTrain MSE_trainbatch_linear_LOSS = self.alpha * self.loss_fn(x_out_training_batch, train_target_batch)+(1-self.alpha)*self.loss_fn(y_hat, y_training_batch) File "C:\Users\adminstor\anaconda3\envs\python39\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "C:\Users\adminstor\anaconda3\envs\python39\lib\site-packages\torch\nn\modules\loss.py", line 520, in forward return F.mse_loss(input, target, reduction=self.reduction) File "C:\Users\adminstor\anaconda3\envs\python39\lib\site-packages\torch\nn\functional.py", line 3112, in mse_loss return torch._C._nn.mse_loss(expanded_input, expanded_target, _Reduction.get_enum(reduction)) RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

2023-07-25 上传