Class SpatialWeight

Class Documentation

class SpatialWeight

A combined class of distance and weight. Instances of this class are usually constructed by providing pointers to Distance and Weight. In the construct function, instances of types Distance and Weight will be cloned. This class provide the method SpatialWeight::weightVector() to calculate spatial weight directly.

If the distance and weight are set by pointers, this class will take the control of them, and when destructing the pointers will be deleted. If the distance and weight are set by references, this class will clone them.

Public Functions

inline SpatialWeight()

Construct a new SpatialWeight object.

inline SpatialWeight(const Weight *weight, const Distance *distance)

Construct a new SpatialWeight object.

Parameters:
  • weight – Pointer to a weight configuration.

  • distance – Pointer to distance configuration.

inline SpatialWeight(const std::unique_ptr<Weight> &weight, const std::unique_ptr<Distance> &distance)

Construct a new SpatialWeight object.

Parameters:
  • weight – Pointer to a weight configuration.

  • distance – Pointer to distance configuration.

inline SpatialWeight(std::unique_ptr<Weight> &&weight, std::unique_ptr<Distance> &&distance)

Construct a new SpatialWeight object.

Parameters:
  • weight – Pointer to a weight configuration.

  • distance – Pointer to distance configuration.

inline SpatialWeight(const Weight &weight, const Distance &distance)

Construct a new SpatialWeight object.

Parameters:
  • weight – Reference to a weight configuration.

  • distance – Reference to distance configuration.

inline SpatialWeight(const SpatialWeight &spatialWeight)

Copy construct a new SpatialWeight object.

Parameters:

spatialWeight – Reference to the object to copy from.

inline SpatialWeight(SpatialWeight &&other)

Move construct a new SpatialWeight object.

Parameters:

other – Reference to the object to move from.

inline virtual ~SpatialWeight()

Destroy the SpatialWeight object.

inline const std::unique_ptr<Weight> &weight() const

Get the pointer to SpatialWeight::mWeight .

Returns:

Pointer to SpatialWeight::mWeight .

inline void setWeight(const Weight *weight)

Set the pointer to SpatialWeight::mWeight object.

Parameters:

weight – Pointer to Weight instance. Control of this pointer will be taken, and it will be deleted when destructing.

inline void setWeight(const Weight &weight)

Set the pointer to SpatialWeight::mWeight object.

Parameters:

weight – Reference to Weight instance. This object will be cloned.

inline void setWeight(Weight &&weight)

Set the pointer to SpatialWeight::mWeight object.

Parameters:

weight – Reference to Weight instance. This object will be cloned.

inline void setWeight(std::unique_ptr<Weight> &&weight)

Set the pointer to SpatialWeight::mWeight object.

Parameters:

weight – Right reference of unique pointer to Weight instance. This object will be moved.

template<typename T>
inline T &weight() const

Get the reference of SpatialWeight::mWeight and cast it to required type.

Template Parameters:

T – Type of return value. Only BandwidthWeight is allowed.

Returns:

Casted reference of SpatialWeight::mWeight.

inline const std::unique_ptr<Distance> &distance() const

Get the pointer to SpatialWeight::mDistance.

Returns:

Pointer to SpatialWeight::mDistance.

inline void setDistance(const Distance *distance)

Set the pointer to SpatialWeight::mDistance object.

Parameters:

distance – Pointer to Distance instance. Control of this pointer will be taken, and it will be deleted when destructing.

inline void setDistance(const Distance &distance)

Set the pointer to SpatialWeight::mDistance object.

Parameters:

distance – Reference to Distance instance. This object will be cloned.

inline void setDistance(Distance &&distance)

Set the pointer to SpatialWeight::mDistance object.

Parameters:

distance – Reference to Distance instance. This object will be cloned.

inline void setDistance(std::unique_ptr<Distance> &&distance)

Set the pointer to SpatialWeight::mDistance object.

Parameters:

distance – Right reference of unique pointer to Distance instance. This object will be cloned.

template<typename T>
inline T &distance() const

Get the pointer to SpatialWeight::mDistance and cast it to required type.

Template Parameters:

T – Type of return value. Only CRSDistance and MinkwoskiDistance is allowed.

Returns:

Casted pointer to SpatialWeight::mDistance.

SpatialWeight &operator=(const SpatialWeight &spatialWeight)

Override operator = for this class. This function will first delete the current SpatialWeight::mWeight and SpatialWeight::mDistance, and then clone Weight and Distance instances according pointers of the right value.

Parameters:

spatialWeight – Reference to the right value.

Returns:

Reference of this object.

SpatialWeight &operator=(SpatialWeight &&spatialWeight)

Override operator = for this class. This function will first delete the current SpatialWeight::mWeight and SpatialWeight::mDistance, and then clone Weight and Distance instances according pointers of the right value.

Parameters:

spatialWeight – Right value reference to the right value.

Returns:

Reference of this object.

inline virtual arma::vec weightVector(arma::uword focus) const

Calculate the spatial weight vector from focused sample to other samples (including the focused sample itself).

Parameters:

focus – Index of current sample.

Returns:

vec The spatial weight vector from focused sample to other samples.

virtual bool isValid()

Get whether this object is valid in geting weight vector.

Returns:

true if this object is valid.

Returns:

false if this object is invalid.

template<>
inline BandwidthWeight &weight() const

Get the pointer to SpatialWeight::mWeight and cast it to BandwidthWeight type.

Returns:

Casted pointer to SpatialWeight::mWeight.

template<>
inline CRSDistance &distance() const

Get the pointer to SpatialWeight::mDistance and cast it to CRSDistance type.

Returns:

Casted pointer to SpatialWeight::mDistance.

template<>
inline CRSSTDistance &distance() const

Get the pointer to SpatialWeight::mDistance and cast it to CRSSTDistance type.

Returns:

Casted pointer to SpatialWeight::mDistance.

template<>
inline MinkwoskiDistance &distance() const

Get the pointer to SpatialWeight::mDistance and cast it to MinkwoskiDistance type.

Returns:

Casted pointer to SpatialWeight::mDistance.

template<>
inline DMatDistance &distance() const

Get the pointer to SpatialWeight::mDistance and cast it to DMatDistance type.

Returns:

Casted pointer to SpatialWeight::mDistance.

template<>
inline OneDimDistance &distance() const

Get the pointer to SpatialWeight::mDistance and cast it to OneDimDistance type.

Returns:

Casted pointer to SpatialWeight::mDistance.