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#include <random>
7
10
11namespace ps
12{
13
42template <typename T, size_t N>
43std::vector<Point<T, N>> gaussian_clusters(
44 std::vector<Point<T, N>> cluster_centers,
45 size_t points_per_cluster,
46 T spread,
47 std::optional<unsigned int> seed = std::nullopt)
48{
49 std::mt19937 gen(seed ? *seed : std::random_device{}());
50
51 std::vector<Point<T, N>> points;
52 points.reserve(cluster_centers.size() * points_per_cluster);
53
54 for (size_t i = 0; i < cluster_centers.size(); ++i)
55 {
56 std::normal_distribution<T> dist(0, spread);
57 for (size_t j = 0; j < points_per_cluster; ++j)
58 {
60 for (size_t k = 0; k < N; ++k)
61 p[k] = cluster_centers[i][k] + dist(gen);
62 points.push_back(p);
63 }
64 }
65 return points;
66}
67
95template <typename T, size_t N>
96std::vector<Point<T, N>> gaussian_clusters(
97 size_t cluster_count,
98 size_t points_per_cluster,
99 const std::array<std::pair<T, T>, N> &axis_ranges,
100 T spread,
101 std::optional<unsigned int> seed = std::nullopt)
102{
103 std::vector<Point<T, N>> cluster_centers = random<T, N>(cluster_count,
105 seed);
106 std::vector<Point<T, N>> points = gaussian_clusters(cluster_centers,
108 spread,
109 seed);
110 return points;
111}
112
113} // 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:43
A fixed-size N-dimensional point/vector class.
Definition point.hpp:39