MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ProximityGraphs.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Dense>
4
5namespace MayaFlux::Kinesis {
6
17
18using EdgeList = std::vector<std::pair<size_t, size_t>>;
19
22 size_t k_neighbors { 3 };
23 double radius { 1.0 };
24 std::function<EdgeList(const Eigen::MatrixXd&)> custom_function;
25};
26
27/**
28 * @brief Compute sequential chain graph
29 * @param points Dx N matrix where each column is a point
30 * @return Edge list (point index pairs)
31 *
32 * Connects points in order: (0,1), (1,2), ..., (n-2, n-1).
33 * Undirected graph: each edge appears once.
34 *
35 * Complexity: O(n)
36 */
37EdgeList sequential_chain(const Eigen::MatrixXd& points);
38
39/**
40 * @brief Compute K-nearest neighbors graph
41 * @param points Dx N matrix where each column is a point
42 * @param k Number of nearest neighbors per point
43 * @return Edge list (point index pairs)
44 *
45 * For each point, connects it to its k nearest neighbors.
46 * Directed graph: point i connects to k neighbors, but neighbor j
47 * might not reciprocally connect to i.
48 *
49 * Complexity: O(n² log k) with partial sort
50 */
52 const Eigen::MatrixXd& points,
53 size_t k);
54
55/**
56 * @brief Compute radius threshold graph
57 * @param points Dx N matrix where each column is a point
58 * @param radius Maximum connection distance
59 * @return Edge list (point index pairs)
60 *
61 * Connects all point pairs within radius distance.
62 * Undirected graph: if (i,j) exists, edge appears once.
63 *
64 * Complexity: O(n²) brute force
65 */
67 const Eigen::MatrixXd& points,
68 double radius);
69
70/**
71 * @brief Compute minimum spanning tree (Prim's algorithm)
72 * @param points DxN matrix where each column is a point
73 * @return Edge list forming MST
74 *
75 * Returns exactly (n-1) edges forming tree of minimum total length
76 * that connects all points. Undirected acyclic graph.
77 *
78 * Complexity: O(n² log n) with priority queue
79 */
80EdgeList minimum_spanning_tree(const Eigen::MatrixXd& points);
81
82/**
83 * @brief Compute Gabriel graph
84 * @param points DxN matrix where each column is a point
85 * @return Edge list of Gabriel edges
86 *
87 * Gabriel property: Edge (p,q) exists iff disk with diameter pq
88 * contains no other points. Subset of Delaunay triangulation.
89 *
90 * The Gabriel graph is a proximity graph defined by the following rule:
91 * Two points p and q are connected if and only if the closed disk
92 * having the line segment pq as diameter contains no other points.
93 *
94 * Equivalently: |p-r|² + |q-r|² ≥ |p-q|² for all r ∈ P \ {p,q}
95 *
96 * Complexity: O(n³) with naive geometric tests
97 */
98EdgeList gabriel_graph(const Eigen::MatrixXd& points);
99
100/**
101 * @brief Compute nearest neighbor graph
102 * @param points DxN matrix where each column is a point
103 * @return Edge list of nearest neighbor edges
104 *
105 * Connects each point to its single nearest neighbor.
106 * Directed graph: point i connects to nearest neighbor j, but j may
107 * connect to a different point k.
108 *
109 * Complexity: O(n²) brute force
110 */
111EdgeList nearest_neighbor_graph(const Eigen::MatrixXd& points);
112
113/**
114 * @brief Compute relative neighborhood graph
115 * @param points DxN matrix where each column is a point
116 * @return Edge list of RNG edges
117 *
118 * RNG property: Edge (p,q) exists iff lune(p,q) contains no points.
119 * Lune is intersection of two circles centered at p and q, each
120 * with radius |p-q|.
121 *
122 * Equivalently: max(|p-r|, |q-r|) ≥ |p-q| for all r ∈ P \ {p,q}
123 *
124 * The RNG is a subset of Gabriel graph and Delaunay triangulation.
125 *
126 * Complexity: O(n³) with geometric tests
127 */
128EdgeList relative_neighborhood_graph(const Eigen::MatrixXd& points);
129
130/**
131 * @brief Custom proximity graph via user function
132 * @param points DxN matrix where each column is a point
133 * @param connection_function User-provided edge generator
134 * @return Edge list
135 *
136 * Allows arbitrary proximity rules defined by user.
137 */
139 const Eigen::MatrixXd& points,
140 const std::function<EdgeList(const Eigen::MatrixXd&)>& connection_function);
141
142/**
143 * @brief Generate proximity graph using specified mode
144 * @param points DxN matrix where each column is a point
145 * @param config Configuration specifying mode and parameters
146 * @return Edge list
147 */
149 const Eigen::MatrixXd& points,
150 const ProximityConfig& config);
151
152} // namespace MayaFlux::Kinesis
EdgeList minimum_spanning_tree(const Eigen::MatrixXd &points)
Compute minimum spanning tree (Prim's algorithm)
EdgeList nearest_neighbor_graph(const Eigen::MatrixXd &points)
Compute nearest neighbor graph.
EdgeList custom_proximity_graph(const Eigen::MatrixXd &points, const std::function< EdgeList(const Eigen::MatrixXd &)> &connection_function)
Custom proximity graph via user function.
EdgeList k_nearest_neighbors(const Eigen::MatrixXd &points, size_t k)
Compute K-nearest neighbors graph.
std::vector< std::pair< size_t, size_t > > EdgeList
EdgeList sequential_chain(const Eigen::MatrixXd &points)
Compute sequential chain graph.
EdgeList relative_neighborhood_graph(const Eigen::MatrixXd &points)
Compute relative neighborhood graph.
EdgeList generate_proximity_graph(const Eigen::MatrixXd &points, const ProximityConfig &config)
Generate proximity graph using specified mode.
EdgeList radius_threshold_graph(const Eigen::MatrixXd &points, double radius)
Compute radius threshold graph.
EdgeList gabriel_graph(const Eigen::MatrixXd &points)
Compute Gabriel graph.
std::function< EdgeList(const Eigen::MatrixXd &)> custom_function