Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What't the the meaning of function accum_dist? #222

Open
chengfzy opened this issue Dec 8, 2023 · 0 comments
Open

What't the the meaning of function accum_dist? #222

chengfzy opened this issue Dec 8, 2023 · 0 comments

Comments

@chengfzy
Copy link

chengfzy commented Dec 8, 2023

I am build a KD tree with some constraint. For object it has timestamp t and a 3D position p, only the delta time less than some threshold, the distance could be valid, otherwise return the inf value. I modify the code based on example, the result index is found correct, but the return dist_sqr is not right. I found it's maybe the method of accum_dist(), but I don't know what's the parameters and affect of this function, could you be give some explain?

template <class DataSource>
class MyCustomMetric
{
   public:
    using ElementType  = double;
    using DistanceType = double;
    MyCustomMetric(
        const DataSource& dataList, const double& param, bool with_t = false)
        : data_(dataList), param_(param), with_t_(with_t)
    {
    }

   public:
    inline const DataSource& dataList() const { return data_; }

    inline double evalMetric(
        const double* a, const size_t b_idx, size_t dim_size) const
    {
        double result{0};
        if (with_t_)
        {
            if (abs(a[3] - data_.kdtree_get_pt(b_idx, 3)) > 4)
            {
                result = std::numeric_limits<double>::max();
            }
            else
            {
                for (size_t i = 0; i < dim_size - 1; ++i)
                {
                    double diff = a[i] - data_.kdtree_get_pt(b_idx, i);
                    result += std::pow(diff, param_);
                }
            }
        }
        else
        {
            for (size_t i = 0; i < dim_size; ++i)
            {
                double diff = a[i] - data_.kdtree_get_pt(b_idx, i);
                result += std::pow(diff, param_);
            }
        }
        return result;
    }

    template <typename U, typename V>
    inline double accum_dist(const U a, const V b, const size_t idx) const
    {
        return pow(a-b,param_);
    }

   private:
    const DataSource& data_;
    double            param_ = 2.0;
    bool              with_t_{false};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant