split_and_merge
create_a_subgraph_copy Link
create_a_subgraph_copy(G, list_of_nodes=[])
Creates a subgraph as a copy based on the given list of nodes. This function preserves the attributes of the original graph and nodes. If the graph is a multigraph, it copies all edges and their attributes for the specified nodes; otherwise, it works with simple graphs.
Parameters:
-
G
(Graph or DiGraph or MultiGraph or MultiDiGraph
) –The original graph from which the subgraph is to be created. This can be any NetworkX graph instance.
-
list_of_nodes
(list
, default:[]
) –A list of nodes to be included in the subgraph. If not provided, an empty list will result in a subgraph with no nodes. Each node in this list must exist in the original graph.
Returns:
-
SG
(Graph or DiGraph or MultiGraph or MultiDiGraph
) –A deep copy of the subgraph containing only the nodes and edges specified by the
list_of_nodes
. The type of the resulting graph matches the type of the input graph.
Source code in spectral_clustering/split_and_merge.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
create_subgraphs_to_work Link
create_subgraphs_to_work(quotientgraph, list_quotient_node_to_work=[])
Creates subgraphs from the given quotient graph by focusing on specific nodes to work with. This function builds a Riemannian subgraph using the original graph stored in the given quotient graph, and includes the nodes mapped to specified quotient graph nodes.
Parameters:
-
quotientgraph
(Any
) –The quotient graph object that contains the point cloud graph.
-
list_quotient_node_to_work
(list
, default:[]
) –List of nodes in the quotient graph for which the corresponding nodes in the point cloud graph will be included in the subgraph. Defaults to an empty list.
Returns:
-
Graph
–The created subgraph that includes all the nodes from the original graph associated with the given list of quotient graph nodes.
Source code in spectral_clustering/split_and_merge.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
|
opti_energy_dot_product Link
opti_energy_dot_product(quotientgraph, subgraph_riemannian, angle_to_stop=30, export_iter=True, list_leaves=[])
Optimize graph energy by iteratively merging nodes based on dot product energy.
This function modifies the given quotient graph and its subgraph to iteratively optimize energy by merging nodes connected by edges with the lowest energy. The merging process involves updating node attributes and subgraph structures. Optionally, iteration results can be exported or visualized after each update.
Parameters:
-
quotientgraph
(Graph
) –The quotient graph on which optimization is performed. This is modified in place and used in conjunction with its associated point cloud graph.
-
subgraph_riemannian
(Graph
) –A subgraph of the quotient graph focusing on a particular region of the point cloud. This graph plays a key role in computing and organizing cluster information.
-
angle_to_stop
(float
, default:30
) –The angle (in degrees) that determines the stopping criterion for energy optimization. The default is 30 degrees. The energy to stop is computed as
1 - cos(angle_to_stop)
. -
export_iter
(bool
, default:True
) –Boolean flag to specify if intermediate results of the quotient graph optimization should be exported. The default is True.
-
list_leaves
(list
, default:[]
) –A list of node identifiers in the graph that are considered leaves. These nodes may affect energy calculations during optimization.
Source code in spectral_clustering/split_and_merge.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
opti_energy_dot_product_old Link
opti_energy_dot_product_old(quotientgraph, energy_to_stop=0.13, leaves_out=False, list_graph_node_to_work=[], export_iter=True)
Optimize the energy dot product in a graph by iteratively fusing nodes with higher energy edges, rebuilding the graph, and exporting the results. The method modifies the graph and performs operations like edge energy computation, label updates, and graph attribute exports.
Parameters:
-
quotientgraph
(object
) –A graph object representing the quotient graph. Assumes it has methods to compute direction info, rebuild the graph, and attributes related to the point cloud graph.
-
energy_to_stop
(float
, default:0.13
) –Threshold energy value to stop the optimization process. Default is 0.13.
-
leaves_out
(bool
, default:False
) –If True, treats the graph clusters excluding the leaf nodes during the optimization steps. Default is False.
-
list_graph_node_to_work
(list
, default:[]
) –A list of specific graph nodes from the point cloud to consider during the optimization process. If empty, the method will compute and process all edges with energy details in the graph. Default is an empty list.
-
export_iter
(bool
, default:True
) –If True, exports graph attributes and visualizations at every iteration of the optimization process. Default is True.
Notes
This function is designed for specialized usage with quotient graphs and associated point cloud graphs.
The graph manipulation includes operations like merging graph nodes associated by minimum energy,
updating attributes in the point cloud graph, and regenerating the quotient graph. The energy is
calculated between nodes or edges, directly impacting the choice of clusters or edges for merging.
Repeated iterations are performed until the minimum energy exceeds the specified energy_to_stop
value. Optionally, leaf nodes may be excluded during processing to focus on core clusters.
The function also relies on external calls, such as exporting attributes to a file and displaying the resulting quotient graphs using matplotlib. These external utilities must be implemented separately, and their proper functioning is assumed.
Source code in spectral_clustering/split_and_merge.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
oversegment_part Link
oversegment_part(quotientgraph, subgraph_riemannian, average_size_cluster=20)
Segments an input subgraph using clustering and updates the corresponding quotient graph.
This function performs oversegmentation of a given subgraph using the KMeans clustering algorithm. It determines a number of clusters based on the average cluster size provided. The resulting cluster labels are then integrated into the quotient graph to represent the updated segmentation.
Parameters:
-
quotientgraph
(object
) –The input quotient graph to be updated with new segmentation labels.
-
subgraph_riemannian
(Graph
) –The subgraph to be segmented, where each node must have a 'pos' attribute representing its spatial coordinates.
-
average_size_cluster
(int
, default:20
) –The target average number of nodes per cluster. Defaults to 20.
Notes
This function expects a Riemannian subgraph that includes spatial positions stored under the
'pos' node attribute. KMeans clustering is performed on these positions. The function also
assumes that the quotient graph has methods to update itself with new node labels. The
clustering process includes configuring KMeans to perform up to 20 runs (n_init=20
) and
allow 300 iterations per run with specified tolerance.
Source code in spectral_clustering/split_and_merge.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
|
oversegment_part_return_list Link
oversegment_part_return_list(quotientgraph, list_quotient_node_to_work=[], average_size_cluster=20)
Clusters points in a point cloud graph and updates the quotient graph nodes.
This function performs clustering on nodes within specified quotient graph nodes and updates their associated quotient graph labels based on the clustering results. The updated quotient graph integrates new labels for further processing.
Parameters:
-
quotientgraph
(object
) –The quotient graph, which contains the point cloud graph structure (
point_cloud_graph
) and nodes to be updated with new labels. -
list_quotient_node_to_work
(list
, default:[]
) –A list of quotient graph nodes to be processed. The nodes within these quotient graph nodes are clustered and updated. Default is an empty list.
-
average_size_cluster
(int
, default:20
) –The average number of points per cluster, used to determine the desired number of clusters during the clustering process. Default is 20.
Returns:
-
list
–A list of point cloud graph nodes (from the quotient graph node updates) that were processed and are available for subsequent operations.
Source code in spectral_clustering/split_and_merge.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
resegment_nodes_with_elbow_method Link
resegment_nodes_with_elbow_method(QG, QG_nodes_to_rework=[], number_of_cluster_tested=10, attribute='norm_gradient', number_attribute=1, standardization=False, numer=1, G_mod=True, export_div=False, ret=False)
Resegments the nodes of a given quotient graph using the elbow method to find the optimal number of clusters.
This function takes a quotient graph and a list of nodes to rework, applies the elbow method to resegment them into a more optimal clustering structure, and updates the graph accordingly. The function uses k-means clustering for segmentation and provides an option to standardize certain attributes prior to clustering.
Parameters:
-
QG
(any
) –The quotient graph on which the resegmentation will be performed.
-
QG_nodes_to_rework
(list
, default:[]
) –A list of quotient graph nodes to rework their clustering. Defaults to an empty list.
-
number_of_cluster_tested
(int
, default:10
) –The maximum number of clusters to test using the elbow method. Defaults to
10
. -
attribute
(str
, default:'norm_gradient'
) –The node attribute used for clustering. Defaults to
'norm_gradient'
. -
number_attribute
(int
, default:1
) –The dimensionality of the node attribute used for clustering. Defaults to
1
. -
standardization
(bool
, default:False
) –If True, the attributes used for clustering are standardized using StandardScaler. Defaults to
False
. -
numer
(int
, default:1
) –An offset added to the new cluster labels. Defaults to
1
. -
G_mod
(bool
, default:True
) –If True, modifies the original graph by updating the nodes with the new cluster labels. Defaults to
True
. -
export_div
(bool
, default:False
) –If True, exports the new clustered labels to text files. Defaults to
False
. -
ret
(bool
, default:False
) –If True, returns the cluster centers of the new segmentation. Defaults to
False
.
Returns:
-
(ndarray, optional)
–An array of the cluster centers, if
ret
is set to True and clustering is performed successfully.
Source code in spectral_clustering/split_and_merge.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
|
select_all_quotientgraph_nodes_from_pointcloudgraph_cluster Link
select_all_quotientgraph_nodes_from_pointcloudgraph_cluster(G, QG, labelpointcloudgraph, attribute='kmeans_labels')
Select all quotient graph nodes corresponding to a specific point cloud graph cluster.
This function identifies and selects the quotient graph nodes which correspond to a specific cluster in the point cloud graph. The selection is based on the provided clustering labels and a specified attribute.
Parameters:
-
G
(Graph
) –The original point cloud graph containing the clustering labels.
-
QG
(Graph
) –The quotient graph derived from the point cloud graph.
-
labelpointcloudgraph
(int
) –The label of the cluster in the point cloud graph to be matched.
-
attribute
(str
, default:'kmeans_labels'
) –The clustering attribute name used for matching, default is 'kmeans_labels'.
Returns:
-
list_leaves
(list
) –A list of quotient graph nodes associated with the specific cluster label.
Source code in spectral_clustering/split_and_merge.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
select_minimum_centroid_class Link
select_minimum_centroid_class(clusters_centers)
Selects the label of the cluster with the minimum centroid value.
This function identifies the cluster with the smallest centroid value from the provided array of cluster centroids and returns the corresponding cluster label.
Parameters:
-
clusters_centers
(ndarray
) –A 1D numpy array containing the centroid values of all clusters.
Returns:
-
int
–The label of the cluster with the smallest centroid value.
Source code in spectral_clustering/split_and_merge.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|