Class GWDA

Inheritance Relationships

Base Types

Class Documentation

class GWDA : public gwm::SpatialMonoscaleAlgorithm, public gwm::IMultivariableAnalysis, public gwm::IParallelizable, public gwm::IParallelOpenmpEnabled

The class for Geographically Weighted Discriminant Analysis. Geographically Weighted Discriminant Analysis is an algorithm for calculating local weighted statistics, where location-wise probabilities and their associated entropy are also calculated.

Public Types

typedef void (GWDA::* DiscriminantAnalysisCalculator)()

Calculator for summary statistics.

Public Functions

inline GWDA()

Construct a new GWDA object.

inline GWDA(const arma::mat x, const arma::mat coords, const SpatialWeight &spatialWeight)

Construct a new GWDA object.

inline ~GWDA()

Destroy the GWDA object.

inline bool isWqda() const

Get whether weighted quadratic discriminant analysis will be applied; otherwise weighted linear discriminant analysis will be applied. Yes No.

inline void setIsWqda(bool iswqda)

Set whether weighted quadratic discriminant analysis will be applied. Whether weighted quadratic discriminant analysis will be applied.

inline bool hasCov() const

Get whether localised variance-covariance matrix is used for GW discriminant analysis; otherwise, global variance-covariance matrix is used. Yes No.

inline void setHascov(bool hascov)

Set whether localised variance-covariance matrix is used for GW discriminant analysis; otherwise, global variance-covariance matrix is used. Whether localised variance-covariance matrix is used for GW discriminant analysis; otherwise, global variance-covariance matrix is used.

inline bool hasMean() const

Get whether localised mean is used for GW discriminant analysis; otherwise, global mean is used. Yes No.

inline void setHasmean(bool hasmean)

Set whether localised variance-covariance matrix is used for GW discriminant analysis; otherwise, global variance-covariance matrix is used. Whether localised mean is used for GW discriminant analysis; otherwise, global mean is used.

inline bool hasPrior() const

Get whether localised prior probability is used for GW discriminant analysis; otherwise, fixed prior probability is used. Yes No.

inline void setHasprior(bool hasprior)

Set whether localised prior probability is used for GW discriminant analysis; otherwise, fixed prior probability is used. Whether localised prior probability is used for GW discriminant analysis; otherwise, fixed prior probability is used.

inline double correctRate() const

Get prediction accuracy Prediction accuracy.

inline const arma::mat &res() const

Get the result matrix of geographical weighted discriminant analysis The result matrix of geographical weighted discriminant analysis.

inline const std::vector<std::string> &group() const

Get classification results Classification results.

inline const arma::mat &probs() const

Get location-wise probabilities Location-wise probabilities.

inline const arma::mat &pmax() const

Get max location-wise probabilities max location-wise probabilities.

inline const arma::mat &entropy() const

Get associated entropy Associated entropy.

arma::mat wqda(arma::mat &x, std::vector<std::string> &y, arma::mat &wt, arma::mat &xpr, bool hasCOv, bool hasMean, bool hasPrior)

Weighted quadratic discriminant analysis.

Parameters:
  • x – Independent variables.

  • y – Dependent variable.

  • wt – Weighted matrix.

  • xpr – Predict data variables.

  • hasCov – whether localised variance-covariance matrix is used for GW discriminant analysis; otherwise, global variance-covariance matrix is used.

  • hasMean – Whether localised mean is used for GW discriminant analysis; otherwise, global mean is used.

  • hasPrior – Whether localised prior probability is used for GW discriminant analysis; otherwise, fixed prior probability is used.

Returns:

arma::mat The result matrix of geographical weighted discriminant analysis.

arma::mat wlda(arma::mat &x, std::vector<std::string> &y, arma::mat &wt, arma::mat &xpr, bool hasCOv, bool hasMean, bool hasPrior)

Weighted linear discriminant analysis.

