Python 中均值和协方差的快速增量更新 [英] Fast incremental update of the mean and covariance in Python

查看:93
本文介绍了Python 中均值和协方差的快速增量更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Python 脚本,需要经常更新均值和协方差矩阵.我目前正在做的是,每次我得到一个新的数据点 $x$(一个向量),我重新计算均值和协方差如下:

I have a Python script where I need to frequently update the mean and co-variance matrix. What I am currently doing is that each time I get a new data point $x$ (a vector), I recompute the mean and covariance as follows:

data.append(x) # My `data` is just a list of lists of floats (i.e., x is a list of floats)
self.mean = np.mean( data, axis=0) # self.mean is a list representing the center of data
self.cov = np.cov( data, rowvar=0)

问题是这对我来说还不够快.无论如何,通过增量更新 meancov 而不根据所有 data 重新计算它们是否会更有效?

The problem is that is not fast enough for me. Is there anyway to be more efficient by incrementally updating mean and cov without re-computing them based on all the data ?

计算均值应该很容易,我可以弄清楚.我的主要问题是如何更新协方差矩阵 self.cov.

Computing mean incrementally should be easy and I can figure it out. My main problem is how to update the covariance matrix self.cov.

推荐答案

我刚刚发现我们可以使用 mdp 库轻松做到这一点http://mdp-toolkit.sourceforge.net/api/mdp.utils.CovarianceMatrix-class.html

I just figured out that we can easily do that using the mdp library http://mdp-toolkit.sourceforge.net/api/mdp.utils.CovarianceMatrix-class.html

这篇关于Python 中均值和协方差的快速增量更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