/*
* Bayes++ the Bayesian Filtering Library
* Copyright (c) 2002 Michael Stevens
* See accompanying Bayes++.htm for terms and conditions of use.
*
* $Header: /cvsroot/bayesclasses/Bayes++/BayesFilter/UdU.cpp,v 1.24.2.4 2005/01/17 14:00:16 mistevens Exp $
* $NoKeywords: $
*/
/*
* Linear algebra support functions for filter classes
* Cholesky and Modified Cholesky factorisations
*
* UdU' and LdL' factorisations of Positive semi-definate matrices. Where
* U is unit upper triangular
* d is diagonal
* L is unit lower triangular
* Storage
* UD(RowMatrix) format of UdU' factor
* strict_upper_triangle(UD) = strict_upper_triangle(U), diagonal(UD) = d, strict_lower_triangle(UD) ignored or zeroed
* LD(LTriMatrix) format of LdL' factor
* strict_lower_triangle(LD) = strict_lower_triangle(L), diagonal(LD) = d, strict_upper_triangle(LD) ignored or zeroed
*/
#include "bayesFlt.hpp"
#include "matSup.hpp"
#include <cassert>
#include <cmath>
/* Filter Matrix Namespace */
namespace Bayesian_filter_matrix
{
template <class V>
inline typename V::value_type rcond_internal (const V& D)
/*
* Estimate the reciprocal condition number of a Diagonal Matrix for inversion.
* D represents a diagonal matrix, the parameter is actually passed as a vector
*
* The Condition Number is defined from a matrix norm.
* Choose max element of D as the norm of the original matrix.
* Assume this norm for inverse matrix is min element D.
* Therefore rcond = min/max
*
* Note:
* Defined to be 0 for semi-definate and 0 for an empty matrix
* Defined to be 0 for max and min infinite
* Defined to be <0 for negative matrix (D element a value < 0)
* Defined to be <0 with any NaN element
*
* A negative matrix may be due to errors in the original matrix resulting in
* a factorisation producing special values in D (e.g. -infinity,NaN etc)
* By definition rcond <= 1 as min<=max
*/
{
// Special case an empty matrix
const std::size_t n = D.size();
if (n == 0)
return 0;
Vec::value_type rcond, mind = D[0], maxd = 0;
for (std::size_t i = 0; i < n; ++i) {
Vec::value_type d = D[i];
if (d != d) // NaN
return -1;
if (d < mind) mind = d;
if (d > maxd) maxd = d;
}
if (mind < 0) // matrix is negative
return -1;
// ISSUE mind may still be -0, this is progated into rcond
assert (mind <= maxd); // check sanity
rcond = mind / maxd; // rcond from min/max norm
if (rcond != rcond) // NaN, singular due to (mind == maxd) == (zero or infinity)
rcond = 0;
assert (rcond <= 1);
return rcond;
}
template <class V>
inline typename V::value_type rcond_ignore_infinity_internal (const V& D)
/*
* Estimate the reciprocal condition number of a Diagonal Matrix for inversion.
* Same as rcond_internal except that elements are infinity are ignored
* when determining the maximum element.
*/
{
// Special case an empty matrix
const std::size_t n = D.size();
if (n == 0)
return 0;
Vec::value_type rcond, mind = D[0], maxd = 0;
for (std::size_t i = 0; i < n; ++i) {
Vec::value_type d = D[i];
if (d != d) // NaN
return -1;
if (d < mind) mind = d;
if (d > maxd && 1/d != 0) // ignore infinity for maxd
maxd = d;
}
if (mind < 0) // matrix is negative
return -1;
// ISSUE mind may still be -0, this is progated into rcond
if (maxd == 0) // singular due to maxd == zero (elements all zero or infinity)
return 0;
assert (mind <= maxd); // check sanity
rcond = mind / maxd; // rcond from min/max norm
// CRITICAL CHECK requires NaN != NaN
if (rcond != rcond) // NaN, singular due to (mind == maxd) == infinity
rcond = 0;
assert (rcond <= 1);
return rcond;
}
Vec::value_type UdUrcond (const Vec& d)
/*
* Estimate the reciprocal condition number for inversion of the original PSD
* matrix for which d is the factor UdU' or LdL'.
* The original matrix must therefore be diagonal
*/
{
return rcond_internal (d);
}
RowMatrix::value_type UdUrcond (const RowMatrix& UD)
/*
* Estimate the reciprocal condition number for inversion of the original PSD
* matrix for which UD is the factor UdU' or LdL'
*
* The rcond of the original matrix is simply the rcond of its d factor
* Using the d factor is fast and simple, and avoids computing any squares.
*/
{
assert (UD.size1() == UD.size2());
return rcond_internal (diag(UD));
}
RowMatrix::value_type UdUrcond (const RowMatrix& UD, std::size_t n)
/*
* As above but only first n elements are used
*/
{
return rcond_internal (diag(UD,n));
}
UTriMatrix::value_type UCrcond (const UTriMatrix& UC)
/*
* Estimate the reciprocal condition number for inversion of the original PSD
* matrix for which U is the factor UU'
*
* The rcond of the original matrix is simply the square of the rcond of diagonal(UC)
*/
{
assert (UC.size1() == UC.size2());
Float rcond = rcond_internal (diag(UC));
// Square to get rcond of original matrix, take care to propogate rcond's sign!
if (rcond < 0)
return -(rcond*rcond);
else
return rcond*rcond;
}
inline UTriMatrix::value_type UCrcond (const UTriMatrix& UC, std::size_t n)
/*
* As above but for use by UCfactor functions where only first n elements are used
*/
{
Float rcond = rcond_internal (diag(UC,n));
// Square to get rcond of original matrix, take care to propogate rcond's sign!
if (rcond < 0)
return -(rcond*rcond);
else
return rcond*rcond;
}
RowMatrix::value_type UdUdet (const RowMatrix& UD)
/*
* Compute the determinant of the original PSD
* matrix for which UD is the factor UdU' or LdL'
* Result comes directly from determinant of diagonal in triangular matrices
* Defined to be 1 for 0 size UD
*/
{
const std::size_t n = UD.size1();
assert (n == UD.size2());
RowMatrix::value_type det = 1;
for (std::size_t i = 0; i < n; ++i) {
det *= UD(i,i);
}
return det;
}
RowMatrix::value_type UdUfactor_variant1 (RowMatrix& M, std::size_t n)
/*
* In place Modified upper triangular Cholesky factor of a
* Positive definate or semi-definate matrix M
* Reference: A+G p.218 Upper cholesky algorithm modified for UdU'
* Numerical stability may not be as good as M(k,i) is updated from previous results
* Algorithm has poor locality of reference and avoided for large matrices
* Infinity values on the diagonal can be factorised
*
* Strict lower triangle of M is ignored in computation
*
* Input: M, n=last std::size_t to be included in factorisation
* Output: M as UdU' factor
* strict_upper_triangle(M) = strict_upper_triangle(U)
* diagonal(M) = d
* strict_lower_triangle(M) is unmodifed
* Return:
* reciprocal condition number, -1 if negative, 0 if semi-definate (including zero)
*/
{
std::size_t i,j,k;
RowMatrix::value_type e, d;
if (n > 0)
{
j = n-1;
do {
d = M(j,j);
// Diagonal element
if (d > 0)
{ // Positive definate
d = 1 / d;
for (i = 0; i < j; ++i)
{
e = M(i,j);
M(i,j) = d*e;
for (k = 0; k <= i; ++k)
{
RowMatrix::Row Mk(M,k);
Mk[i] -= e*Mk[j];
}
}
}
else if (d == 0)
{ // Possibly Semidefinate, check not negative
for (i = 0; i < j; ++i)
{
if (M(i,j) != 0)
goto Negative;
}
}
else
{ // Negative
goto Negative;
}
} while (j-- > 0);
}
// Estimate the reciprocal condition number
return rcond_internal (diag(M,n));
Negative:
return -1;
}
RowMatrix::value_type UdUfactor_variant2 (RowMatrix& M, std::size_t n)
/*
* In place Modified upper triangular Cholesky factor of a
* Positive definate or semi-definate matrix M
* Reference: A+G p.219 right side of table
* Algorithm has good locality of reference and preferable for large matrices
* Infinity values on the diagonal cannot be factorised
*
* Strict lower triangle of M is ignored in computation
*
* Input: M, n=last std::size_t to be included in factorisation
* Output: M as UdU' factor
* strict_upper_triangle(M) = strict_upper_triangle(U)
* diagonal(M) = d
* strict_lower_tria
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Bayesian Filter.贝叶斯(Bayesian)滤波器的C++类库。包括卡尔曼滤波(kalman filter)、粒子滤波(particle filter)
资源推荐
资源详情
资源评论
收起资源包目录
Bayesian Filter.贝叶斯(Bayesian)滤波器的C++类库。包括卡尔曼滤波(kalman filter)、粒子滤波(particle filter).zip (64个子文件)
Bayesian Filter.贝叶斯(Bayesian)滤波器的C++类库。包括卡尔曼滤波(kalman filter)、粒子滤波(particle filter)
Bayes++.doxygen 7KB
Bayesian Filtering Classes.html 36KB
Jamrules 730B
Test
random.hpp 3KB
VClib
VClib.vcproj 6KB
Jamfile 507B
SLAM
fastSLAM.hpp 4KB
kalmanSLAM.hpp 2KB
testFastSLAM.cpp 9KB
fastSLAM.cpp 13KB
FastSLAM.vcproj 3KB
Jamfile.v2 243B
kalmanSLAM.cpp 6KB
SLAM.hpp 4KB
PV
Jamfile 331B
PV.cpp 5KB
Jamfile.v2 175B
PV.vcproj 3KB
Jamfile.v2 349B
Makefile 801B
Bayes++.sln 3KB
QuadCalib
Jamfile 366B
QuadCalib.cpp 5KB
QuadCalib.vcproj 3KB
Jamfile.v2 201B
Simple
Jamfile 351B
Jamfile.v2 191B
simpleExample.cpp 2KB
simple.vcproj 3KB
project-root.jam 979B
Bayes++.html 24KB
BayesFilter
CIFlt.hpp 2KB
matSup.cpp 3KB
matSup.hpp 3KB
infFlt.hpp 3KB
schemeFlt.hpp 3KB
covFlt.hpp 2KB
models.hpp 9KB
infRtFlt.hpp 3KB
covFlt.cpp 4KB
uBLASmatrix.hpp 22KB
Jamfile 665B
matSupSub.hpp 5KB
UdU.cpp 22KB
allFilters.hpp 696B
itrFlt.cpp 4KB
unsFlt.hpp 5KB
UDFlt.cpp 13KB
infFlt.cpp 6KB
uLAPACK.hpp 6KB
CIFlt.cpp 4KB
bayesFlt.hpp 22KB
unsFlt.cpp 9KB
Jamfile.v2 727B
bayesFltAlg.cpp 7KB
bayesFlt.cpp 7KB
infRtFlt.cpp 9KB
SIRFlt.hpp 9KB
filters
average1.hpp 2KB
indirect.hpp 3KB
SIRFlt.cpp 16KB
bayesException.hpp 1KB
UDFlt.hpp 3KB
itrFlt.hpp 4KB
共 64 条
- 1
资源评论
- m0_629188452023-04-05资源和描述一致,质量不错,解决了我的问题,感谢资源主。
wouderw
- 粉丝: 268
- 资源: 2960
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240430_144340_com.ss.android.ugc.live.jpg
- 回到山沟沟.mp3
- 基于matlab实现自适应波束形成RLS及LMS算法仿真源程序1.rar
- 基于matlab实现自己编写的基于卡尔曼滤波的利用加速度传感器的计步器,测试数据是传感器放在腰部和手臂 .rar
- 基于matlab实现阵列信号处理,波束形成.rar
- 111111111111111111
- 基于matlab实现计步器编程;对当前的计步器装置的数值算法模拟 .rar
- Mdb学习查看PW;access;mdb;pw;password;patch
- 基于matlab实现关于语音信号声源定位DOA估计所用的一些传统算法.rar
- 基于ultralytics-yolov8, 将其检测/分类/分割/姿态等任务移植到rk3588上
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功