Parameters:
  • x – Independent variables.

  • y – Dependent variable.

  • wt – Weighted matrix.

  • xpr – Predict data variables.

  • hasCov – whether localised variance-covariance matrix is used for GW discriminant analysis; otherwise, global variance-covariance matrix is used.

  • hasMean – Whether localised mean is used for GW discriminant analysis; otherwise, global mean is used.

  • hasPrior – Whether localised prior probability is used for GW discriminant analysis; otherwise, fixed prior probability is used.

Returns:

arma::mat The result matrix of geographical weighted discriminant analysis.

std::vector<arma::mat> splitX(arma::mat &x, std::vector<std::string> &y)

Filter arguments according to different categories. Independent variables. Dependent variable. Filter results.

arma::mat wMean(arma::mat &x, arma::mat &wt)

Calculate the local weighted mean. Independent variables. Weighted matrix. Calculate results.

arma::cube wVarCov(arma::mat &x, arma::mat &wt)

Calculate localised variance-covariance. Independent variables. Weighted matrix. Calculate results.

arma::vec wPrior(arma::mat &wt, double sumW)

Calculate localised prior probability. Independent variables. Weight sum. Calculate results.

std::vector<std::string> levels(std::vector<std::string> &y)

Gets the category information of the dependent variable. Dependent variable. Category information.

double shannonEntropy(arma::vec &p)

Calculate associated entropy. Location-wise probabilities Calculate results.

arma::uvec findSameString(std::vector<std::string> &y, std::string s)

Gets the index of the same category in the dependent variable. Dependent variable. Detection value. Index information.

std::unordered_map<std::string, arma::uword> ytable(std::vector<std::string> &y)

Gets the counts of categories in the dependent variable. Dependent variable. Counts information of each category.

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.

inline virtual const arma::mat &variables() const override

Get variables.

Returns:

Vector of variables.

inline virtual void setVariables(const arma::mat &x) override

Set variables.

Parameters:

x – Vector of variables.

inline void setGroup(std::vector<std::string> &y)
virtual void run() override

Run analysis algorithm.

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.

Use gwmodel_set_gwss_openmp() to set parallel type of this algorithm to ParallelType::OpenMP in shared build.

Parameters:

type – Parallel type of this algorithm.

inline virtual void setOmpThreadNum(const int threadNum) override

Set the thread numbers while paralleling.

Use gwmodel_set_gwss_openmp() to set this property in shared build.

Parameters:

threadNum – Number of threads.

Public Static Functions

static arma::mat covwtmat(const arma::mat &x, const arma::vec &wt)

Calculate weighted covariances for two matrices. Matrix \( X \) Weight vector \( w \) Weighted covariances.

\[ cov(X_1,X_2) = \frac{\sum_{i=1}^n w_i(x_{1i} - \bar{x}_1) \sum_{i=1}^n w_i(x_{2i} - \bar{x}_2)}{1 - \sum_{i=1}^n w_i} \]

static inline double covwt(const arma::mat &x1, const arma::mat &x2, const arma::vec &w)

Calculate weighted covariances for two matrices. Matrix \( X_1 \) Matrix \( X_2 \) Weight vector \( w \) Weighted covariances.

\[ cov(X_1,X_2) = \frac{\sum_{i=1}^n w_i(x_{1i} - \bar{x}_1) \sum_{i=1}^n w_i(x_{2i} - \bar{x}_2)}{1 - \sum_{i=1}^n w_i} \]

static inline double corwt(const arma::mat &x1, const arma::mat &x2, const arma::vec &w)

Calculate weighted correlation for two matrices. Matrix \( X_1 \) Matrix \( X_2 \) Weight vector \( w \) Weighted correlation.

\[ corr(X_1,X_2) = \frac{cov(X_1,X_2)}{\sqrt{cov(X_1,X_1) cov(X_2,X_2)}} \]
加权相关系数
\[ corr(X_1,X_2) = \frac{cov(X_1,X_2)}{\sqrt{cov(X_1,X_1) cov(X_2,X_2)}} \]