Skip to content

Commit b82988e

Browse files
committed
edit: optimise matrix inverse
1 parent 17a3c41 commit b82988e

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/gwmodelpp/GWRMultiscale.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,17 @@ vec GWRMultiscale::fitVarSerial(const vec &x, const vec &y, const uword var, mat
426426
if (mHasHatMatrix)
427427
{
428428
mat ci, si;
429-
S = mat(mHasHatMatrix ? nDp : 1, nDp, fill::zeros);
429+
S = mat(nDp, nDp, fill::zeros);
430430
for (uword i = 0; i < nDp ; i++)
431431
{
432432
GWM_LOG_STOP_BREAK(mStatus);
433433
vec w = mSpatialWeights[var].weightVector(i);
434434
mat xtw = trans(x % w);
435-
mat xtwx = xtw * x;
436-
mat xtwy = xtw * y;
435+
double xtwx = as_scalar(xtw * x);
436+
double xtwy = as_scalar(xtw * y);
437437
try
438438
{
439-
mat xtwx_inv = inv_sympd(xtwx);
439+
double xtwx_inv = 1.0 / xtwx;
440440
betas.col(i) = xtwx_inv * xtwy;
441441
ci = xtwx_inv * xtw;
442442
si = x(i) * ci;
@@ -570,12 +570,12 @@ double GWRMultiscale::bandwidthSizeCriterionVarCVSerial(BandwidthWeight *bandwid
570570
vec w = bandwidthWeight->weight(d);
571571
w(i) = 0.0;
572572
mat xtw = trans(mXi % w);
573-
mat xtwx = xtw * mXi;
574-
mat xtwy = xtw * mYi;
573+
double xtwx = as_scalar(xtw * mXi);
574+
double xtwy = as_scalar(xtw * mYi);
575575
try
576576
{
577-
mat xtwx_inv = inv_sympd(xtwx);
578-
vec beta = xtwx_inv * xtwy;
577+
double xtwx_inv = 1.0 / xtwx;
578+
double beta = xtwx_inv * xtwy;
579579
double res = mYi(i) - det(mXi(i) * beta);
580580
cv += res * res;
581581
}
@@ -607,11 +607,11 @@ double GWRMultiscale::bandwidthSizeCriterionVarAICSerial(BandwidthWeight *bandwi
607607
vec d = mSpatialWeights[var].distance()->distance(i);
608608
vec w = bandwidthWeight->weight(d);
609609
mat xtw = trans(mXi % w);
610-
mat xtwx = xtw * mXi;
611-
mat xtwy = xtw * mYi;
610+
double xtwx = as_scalar(xtw * mXi);
611+
double xtwy = as_scalar(xtw * mYi);
612612
try
613613
{
614-
mat xtwx_inv = inv_sympd(xtwx);
614+
double xtwx_inv = 1.0 / xtwx;
615615
betas.col(i) = xtwx_inv * xtwy;
616616
mat ci = xtwx_inv * xtw;
617617
mat si = mXi(i) * ci;

0 commit comments

Comments
 (0)