.. _program_listing_file_include_gwmodelpp_spatialweight_BandwidthWeight.h: Program Listing for File BandwidthWeight.h ========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/gwmodelpp/spatialweight/BandwidthWeight.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef BANDWIDTHWEIGHT_H #define BANDWIDTHWEIGHT_H #include #include #include "Weight.h" namespace gwm { class BandwidthWeight : public Weight { public: enum KernelFunctionType { Gaussian, // Call for gaussian kernel BandwidthWeight::GaussianKernelFunction(). Exponential, // Call for exponential kernel BandwidthWeight::ExponentialKernelFunction(). Bisquare, // Call for bisquare kernel BandwidthWeight::BisquareKernelFunction(). Tricube, // Call for tricube kernel BandwidthWeight::TricubeKernelFunction(). Boxcar // Call for boxcar kernel BandwidthWeight::BoxcarKernelFunction(). }; static std::unordered_map KernelFunctionTypeNameMapper; static std::unordered_map BandwidthTypeNameMapper; typedef arma::vec (*KernelFunction)(arma::vec, double); static KernelFunction Kernel[]; static arma::vec GaussianKernelFunction(arma::vec dist, double bw) { return exp((dist % dist) / ((-2.0) * (bw * bw))); } static arma::vec ExponentialKernelFunction(arma::vec dist, double bw) { return exp(-dist / bw); } static arma::vec BisquareKernelFunction(arma::vec dist, double bw) { arma::vec d2_d_b2 = 1.0 - (dist % dist) / (bw * bw); return (dist < bw) % (d2_d_b2 % d2_d_b2); } static arma::vec TricubeKernelFunction(arma::vec dist, double bw) { arma::vec d3_d_b3 = 1.0 - (dist % dist % dist) / (bw * bw * bw); return (dist < bw) % (d3_d_b3 % d3_d_b3 % d3_d_b3); } static arma::vec BoxcarKernelFunction(arma::vec dist, double bw) { return (dist < bw) % arma::vec(arma::size(dist), arma::fill::ones); } public: BandwidthWeight() {} BandwidthWeight(double size, bool adaptive, KernelFunctionType kernel) { mBandwidth = size; mAdaptive = adaptive; mKernel = kernel; } BandwidthWeight(const BandwidthWeight& bandwidthWeight) { mBandwidth = bandwidthWeight.mBandwidth; mAdaptive = bandwidthWeight.mAdaptive; mKernel = bandwidthWeight.mKernel; } BandwidthWeight(const BandwidthWeight* bandwidthWeight) { mBandwidth = bandwidthWeight->bandwidth(); mAdaptive = bandwidthWeight->adaptive(); mKernel = bandwidthWeight->kernel(); } virtual Weight * clone() override { return new BandwidthWeight(*this); } public: virtual arma::vec weight(arma::vec dist) override; double bandwidth() const { return mBandwidth; } void setBandwidth(double bandwidth) { mBandwidth = bandwidth; } bool adaptive() const { return mAdaptive; } void setAdaptive(bool adaptive) { mAdaptive = adaptive; } KernelFunctionType kernel() const { return mKernel; } void setKernel(const KernelFunctionType &kernel) { mKernel = kernel; } private: double mBandwidth; bool mAdaptive; KernelFunctionType mKernel; }; } #endif // BANDWIDTHWEIGHT_H