Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scaling of KF for numeric stability #12

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/linearsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ void LinearSystem::kf_init(int n, int k, double rho, const Eigen::MatrixXd& Dseq
Kt_b = VectorXd::Zero(k);
Kinf_b = VectorXd::Zero(k);
RQR = s_seq.array().square().inverse();
RQR *= 1 / rho;
RQR *= 1 / sqrt(rho / n);
z = n * sqrt(rho / n);
T.row(0) = Dseq.row(0);
// backward:
r = VectorXd::Zero(k);
Expand Down Expand Up @@ -174,7 +175,7 @@ void LinearSystem::kf_iter(const Eigen::VectorXd& y, const Eigen::ArrayXd& w,
P1inf = MatrixXd::Identity(k, k);
Pinf.col(0) = Map<Eigen::VectorXd>(P1inf.data(), k * k);
while (rankp > 0 && d < n) {
df1step(y(d), 1, 1 / w(d), T, rqr, a1, P1, P1inf, rankp, vt_b, Ft_b,
df1step(y(d), 1, z / w(d), T, rqr, a1, P1, P1inf, rankp, vt_b, Ft_b,
Finf_b, Kt_b, Kinf_b);
at.col(d + 1) = a1;
vt(d) = vt_b;
Expand All @@ -189,7 +190,7 @@ void LinearSystem::kf_iter(const Eigen::VectorXd& y, const Eigen::ArrayXd& w,
for (int i = d; i < n; i++) {
if (!equal_space)
rqr = RQR(i - d);
f1step(y(i), c(i - d) / s, 1, 1 / w(i), T, rqr, a1, P1,
f1step(y(i), c(i - d) / s, 1, z / w(i), T, rqr, a1, P1,
vt_b, Ft_b, Kt_b);
vt(i) = vt_b;
Ft(i) = Ft_b;
Expand Down
2 changes: 1 addition & 1 deletion src/linearsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LinearSystem {
Eigen::SparseMatrix<double> A;
// kf:
int d, rankp;
double vt_b, Ft_b, Finf_b;
double vt_b, Ft_b, Finf_b, z;
Eigen::VectorXd RQR, a1, vt, Ft, Finf, Kt_b, Kinf_b, r, r1, rtmp, sol;
Eigen::MatrixXd T, at, P1, Pt, P1inf, Pinf, Kt, Kinf, L0, L1, Ptemp;
};
Expand Down