Class GWRBasic
Defined in File GWRBasic.h
Inheritance Relationships
Base Types
public gwm::GWRBase
(Class GWRBase)public gwm::IBandwidthSelectable
(Struct IBandwidthSelectable)public gwm::IVarialbeSelectable
(Struct IVarialbeSelectable)public gwm::IParallelizable
(Struct IParallelizable)public gwm::IParallelOpenmpEnabled
(Struct IParallelOpenmpEnabled)public gwm::IParallelCudaEnabled
(Struct IParallelCudaEnabled)public gwm::IParallelMpiEnabled
(Struct IParallelMpiEnabled)
Derived Type
public gwm::GWRRobust
(Class GWRRobust)
Class Documentation
-
class GWRBasic : public gwm::GWRBase, public gwm::IBandwidthSelectable, public gwm::IVarialbeSelectable, public gwm::IParallelizable, public gwm::IParallelOpenmpEnabled, public gwm::IParallelCudaEnabled, public gwm::IParallelMpiEnabled
Basic implementation of geographically weighted regression. This algorithm can auto select bandwidth and variables. This algorithm can speed-up by OpenMP.
Subclassed by gwm::GWRRobust
Public Types
-
enum BandwidthSelectionCriterionType
Type of criterion for bandwidth selection.
Values:
-
enumerator AIC
AIC.
-
enumerator CV
CV.
-
enumerator AIC
-
typedef arma::mat (GWRBasic::* PredictCalculator)(const arma::mat&, const arma::mat&, const arma::vec&)
Predict function declaration.
-
typedef arma::mat (GWRBasic::* FitCoreCalculator)(const arma::mat&, const arma::vec&, const SpatialWeight&)
Fit function declaration.
-
typedef arma::mat (GWRBasic::* FitCoreSHatCalculator)(const arma::mat&, const arma::vec&, const SpatialWeight&, arma::vec&)
Fit function declaration.
-
typedef arma::mat (GWRBasic::* FitCoreCVCalculator)(const arma::mat&, const arma::vec&, const SpatialWeight&)
Fit function declaration.
-
typedef double (GWRBasic::* BandwidthSelectionCriterionCalculator)(BandwidthWeight*)
Declaration of criterion calculator for bandwidth selection.
Public Functions
-
inline GWRBasic()
Construct a new CGwmGWRBasic object.
-
inline GWRBasic(const arma::mat &x, const arma::vec &y, const arma::mat &coords, const SpatialWeight &spatialWeight, bool hasHatMatrix = true, bool hasIntercept = true)
Construct a new CGwmGWRBasic object.
- Parameters:
x – Independent variables.
y – Dependent variable.
coords – Coordinate matrix.
spatialWeight – Spatial weighting configuration.
hasHatMatrix – Whether has hat-matrix.
hasIntercept – Whether has intercept.
-
inline ~GWRBasic()
Destroy the CGwmGWRBasic object.
-
inline bool isAutoselectBandwidth() const
Get whether auto select bandwidth.
- Returns:
true if auto select bandwidth.
- Returns:
false if not auto select bandwidth.
-
inline void setIsAutoselectBandwidth(bool isAutoSelect)
Set whether auto select bandwidth.
- Parameters:
isAutoSelect – true if auto select bandwidth, otherwise false.
-
inline BandwidthSelectionCriterionType bandwidthSelectionCriterion() const
Get type of criterion for bandwidth selection.
- Returns:
BandwidthSelectionCriterionType Type of criterion for bandwidth selection.
-
void setBandwidthSelectionCriterion(const BandwidthSelectionCriterionType &criterion)
Set type of criterion for bandwidth selection.
- Parameters:
criterion – Type of criterion for bandwidth selection.
-
inline void setGoldenUpperBounds(double value)
Set the upper bounds of golden selection.
-
inline void setGoldenLowerBounds(double value)
Set the lower bounds of golden selection.
-
inline bool isAutoselectIndepVars() const
Get whether auto select variables.
- Returns:
true if auto select variables.
- Returns:
false if not auto select variables.
-
inline void setIsAutoselectIndepVars(bool isAutoSelect)
Set whether auto select variables.
- Parameters:
isAutoSelect – true if auto select variables, otherwise false.
-
inline double indepVarSelectionThreshold() const
Get threshold for variable selection.
- Returns:
double Threshold for variable selection.
-
inline void setIndepVarSelectionThreshold(double threshold)
Set threshold for variable selection.
- Parameters:
threshold – Threshold for variable selection. This value dependends on the size of samples. Larger samples, larger threshold.
-
inline const VariablesCriterionList &indepVarsSelectionCriterionList() const
Get criterion list for variable selection.
- Returns:
VariablesCriterionList Criterion list for variable selection.
-
inline const BandwidthCriterionList &bandwidthSelectionCriterionList() const
Get criterion list for bandwidth selection.
- Returns:
BandwidthCriterionList Criterion list for bandwidth selection.
-
inline bool hasHatMatrix() const
Get whether has hat-matrix.
- Returns:
true if has hat-matrix.
- Returns:
false if does not have hat-matrix.
-
inline void setHasHatMatrix(const bool has)
Set the Has Hat-Matrix object.
- Parameters:
has – true if has hat-matrix, otherwise false.
-
inline const arma::mat &betasSE()
Get standard errors of coefficient estimates.
- Returns:
arma::mat Standard errors of coefficient estimates.
-
inline const arma::vec &sHat()
Get a vector of \(tr(S)\) and \(tr(SS^T)\).
- Returns:
arma::vec A vector of \(tr(S)\) and \(tr(SS^T)\).
-
inline const arma::vec &qDiag()
Get the diagonal elements of matrix \(Q\).
- Returns:
arma::vec The diagonal elements of matrix \(Q\).
-
inline const arma::mat &s()
Get the hat-matrix \(S\).
- Returns:
arma::mat The hat-matrix \(S\).
-
inline const arma::cube &c()
-
inline bool isStoreS()
Whether to store hat-matrix \(S\).
- Returns:
true if store hat-matrix.
- Returns:
false if not to store hat-matrix.
-
inline bool isStoreC()
-
inline void setStoreS(bool flag)
-
inline void setStoreC(bool flag)
-
virtual bool isValid() override
Check whether the algorithm’s configuration is valid.
- Returns:
true if the algorithm’s configuration is valid.
- Returns:
false if the algorithm’s configuration is invalid.
-
virtual arma::mat predict(const arma::mat &locations) override
Predict coefficients on specified locations.
- Parameters:
locations – Locations where to predict coefficients.
- Returns:
mat Predicted coefficients.
-
virtual arma::mat fit() override
Fit coefficient estimates.
- Returns:
mat Coefficient estimates
-
inline virtual std::vector<std::size_t> selectedVariables() override
Get selected variables.
- Returns:
std::vector<std::size_t> Selected variables.
-
double indepVarsSelectionCriterion(const std::vector<std::size_t> &indepVars)
Get AIC value with given variables for variable optimization (serial implementation).
- Parameters:
indepVars – Given variables
- Returns:
double Criterion value
-
inline virtual Status getCriterion(BandwidthWeight *weight, double &criterion) override
Get criterion value with given bandwidth for bandwidth optimization.
- Parameters:
weight – Given bandwidth.
criterion – [out] Criterion value.
- Returns:
Status Algorithm status.
-
double bandwidthSizeCriterionCV(BandwidthWeight *bandwidthWeight)
Get CV value with given bandwidth for bandwidth optimization (serial implementation).
- Parameters:
bandwidthWeight – Given bandwidth
- Returns:
double Criterion value
-
double bandwidthSizeCriterionAIC(BandwidthWeight *bandwidthWeight)
Get AIC value with given bandwidth for bandwidth optimization (serial implementation).
- Parameters:
bandwidthWeight – Given bandwidth
- Returns:
double Criterion value
-
inline virtual int parallelAbility() const override
Return the parallel ability of this algorithm.
- Returns:
Bitwise OR of aviliable parallel types of this algorithm.
-
inline virtual ParallelType parallelType() const override
Return the parallel type of this algorithm.
- Returns:
Parallel type of this algorithm
-
virtual void setParallelType(const ParallelType &type) override
Set the parallel type of this algorithm.
- Parameters:
type – Parallel type of this algorithm.
-
inline virtual void setOmpThreadNum(const int threadNum) override
Set the thread numbers while paralleling.
- Parameters:
threadNum – Number of threads.
-
inline virtual void setGPUId(const int gpuId) override
Set ID of used GPU while paralleling.
- Parameters:
gpuId – ID of used GPU. Start from 0.
-
inline virtual void setGroupSize(const std::size_t size) override
Set the group size while paralleling.
- Parameters:
size – Group size \(g\) while paralleling. Usually this is up to memory size \(m\) (B) of GPU with ID gpuId. If there are \(n\) samples and \(k\) variables,
\[ k * n * g * 8 < m \]For most GPU, 64 is OK.
-
inline virtual int workerId() override
-
inline virtual void setWorkerId(int id) override
-
inline virtual void setWorkerNum(int size) override
Public Static Attributes
-
static std::unordered_map<BandwidthSelectionCriterionType, std::string> BandwidthSelectionCriterionTypeNameMapper
Protected Functions
Protected Attributes
-
bool mHasHatMatrix = true
Whether has hat-matrix.
-
bool mHasPredict = false
- Deprecated:
Whether has variables to predict dependent variable.
-
bool mIsAutoselectIndepVars = false
Whether to auto select variables.
-
double mIndepVarSelectionThreshold = 3.0
The threshold for variable selection.
-
IndepVarsSelectCriterionCalculator mIndepVarsSelectionCriterionFunction = &GWRBasic::indepVarsSelectionCriterion
Criterion calculator for variable selection.
-
VariablesCriterionList mIndepVarsSelectionCriterionList
Criterion list of each variable combination.
-
std::vector<std::size_t> mSelectedIndepVars
Selected variables.
-
std::size_t mIndepVarSelectionProgressTotal = 0
Total number of independent variable combination.
-
std::size_t mIndepVarSelectionProgressCurrent = 0
Current progress of independent variable selection.
-
bool mIsAutoselectBandwidth = false
Whether to auto select bandwidth.
-
BandwidthSelectionCriterionType mBandwidthSelectionCriterion = BandwidthSelectionCriterionType::AIC
Type criterion for bandwidth selection.
-
BandwidthSelectionCriterionCalculator mBandwidthSelectionCriterionFunction = &GWRBasic::bandwidthSizeCriterionCV
Criterion calculator for bandwidth selection.
-
BandwidthCriterionList mBandwidthSelectionCriterionList
Criterion list of each bandwidth.
-
double mBandwidthLastCriterion = DBL_MAX
Last criterion for bandwidth selection.
-
std::optional<double> mGoldenUpperBounds
-
std::optional<double> mGoldenLowerBounds
-
PredictCalculator mPredictFunction = &GWRBasic::predictSerial
Implementation of predict function.
-
FitCalculator mFitFunction = &GWRBasic::fitBase
Implementation of fit function.
-
FitCoreCalculator mFitCoreFunction = &GWRBasic::fitCoreSerial
Implementation of fit function.
-
FitCoreSHatCalculator mFitCoreSHatFunction = &GWRBasic::fitCoreSHatSerial
Implementation of fit function.
-
FitCoreCVCalculator mFitCoreCVFunction = &GWRBasic::fitCoreCVSerial
Implementation of fit function.
-
ParallelType mParallelType = ParallelType::SerialOnly
Type of parallel method.
-
int mOmpThreadNum = 8
Number of threads to create.
-
size_t mGroupLength = 64
Size of a group computing together.
-
int mGpuId = 0
The ID of selected GPU.
-
int mWorkerId = 0
-
int mWorkerNum = 1
-
arma::uword mWorkRangeSize = 0
-
std::optional<std::pair<arma::uword, arma::uword>> mWorkRange
-
arma::mat mBetasSE
Standard errors of coefficient estimates.
-
arma::vec mSHat
A vector of \(tr(S)\) and \(tr(SS^T)\).
-
arma::vec mQDiag
The diagonal elements of matrix \(Q\).
-
arma::mat mS
The hat-matrix \(S\).
-
arma::cube mC
All \(S\) matrices.
-
bool mStoreS = false
Whether to save S.
-
bool mStoreC = false
Whether to save C.
-
enum BandwidthSelectionCriterionType