opfython.subgraphs¶
As each type of OPF classifier might need a particular subgraph, we opted to define a unique package to hold them all. The subgraph’s package is in charge of implementing some of its varities, such as the k-nearest neighbour (KNN) subgraph.
A subgraphs package for all common opfython modules.
- class opfython.subgraphs.KNNSubgraph(X: Optional[numpy.array] = None, Y: Optional[numpy.array] = None, I: Optional[numpy.array] = None, from_file: Optional[bool] = None)¶
Bases:
opfython.core.Subgraph
A KNNSubgraph is used to implement a k-nearest neightbours subgraph.
- __init__(self, X: Optional[numpy.array] = None, Y: Optional[numpy.array] = None, I: Optional[numpy.array] = None, from_file: Optional[bool] = None)¶
Initialization method.
- Parameters
X – Array of features.
Y – Array of labels.
I – Array of indexes.
from_file – Whether Subgraph should be directly created from a file.
- property best_k(self)¶
int: Number of adjacent nodes (k-nearest neighbours).
- calculate_pdf(self, n_neighbours: int, distance_function: callable, pre_computed_distance: Optional[bool] = False, pre_distances: Optional[numpy.array] = None)¶
Calculates the probability density function for k neighbours.
- Parameters
n_neighbours – Number of neighbours in the adjacency relation.
distance_function – The distance function to be used to calculate the arcs.
pre_computed_distance – Whether OPF should use a pre-computed distance or not.
pre_distances – Pre-computed distance matrix.
- property constant(self)¶
float: Constant used to calculate the probability density function.
- create_arcs(self, k: int, distance_function: callable, pre_computed_distance: Optional[bool] = False, pre_distances: Optional[numpy.array] = None)¶
Creates arcs for each node (adjacency relation).
- Parameters
k – Number of neighbours in the adjacency relation.
distance_function – The distance function to be used to calculate the arcs.
pre_computed_distance – Whether OPF should use a pre-computed distance or not.
pre_distances – Pre-computed distance matrix.
- Returns
The maximum possible distances for each value of k.
- Return type
(np.array)
- property density(self)¶
float: Density of the subgraph.
- eliminate_maxima_height(self, height: float)¶
Eliminates maxima values in the subgraph that are below the inputted height.
- Parameters
height – Height’s threshold.
- property max_density(self)¶
float: Maximum density of the subgraph.
- property min_density(self)¶
float: Minimum density of the subgraph.
- property n_clusters(self)¶
int: Number of assigned clusters.