Class GTWR

Inheritance Relationships

Base Types

Class Documentation

class GTWR : public gwm::GWRBase, public gwm::IBandwidthSelectable, public gwm::IParallelizable, public gwm::IParallelOpenmpEnabled

Basic implementation of geographically temporally weighted regression. This algorithm can auto select bandwidth.

Public Types

enum BandwidthSelectionCriterionType

Type of criterion for bandwidth selection.

Values:

enumerator AIC
enumerator CV
typedef arma::mat (GTWR::* PredictCalculator)(const arma::mat&, const arma::mat&, const arma::vec&)

Predict function declaration.

typedef arma::mat (GTWR::* FitCalculator)(const arma::mat&, const arma::vec&, arma::mat&, arma::vec&, arma::vec&, arma::mat&)

Fit function declaration.

typedef double (GTWR::* BandwidthSelectionCriterionCalculator)(BandwidthWeight*)

Declaration of criterion calculator for bandwidth selection.

typedef double (GTWR::* IndepVarsSelectCriterionCalculator)(const std::vector<std::size_t>&)

Declaration of criterion calculator for variable selection.

Public Functions

inline GTWR()

Construct a new GTWR object.

inline GTWR(const arma::mat &x, const arma::vec &y, const arma::mat &coords, const SpatialWeight &spatialWeight, bool hasHatMatrix = true, bool hasIntercept = true)

Construct a new GTWR 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 ~GTWR()

Destroy the GTWR 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 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 void setCoords(const arma::mat &coords, const arma::vec &times)

Set the spatial and temporal data.

Parameters:
  • coords – spatial coordinates mat.

  • times – temporal stamps vector.

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\).

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 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.

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 void setIsAutoselectLambda(bool isAutoSelect)

Get whether auto select lambda.

Returns:

true if auto select lambda.

Returns:

false if not auto select lambda.

Public Static Functions

static inline std::string infoLambdaCriterion()

Get meta infomation of lambda and the corresponding criterion value. Information string.

static inline std::string infoLambdaCriterion(const double &lambda, const double &criterion)

Get infomation of lambda and the corresponding criterion value. Lambda value Criterion value Information string.

Public Static Attributes

static std::unordered_map<BandwidthSelectionCriterionType, std::string> BandwidthSelectionCriterionTypeNameMapper

Protected Functions

inline bool isStoreS()

Whether to store hat-matrix \(S\).

Returns:

true if store hat-matrix.

Returns:

false if not to store hat-matrix.

void createPredictionDistanceParameter(const arma::mat &locations)

Create distance parameters for prediction.

Parameters:

locationsDistance parameters for prediction.

void createDistanceParameter()

Create distance parameters.

double LambdaAutoSelection(BandwidthWeight *bandwidthWeight)

Lambda and bandwidth auto selection. not complete.

Lambda auto selection.

Parameters:

bandwidthWeight – bandwidth parameters to create weight.

Returns:

double best lambda after selection.

Status RsquareByLambda(BandwidthWeight *bandwidthWeight, double lambda, double &rsquare)

Rsquare calculate by lambda.

Parameters:
  • bandwidthWeight – bandwidth weight parameters,

  • lambda – the lambda value.

  • rsquare – R-square by lambda.

Returns:

Status Algorithm status.

Protected Attributes

bool mHasHatMatrix = true

Whether has hat-matrix.

bool mHasFTest = false

Todo:

Whether has F-test

bool mHasPredict = false

Deprecated:

Whether has variables to predict dependent variable.

bool mIsAutoselectBandwidth = false

Whether need bandwidth autoselect.

bool mIsAutoselectLambda = false

Whether need lambda autoselect.

BandwidthSelectionCriterionType mBandwidthSelectionCriterion = BandwidthSelectionCriterionType::AIC

Bandwidth Selection Criterion Type.

BandwidthSelectionCriterionCalculator mBandwidthSelectionCriterionFunction = &GTWR::bandwidthSizeCriterionCVSerial

Bandwidth Selection Criterion Function.

BandwidthCriterionList mBandwidthSelectionCriterionList

Bandwidth Selection Criterion List.

double mBandwidthLastCriterion = DBL_MAX

Last criterion for bandwidth selection.

PredictCalculator mPredictFunction = &GTWR::predictSerial

Predict Function.

FitCalculator mFitFunction = &GTWR::fitSerial

Fit Function.

ParallelType mParallelType = ParallelType::SerialOnly

Type of parallel method.

int mOmpThreadNum = 8

Number of threads to create.

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::vec vTimes

vectors for timestamp input.

CRSSTDistance *mStdistance