SNN2.src.model.layers.tf_cure.tree module

tree module

This module is used to manage a rtree easily, masking the complexity of introducing tensors in the tree structure.

class SNN2.src.model.layers.tf_cure.tree.tf_rtree(*args, **kwargs)

Bases: object

tf_rtree.

Class to manage a rtree with tensors

add_cluster(c_id: int, reps: Tensor) None

add_cluster.

Insert a cluster in the rtree

Parameters:
  • c_id (int) – The id of the cluster

  • reps (tf.Tensor) – The representation of the cluster

add_clusters(ids: Tensor, reps: RaggedTensor) None

add_clusters.

Insert all the clusters in the rtree

Parameters:
  • ids (tf.Tensor) – The ids of the clusters

  • reps (tf.RaggedTensor) – The representations of the clusters

nearest(rep: Tensor, n: int = 1) Tensor

nearest.

Get the nearest n clusters to the representation rep

Parameters:
  • rep (tf.Tensor) – The representation of the cluster

  • n (int) – The number of clusters to return

  • **kwargs (Any) – kwargs to pass to the nearest method

Returns:

Tensor with 2 dimensions, for each rep n closest clusters are piked shape (n_rep, n)

Return type:

tf.Tensor

remove_cluster(c_id: int, reps: Tensor) None

remove_cluster.

Remove a cluster from the rtree

Parameters:

c_id (int) – The id of the cluster to remove

property tree: Index

tree.

Returns:

The current tree

Return type:

index.Index