PointSampler library (C++)
Loading...
Searching...
No Matches
hammersley.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
13template <typename T, size_t N>
14std::vector<Point<T, N>> hammersley_sequence(size_t count, size_t shift)
15{
16 auto van_der_corput = [](size_t n, size_t base) -> T
17 {
18 T q = 0;
19 T bk = 1.0 / base;
20 while (n > 0)
21 {
22 q += T(n % base) * bk;
23 n /= base;
24 bk /= base;
25 }
26 return q;
27 };
28
29 constexpr size_t primes[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
30 constexpr size_t n_primes = 15;
31
32 std::vector<Point<T, N>> points(count);
33 for (size_t i = 0; i < count; ++i)
34 {
35 points[i][0] = static_cast<T>(i) / static_cast<T>(count);
36 for (size_t d = 1; d < N; ++d)
37 points[i][d] = van_der_corput(i + shift, primes[std::min(n_primes - 1, d - 1)]);
38 }
39 return points;
40}
41
70template <typename T, size_t N>
71std::vector<Point<T, N>> hammersley(size_t count,
72 const std::array<std::pair<T, T>, N> &axis_ranges,
73 std::optional<unsigned int> seed = std::nullopt)
74{
75 // seed-like effect...
76 size_t shift = seed ? *seed : 0;
79 return points;
80}
81
82} // 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
void rescale_points(std::vector< Point< T, N > > &points, const std::array< std::pair< T, T >, N > &ranges)
Rescales normalized points (in [0, 1]) to specified axis-aligned ranges.
Definition range.hpp:207
std::vector< Point< T, N > > hammersley(size_t count, const std::array< std::pair< T, T >, N > &axis_ranges, std::optional< unsigned int > seed=std::nullopt)
Generates a set of quasi-random points using the Hammersley sequence in N dimensions.
Definition hammersley.hpp:71
std::vector< Point< T, N > > hammersley_sequence(size_t count, size_t shift)
Definition hammersley.hpp:14