Skip to content

Commit 1d1d56b

Browse files
authored
Merge pull request #106 from GWmodel-Lab/fix/sgwr
fix: correct sgwr related logic
2 parents bddacd7 + 81f9204 commit 1d1d56b

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

include/gwmodelpp/GWRScalable.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ class GWRScalable : public GWRBase
146146
*/
147147
void setHasHatMatrix(const bool has) { mHasHatMatrix = has; }
148148

149+
/**
150+
* @brief \~english Get standard errors of coefficient estimates. \~chinese 获取回归系数估计值的标准差。
151+
*
152+
* @return arma::mat \~english Standard errors of coefficient estimates. \~chinese 回归系数估计值的标准差。
153+
*/
154+
const arma::mat& betasSE() const { return mBetasSE; }
155+
156+
/**
157+
* @brief \~english Get a vector of \f$tr(S)\f$ and \f$tr(SS^T)\f$. \~chinese 获取一个由 \f$tr(S)\f$ 和 \f$tr(SS^T)\f$ 组成的向量。
158+
*
159+
* @return arma::vec \~english A vector of \f$tr(S)\f$ and \f$tr(SS^T)\f$. \~chinese 由 \f$tr(S)\f$ 和 \f$tr(SS^T)\f$ 组成的向量。
160+
*/
161+
const arma::vec& sHat() const { return mShat; }
162+
149163
/**
150164
* @brief \~english Get the type of calculator for parameter optimization criterion. \~chinese 获取计算优化参数指标值的类型。
151165
*

test/testGWRScalable.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ TEST_CASE("ScableGWR: autoselection with CV")
122122

123123
REQUIRE(algorithm.hasIntercept() == true);
124124

125+
// Test sHat() and betasSE() getters
126+
vec shat = algorithm.sHat();
127+
mat betasSE = algorithm.betasSE();
128+
double cv = algorithm.cv();
129+
130+
std::cout << "\n=== ScalableGWR Intermediate Results ===" << std::endl;
131+
std::cout << "CV (Cross-Validation) value: " << cv << std::endl;
132+
std::cout << "sHat values: tr(S)=" << shat(0) << ", tr(S'S)=" << shat(1) << std::endl;
133+
std::cout << "betasSE shape: " << betasSE.n_rows << " x " << betasSE.n_cols << std::endl;
134+
std::cout << "betasSE first row: " << betasSE.row(0) << std::endl;
135+
std::cout << "betasSE values (全部):\n" << betasSE << std::endl;
136+
137+
REQUIRE(shat.n_rows == 2);
138+
REQUIRE(betasSE.n_rows > 0);
139+
REQUIRE(betasSE.n_cols > 0);
140+
125141
}
126142

127143
TEST_CASE("Scalable GWR: cancel")

0 commit comments

Comments
 (0)