Program Listing for File MinkwoskiDistance.h

Return to documentation for file (include/gwmodelpp/spatialweight/MinkwoskiDistance.h)

#ifndef MINKWOSKIDISTANCE_H
#define MINKWOSKIDISTANCE_H

#include "CRSDistance.h"

namespace gwm
{

class MinkwoskiDistance : public CRSDistance
{
public:

    static arma::mat CoordinateRotate(const arma::mat& coords, double theta);

    static arma::vec ChessDistance(const arma::rowvec& out_loc, const arma::mat& in_locs);

    static arma::vec ManhattonDist(const arma::rowvec& out_loc, const arma::mat& in_locs);

    static arma::vec MinkwoskiDist(const arma::rowvec& out_loc, const arma::mat& in_locs, double p);

public:

    MinkwoskiDistance() : mPoly(2.0), mTheta(0.0) {}

    MinkwoskiDistance(double p, double theta);

    MinkwoskiDistance(const MinkwoskiDistance& distance);

    virtual Distance * clone() const override
    {
        return new MinkwoskiDistance(*this);
    }

    DistanceType type() override { return DistanceType::MinkwoskiDistance; }

    double poly() const;

    void setPoly(double poly);

    double theta() const;

    void setTheta(double theta);

public:
    virtual arma::vec distance(arma::uword focus) override;

private:
    double mPoly = 2.0;
    double mTheta = 0.0;
};

inline arma::vec MinkwoskiDistance::ChessDistance(const arma::rowvec& out_loc, const arma::mat& in_locs)
{
    return max(abs(in_locs.each_row() - out_loc), 1);
}

inline arma::vec MinkwoskiDistance::ManhattonDist(const arma::rowvec& out_loc, const arma::mat& in_locs)
{
    return sum(abs(in_locs.each_row() - out_loc), 1);
}

inline arma::vec MinkwoskiDistance::MinkwoskiDist(const arma::rowvec& out_loc, const arma::mat& in_locs, double p)
{
    arma::vec temp = abs(in_locs.each_row() - out_loc);
    return pow(sum(pow(temp, p), 1), 1.0 / p);
}

inline double MinkwoskiDistance::poly() const
{
    return mPoly;
}

inline void MinkwoskiDistance::setPoly(double poly)
{
    mPoly = poly;
}

inline double MinkwoskiDistance::theta() const
{
    return mTheta;
}

inline void MinkwoskiDistance::setTheta(double theta)
{
    mTheta = theta;
}

}

#endif // MINKWOSKIDISTANCE_H