Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @brief Creates KDE function
- * @param bandwidth
- */
- KernelDensityEstimator::KernelDensityEstimator(double bandwidth) {
- params.append(bandwidth);
- kernel = NULL;
- }
- //---------------------------------------------------------------------------
- /**
- * @brief Evaluates function in x
- * @param x
- * @return y
- */
- double KernelDensityEstimator::evalPrivate(const Point1D &x) const {
- double h = getBandwidth();
- double f = 1.0 / (data.size() * h);
- double sum = 0;
- for (int i = 0; i < data.size(); i++) {
- sum += kernel->eval((x - data[i]) / h);
- }
- return f * sum;
- }
- //---------------------------------------------------------------------------
- void KernelDensityEstimator::setKernel(IFunction1D* kernel) {
- this->kernel = kernel;
- }
- //---------------------------------------------------------------------------
- void KernelDensityEstimator::setData(const Points1D &data) {
- this->data = data;
- }
- //---------------------------------------------------------------------------
- void KernelDensityEstimator::setBandwidth(double bandwidth) {
- this->params[0] = bandwidth;
- }
- //---------------------------------------------------------------------------
- double KernelDensityEstimator::getBandwidth() const {
- return params.at(0);
- }
- //---------------------------------------------------------------------------
- IFunction1D* KernelDensityEstimator::getKernel() const {
- return kernel;
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement