EKF优化:协方差coff计算公式、意义、Code优化
复习!复习!
原文链接:http://blog.csdn.net/goodshot/article/details/8611178
1.代码:
Matlab相关系数的意义:
Eigen::MatrixXf correlation_matrix = corrcoef( LocM );
对行向量求相关系数 , 与列数无关,返回 cols()*cols() 矩阵...
翻译成Eigen:
还是自己写个函数吧
//1.求协方差
Eigen::MatrixXf CIcSearchM::cov(Eigen::MatrixXf &d1, Eigen::MatrixXf &d2)
{
Eigen::MatrixXf CovM(1,1);
assert(1 ==d1.cols() && 1 ==d2.cols() &&d1.cols()==d2.cols() ); //求协方差
float Ex =0;float Ey=0;
for (int i=0;i< d1.rows();++i){
Ex +=d1(i);
Ey +=d2(i);
}
Ex /=d1.rows();
Ey /=d2.rows(); for (int i=0;i< d1.rows();++i){
CovM(0) += (d1(i)-Ex)*(d2(i)-Ey);
}
CovM(0) /= d1.rows() -1;
return CovM;
}
//2.写入方差矩阵
//求矩阵的相关系数!
//返回矩阵A的列向量的相关系数矩阵//对行向量求相关系数 , 与行数无关,返回 cols()*cols() 矩阵...
Eigen::MatrixXf CIcSearchM::corrcoef(Eigen::MatrixXf &M)
{
// C(i,j)/SQRT(C(i,i)*C(j,j)).//C is the covariation Matrix
int Row= M.rows();
int Col= M.cols();
int Order= Col;//int Order= (std::max)(Row,Col); Eigen::MatrixXf Coef(Order,Order);
for (int i=0;i<Order;++i){
for (int j=0;j<Order;++j){
Coef(i,j)= cov((Eigen::MatrixXf)M.col(i),(Eigen::MatrixXf)M.col(j))(0);
}
}
return Coef;
}
2.优化的代码
使用Eigen计算1000维的方阵大概需要200ms的时间,相对于matlab默认开启GPU加速,时间上消耗的太多了。
参考:比较OpenBLAS、Matlab、MKL、Eigen的基础计算性能
优化的代码:
//求矩阵的相关系数!一个原始公式的简化算法/优化算法
//返回矩阵A的列向量的相关系数矩阵//对行向量求相关系数 , 与行数无关,返回 cols()*cols() 矩阵...
Eigen::MatrixXf CIcSearchM::CorrcoefOpm(Eigen::MatrixXf &MI)
{
Eigen::MatrixXf M =MI;
// C(i,j)/SQRT(C(i,i)*C(j,j)).//C is the covariation Matrix
//公式:
//temp = mysample - repmat(mean(mysample), 10, 1);
//result = temp' * temp ./ (size(mysample, 1) - 1)
int Row= M.rows();
int Col= M.cols();
int Order= Col;//int Order= (std::max)(Row,Col); SYSTEMTIME sysP;
GetLocalTime( &sysP );
int MileTsp = sysP.wSecond;
int MileTP = sysP.wMilliseconds; Eigen::MatrixXf CovM(Order,Order);//(1,Col);
Eigen::MatrixXf E_M(1,Col);
//减去每一个维度的均值;确定一列为一个维度。
//std::cout<< "Mat Src :"<<std::endl;m_Testor.print_EigenMat( M);
for (int i =0;i< Col;++i)
{
//求均值
E_M(i) =M.col(i).sum()/M.rows();
//std::cout<< "E_M(i)" << E_M(i)<< std::endl;
M.col(i) = M.col(i)- E_M(i);
//
} //SYSTEMTIME sysP2;
//GetLocalTime( &sysP );
//int MileTsp2 = sysP.wSecond;
//int MileTP2 = sysP.wMilliseconds;
//int DetaTp = MileTP2 - MileTP;
//int DetaTsp = MileTsp2 -MileTsp;
//std::cout<< "The Process time is :"<< DetaTsp<<"S"<< std::endl;
//std::cout<< "The Process time is :"<< DetaTp<<"mS"<< std::endl; //std::cout<< "Mat E_M :"<<std::endl;m_Testor.print_EigenMat( M);
CovM = M.transpose();
//GetLocalTime( &sysP );
//MileTsp2 = sysP.wSecond;
//MileTP2 = sysP.wMilliseconds;
//DetaTp = MileTP2 - MileTP;
//DetaTsp = MileTsp2 -MileTsp;
//std::cout<< "The Process time is :"<< DetaTsp<<"S"<< std::endl;
//std::cout<< "The Process time is :"<< DetaTp<<"mS"<< std::endl; //std::cout<< "Mat CovM :"<<std::endl;m_Testor.print_EigenMat( CovM);
CovM = CovM * M ;
//GetLocalTime( &sysP );
//MileTsp2 = sysP.wSecond;
//MileTP2 = sysP.wMilliseconds;
//DetaTp = MileTP2 - MileTP;
//DetaTsp = MileTsp2 -MileTsp;
//std::cout<< "The Process time is :"<< DetaTsp<<"S"<< std::endl;
//std::cout<< "The Process time is :"<< DetaTp<<"mS"<< std::endl; //实现 ./ 函数 数值计算没有区别
CovM = CovM /(Order-1)/(Order-1);
//GetLocalTime( &sysP );
//MileTsp2 = sysP.wSecond;
//MileTP2 = sysP.wMilliseconds;
//DetaTp = MileTP2 - MileTP;
//DetaTsp = MileTsp2 -MileTsp;
//std::cout<< "The Process time is :"<< DetaTsp<<"S"<< std::endl;
//std::cout<< "The Process time is :"<< DetaTp<<"mS"<< std::endl; //std::cout<< "Mat CovM :"<<std::endl;m_Testor.print_EigenMat( CovM);
//GetLocalTime( &sysP );
//MileTsp2 = sysP.wSecond;
//MileTP2 = sysP.wMilliseconds;
//DetaTp = MileTP2 - MileTP;
//DetaTsp = MileTsp2 -MileTsp;
//std::cout<< "The Process time is :"<< DetaTsp<<"S"<< std::endl;
//std::cout<< "The Process time is :"<< DetaTp<<"mS"<< std::endl; //遍历一次
for (int i=0;i< Order;++i){
for (int j=0;j<Order;++j){
CovM(i,j) = sqrt(CovM(i,i)*CovM(j,j) );
}
} //GetLocalTime( &sysP );
//MileTsp2 = sysP.wSecond;
//MileTP2 = sysP.wMilliseconds;
//DetaTp = MileTP2 - MileTP;
//DetaTsp = MileTsp2 -MileTsp;
//std::cout<< "The Process time is :"<< DetaTsp<<"S"<< std::endl;
//std::cout<< "The Process time is :"<< DetaTp<<"mS"<< std::endl; //std::cout<< "Mat CovM :"<<std::endl;m_Testor.print_EigenMat( CovM);
return CovM;
}
稀疏矩阵可以加速到3ms,我去!终于可以实用了.....
EKF优化:协方差coff计算公式、意义、Code优化的更多相关文章
- Linux启动时间优化-内核和用户空间启动优化实践
关键词:initcall.bootgraph.py.bootchartd.pybootchart等. 启动时间的优化,分为两大部分,分别是内核部分和用户空间两大部分. 从内核timestamp 0.0 ...
- 基于Oracle的SQL优化(社区万众期待 数据库优化扛鼎巨著)
基于Oracle的SQL优化(社区万众期待数据库优化扛鼎巨著) 崔华 编 ISBN 978-7-121-21758-6 2014年1月出版 定价:128.00元 856页 16开 编辑推荐 本土O ...
- mysql数据库优化课程---18、mysql服务器优化
mysql数据库优化课程---18.mysql服务器优化 一.总结 一句话总结: 1.四种字符集问题:字符集都设置为utf-82.slow log慢查询日志问题3.root密码丢失 1.mysql存在 ...
- ORACLE性能优化- Buffer cache 的调整与优化
Buffer Cache是SGA的重要组成部分,主要用于缓存数据块,其大小也直接影响系统的性能.当Buffer Cache过小的时候,将会造成更多的 free buffer waits事件. 下面将具 ...
- 转 cocos2d-x 优化(纹理渲染优化、资源缓存、内存优化)
概述 包括以下5种优化:引擎底层优化.纹理优化.渲染优化.资源缓存.内存优化 引擎优化 2.0版本比1.0版本在算法上有所优化,效率更高.2.0版本使用OpenGl ES 2.0图形库,1.0版本 ...
- Android开发优化之——对Bitmap的内存优化
http://blog.csdn.net/arui319/article/details/7953690 在Android应用里,最耗费内存的就是图片资源.而且在Android系统中,读取位图Bitm ...
- MySql数据库3【优化2】sql语句的优化
1.SELECT语句优化 1).利用LIMIT 1取得唯一行[控制结果集的行数] 有时,当你要查询一张表是,你知道自己只需要看一行.你可能会去的一条十分独特的记录,或者只是刚好检查了任何存在的记录数, ...
- Spring+SpringMVC+MyBatis+easyUI整合优化篇(十二)数据层优化-explain关键字及慢sql优化
本文提要 从编码角度来优化数据层的话,我首先会去查一下项目中运行的sql语句,定位到瓶颈是否出现在这里,首先去优化sql语句,而慢sql就是其中的主要优化对象,对于慢sql,顾名思义就是花费较多执行时 ...
- 数据库性能优化(database tuning)性能优化绝不仅仅只是索引
一毕业就接触优化方面的问题,专业做优化也有至少5年之多的时间了,可现在还是经常听到很多人认为优化很简单,就是建索引的问题,这确实不能怪大家,做这行20多年的时间里,在职业生涯的每个阶段,几乎都能听到这 ...
随机推荐
- 常用Git命令大全思维导图
开发中代码管理少不了使用Git,对于初学者来说Git命令的学习是一个难过的坎,为了帮助大家记忆并快速掌握Git的基本使用,我把常用的Git命令整理成思维导图,分享给大家. 高清大图在线预览 http: ...
- hibernate 中映射关系配置
多对多 : 外键维护权,一方放弃inverse="true",并且不放弃维护权的一方,加入 cascade="save-update":推荐方案 Student ...
- 12SSM整合
u 三大框架基本概念 spring.SpringMVC.Mybatis u 整合思路 u 环境准备 u 工程结构 u SPRING + SPING MVC + MYBATIS 三大框架整合 ...
- SIM900A 发送AT+CSTT 总是 返回Error的原因分析
检查 模块的供电是否正常 本例 修改供电后 联网恢复正常.
- S - Best Reward 扩展KMP
After an uphill battle, General Li won a great victory. Now the head of state decide to reward him w ...
- Hibernate注解开发教程
目录 第一章 类级别注解 1-1 本章简介 一.Hibernate注解简介 二.JPA与Hibernate的关系 三.Hibernate注解的分类 1-2 准备工作 1-3 @Entity注解 1-4 ...
- 相克军_Oracle体系_随堂笔记 PPT
http://www.cnblogs.com/jyzhao/category/581259.html http://download.csdn.net/detail/yzj149286454/8960 ...
- Openfire:XMPP的几种消息类型
XMPP 有以下几种消息类型: l Normal l Chat l Groupchat l Headline l Error 根据官方文档(http://www.igniterea ...
- Java单元測试工具JUnit 5新特性一览
Java单元測试工具JUnit 5新特性一览 作者:chszs,未经博主同意不得转载. 经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs JUnit是最流行的开源 ...
- 3.0 - remote access 基础知识
RA概述: remote access: 广域网的远程连接,按L1分类: 1:通过电路交换网络实现的专线:(circuit switching) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...