PyBayes的安装和使用
PyBayes 主页 文档
PyBayes is an object-oriented Python library for recursive Bayesian estimation (Bayesian filtering) that is convenient to use. Already implemented are Kalman filter, particle filter and marginalized particle filter, all built atop of a light framework of probability density functions. PyBayes can optionally use Cython for large speed gains (Cython build can be several times faster in some situations).
- 安装
可以通过pip install -U PyBayes安装。
如果失败可以考虑手动下载源码,自己安装。
安装过程中,Cython编译可能失败。使用下面的命令安装,可以避免Cython编译加速:
python ./setup.py --use-cython=no install
- 主要功能
Kalman filter, particle filter and marginalized particle filter
- 遇到的问题
在执行python pybayes.GaussPdf(np.array([0.0, 0.0]), np.array([[200.0, 0.0],[0.0, 200.0]]))时报错:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Anaconda\lib\site-packages\pybayes\pdfs.py", line 548, in __init__
self._set_rv(mean.shape[0], rv)
File "D:\Anaconda\lib\site-packages\pybayes\pdfs.py", line 418, in _set_rv
return self._set_rvs(exp_shape, rv, 0, None)
File "D:\Anaconda\lib\site-packages\pybayes\pdfs.py", line 379, in _set_rvs
self.rv = RV(RVComp(exp_shape)) # create RV with one anonymous component
File "D:\Anaconda\lib\site-packages\pybayes\pdfs.py", line 46, in __init__
raise TypeError("dimension must be integer (int)")
TypeError: dimension must be integer (int)
应该是跟1.9版本的NumPy不太兼容,NumPy的shape([1,2,3])返回的是(3L,),是长整型,所以修改pybayes的...\lib\site-packages\pybayes\pdfs.py文件的45行:
#if not isinstance(dimension, int):
if not isinstance(dimension, long):
- 简单实例
一维卡尔曼和简单界面
#coding=utf8
import sys
from PySide.QtCore import *
from PySide.QtGui import *
import pybayes as pb
import numpy as np
_A=np.array([[1.]])
_C=np.array([[1.]])
_Q=np.array([[1.]])
_R=np.array([[1.]])
s_pdf=pb.GaussPdf(np.array([1.]), np.array([[1.]]))
kf=pb.KalmanFilter(A=_A,C=_C,Q=_Q,R=_R,state_pdf=s_pdf)
p=kf.posterior()
def update(x):
kf.bayes(np.array([x]))
return p.mean()[0],p.variance()[0]
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(320, 205)
self.pushButton = QPushButton(Dialog)
self.pushButton.setGeometry(QRect(210, 160, 75, 25))
self.pushButton.setObjectName("pushButton")
self.textBrowser = QTextBrowser(Dialog)
self.textBrowser.setGeometry(QRect(10, 10, 300, 131))
self.textBrowser.setObjectName("textBrowser")
self.textEdit = QTextEdit(Dialog)
self.textEdit.setGeometry(QRect(35, 160, 100, 25))
self.textEdit.setObjectName("textEdit")
self.retranslateUi(Dialog)
QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QApplication.translate("Dialog", "卡尔曼滤波器", None, QApplication.UnicodeUTF8))
self.pushButton.setText(QApplication.translate("Dialog", "更新", None, QApplication.UnicodeUTF8))
class MainUi(QDialog,Ui_Dialog):
def __init__(self,parent = None):#parent默认为0
super(MainUi,self).__init__(parent)#固定形式
self.setupUi(self)
self.connectSlot()
def connectSlot(self):#连接逻辑和界面
#self.textEdit.textChanged.connect(self.changeWord)#同步textEdit和textBrowser的内容
self.pushButton.clicked.connect(self.changeWord)
def clearText(self):
self.textEdit.setText("")
def changeWord(self):#更改textBrowse显示内容
mean,var=update(float(self.textEdit.toPlainText()))
_text = u"<font color = blue>滤波值:%f<br />方差:%f</font>"%(mean,var)
self.textBrowser.setText(_text)
def main():
app = QApplication(sys.argv)
ui = MainUi()#没有给parent赋值
ui.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
PyBayes的安装和使用的更多相关文章
- docker——容器安装tomcat
写在前面: 继续docker的学习,学习了docker的基本常用命令之后,我在docker上安装jdk,tomcat两个基本的java web工具,这里对操作流程记录一下. 软件准备: 1.jdk-7 ...
- 网络原因导致 npm 软件包 node-sass / gulp-sass 安装失败的处理办法
如果你正在构建一个基于 gulp 的前端自动化开发环境,那么极有可能会用到 gulp-sass ,由于网络原因你可能会安装失败,因为安装过程中部分细节会到亚马逊云服务器上获取文件.本文主要讨论在不变更 ...
- Sublime Text3安装JsHint
介绍 Sublime Text3使用jshint依赖Nodejs,SublimeLinter和Sublimelinter-jshint. NodeJs的安装省略. 安装SublimeLinter Su ...
- Fabio 安装和简单使用
Fabio(Go 语言):https://github.com/eBay/fabio Fabio 是一个快速.现代.zero-conf 负载均衡 HTTP(S) 路由器,用于部署 Consul 管理的 ...
- gentoo 安装
加载完光驱后 1进行ping命令查看网络是否通畅 2设置硬盘的标识为GPT(主要用于64位且启动模式为UEFI,还有一个是MBR,主要用于32位且启动模式为bois) parted -a optima ...
- Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级
Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 5.安装Database软件 5. ...
- Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part1:准备工作
Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part1:准备工作 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 1.实施前准备工作 1.1 服务器安装操 ...
- 【原】nodejs全局安装和本地安装的区别
来微信支付有2年多了,从2年前的互联网模式转变为O2O模式,主要的场景是跟线下的商户去打交道,不像以往的互联网模式,有产品经理提需求,我们帮忙去解决问题. 转型后是这样的,团队成员更多需要去寻找业务的 ...
- tLinux 2.2下安装Mono 4.8
Tlinux2.2发行版基于CentOS 7.2.1511研发而成,内核版本与Tlinux2.0发行版保持完全一致,更加稳定,并保持对Tlinux2.0的完全兼容.Mono 4版本要求CentOS 7 ...
随机推荐
- zenmap 的扫描方式
第一种:Intense scan (nmap -T4 -A -v) 一般来说,Intense scan可以满足一般扫描 -T4 加快执行速度 -A 操作系统及版本探测 -v 显示详细的输出 第二种:I ...
- 代码自动生成工具_java版
项目结构: 这里要实现的功能是,当我们给出了bean,如:Admin,User,People等实体类后, 我想用代码自动生成我想要的代码,最后生成的效果: 也就是说为每一个bean都生成相应的Dao, ...
- [前端]利用a标签获取url里所需的内容
function parseURL(url) { var a = document.createElement('a'); a.href = url; return { source: url, pr ...
- Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If the server requires more time, try increasing the timeout in the server editor.
在部署的时候出现Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If the server ...
- MySQL5.7表空间加密
MySQL5.7开始支持表空间加密了,增强了MySQL的数据文件的安全性,这是一个很不错的一个功能,这个特性默认是没有启用的,要使用这个功能要安装插件keyring_file. 下面就来看看怎么安装, ...
- 【C#设计模式——创建型模式】工场方法模式
工场方法模式对简单工场模式进行了乔庙的扩展,不是用一个专门的类来决定实例化哪一个子类.相反,超类把这种决定延迟到每个子类.这种模式实际上没有决策点,就是没有直接选择一个子类实例化的决策. 看书上的例子 ...
- 用paint 计算字符串的像素宽度
方法1: //直接返回参数字符串所占用的像素宽度 Paint paint = new Paint(); width = paint.measureText(str); 有一些view可以直接得到pai ...
- C#获取一个文件的扩展名
C#获取一个文件的扩展名System.IO.Path.GetExtension( "文件名 ");ChangeExtension 更改路径字符串的扩展名. Combine ...
- [HDOJ2874]Connections between cities(LCA, 离线tarjan)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2874 这题有不连通的情况,特别注意. 觉得是存query的姿势不对,用前向星存了一遍,还是T…… /* ...
- 深入学习android之AlarmManager
对应AlarmManage有一个AlarmManagerServie服务程 序,该服务程序才是正真提供闹铃服务的,它主要维护应用程序注册下来的各类闹铃并适时的设置即将触发的闹铃给闹铃设备(在系统中,l ...