PointSampler library (C++)
Loading...
Searching...
No Matches
gaussian_clusters.hpp
Go to the documentation of this file.
1/* Copyright (c) 2025 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4#pragma once
5#include <optional>
6
9
10namespace ps
11{
12
41template <typename T, size_t N>
42std::vector<Point<T, N>> gaussian_clusters(
43 std::vector<Point<T, N>> cluster_centers,
44 size_t points_per_cluster,
45 T spread,
46 std::optional<unsigned int> seed = std::nullopt)
47{
48 std::mt19937 gen(seed ? *seed : std::random_device{}());
49
50 std::vector<Point<T, N>> points;
51 points.reserve(cluster_centers.size() * points_per_cluster);
52
53 for (size_t i = 0; i < cluster_centers.size(); ++i)
54 {
55 std::normal_distribution<T> dist(0, spread);
56 for (size_t j = 0; j < points_per_cluster; ++j)
57 {
59 for (size_t k = 0; k < N; ++k)
60 p[k] = cluster_centers[i][k] + dist(gen);
61 points.push_back(p);
62 }
63 }
64 return points;
65}
66
94template <typename T, size_t N>
95std::vector<Point<T, N>> gaussian_clusters(
96 size_t cluster_count,
97 size_t points_per_cluster,
98 const std::array<std::pair<T, T>, N> &axis_ranges,
99 T spread,
100 std::optional<unsigned int> seed = std::nullopt)
101{
102 std::vector<Point<T, N>> cluster_centers = random<T, N>(cluster_count,
104 seed);
105 std::vector<Point<T, N>> points = gaussian_clusters(cluster_centers,
107 spread,
108 seed);
109 return points;
110}
111
112} // namespace ps
Definition dbscan_clustering.hpp:11
std::vector< Point< T, N > > random(size_t count, const std::array< std::pair< T, T >, N > &axis_ranges, std::optional< unsigned int > seed=std::nullopt)
Generates a specified number of uniformly distributed random points in N-dimensional space.
Definition random.hpp:66
std::vector< Point< T, N > > gaussian_clusters(std::vector< Point< T, N > > cluster_centers, size_t points_per_cluster, T spread, std::optional< unsigned int > seed=std::nullopt)
Generates clustered points around provided cluster centers using a Gaussian distribution.
Definition gaussian_clusters.hpp:42
A fixed-size N-dimensional point/vector class.
Definition point.hpp:39