https://github.com/podgorskiy/kmeans
Simple, one header drop in templated library from kmeans
https://github.com/podgorskiy/kmeans
Last synced: 8 months ago
JSON representation
Simple, one header drop in templated library from kmeans
- Host: GitHub
- URL: https://github.com/podgorskiy/kmeans
- Owner: podgorskiy
- Created: 2020-11-29T02:59:21.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-29T03:17:46.000Z (almost 5 years ago)
- Last Synced: 2025-01-11T05:21:44.895Z (10 months ago)
- Language: C++
- Size: 48.8 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# kmeans
Simple, one-header, drop-in, templated library for kmeans


Works out of the box with scalars and vector types from OpenCV and GLM, such as glm::vec2, glm::vec3, cv::Vec3b, etc (Euclidean metric is assumed).
For everything else, provide specialization of:
```cpp
namespace kmeans
{
// Provide your own specialization for your data type
// Already have default ones for scalars and vector types as in cv::Vec<> and glm::vec_t<>
template
class DataTypeImpl
{
public:
typedef float DistanceType;
static T GenerateRandomSample(const std::pair& bounds);
static std::pair GetBounds(const T* first, const T* end);
static DistanceType ComputeDistance(const T& a, const T& b);
static T ComputeMean(const T* first, const T* end);
};
}
```
Where you need to
* specify `DistanceType` (typically float)
* specify function for random sampling `GenerateRandomSample`, given the bounds
* specify function for computing bounds `GetBounds`, given the sample list
* specify function for computing distance `ComputeDistance`, given the two samples which can be non euclidean to.
* specify function for computing mean of given sample list `ComputeMean`.