Modules
Functions
NPIR(points_, k, IR, i)
This is the implementation of the NPIR algorithm
Parameters
———-
points_ : str
The attribute values of all the points
k : int
Number of clusters
IR : float
The indexing ratio, 0 <= IR <= 1
i : int
Number of iterations, i > 0
Returns
——-
list
labelsPred: the predicted values of the points
Parameters
———-
points_ : str
The attribute values of all the points
k : int
Number of clusters
IR : float
The indexing ratio, 0 <= IR <= 1
i : int
Number of iterations, i > 0
Returns
——-
list
labelsPred: the predicted values of the points
addNearestToElectedCluster(electedIndex, nearestIndex, distance)
Assignment operation: changes the cluster of the Nearest to the cluster of the Elected.
The Nearest is not yet assigned
Parameters
———-
electedIndex : int
The index of the Elected
nearestIndex: int
The index of the Nearest
distance: float
The distance between the Elected and the Nearest
Returns
——-
N/A
The Nearest is not yet assigned
Parameters
———-
electedIndex : int
The index of the Elected
nearestIndex: int
The index of the Nearest
distance: float
The distance between the Elected and the Nearest
Returns
——-
N/A
addPointToCluster(clusterNo, pointIndex, assignerIndex, assignerDistance)
Adds a point to a cluster
Parameters
———-
clusterNo : int
The cluster where the point should be added
pointIndex : int
The index of the point to be added
assignerIndex: int
The index of the Assigner point for the point to be added
assignerDistance: float
The distance between the point and the Assigner
Returns
——-
N/A
Parameters
———-
clusterNo : int
The cluster where the point should be added
pointIndex : int
The index of the point to be added
assignerIndex: int
The index of the Assigner point for the point to be added
assignerDistance: float
The distance between the point and the Assigner
Returns
——-
N/A
arePointsInSameCluster(pointIndex1, pointIndex2)
Checks if two points are assigned to same cluster
Parameters
———-
pointIndex1 : int
The index of the first point to be checked
pointIndex2: int
The index of the second point to be checked
Returns
——-
bool
true/false indicating if the two points are assigned to same cluster
Parameters
———-
pointIndex1 : int
The index of the first point to be checked
pointIndex2: int
The index of the second point to be checked
Returns
——-
bool
true/false indicating if the two points are assigned to same cluster
calculate(i)
The main method
Assigns points to clusters until all points are assigned or maximum index value is reached
Parameters
———-
i : int
Number of iterations, i > 0
Returns
——-
N/A
changeAssigner(nearestIndex, electedIndex, nearestDist)Assigns points to clusters until all points are assigned or maximum index value is reached
Parameters
———-
i : int
Number of iterations, i > 0
Returns
——-
N/A
Checks if the Elected should be the Assigner for the Nearest and change it accordingly
Parameters
———-
nearestIndex : int
The index of the Nearest point
nearestDist: float
The distance between the Elected and the Nearest
electedIndex : int
The index of the Elected
Returns
——-
N/A
Parameters
———-
nearestIndex : int
The index of the Nearest point
nearestDist: float
The distance between the Elected and the Nearest
electedIndex : int
The index of the Elected
Returns
——-
N/A
createInitialPoints(k)
The main method
Assigns points to clusters until all points are assigned or maximum index value is reached
Parameters
———-
k : int
Number of clusters
Returns
——-
N/A
Assigns points to clusters until all points are assigned or maximum index value is reached
Parameters
———-
k : int
Number of clusters
Returns
——-
N/A
findNewPointForAnEmptyCluster()
Creates the initial point to a certain cluster
Parameters
———-
N/A
Returns
——-
int
The index of the initial random point
Parameters
———-
N/A
Returns
——-
int
The index of the initial random point
getNearestIndexAndDistance(pointIndex, pt, dvi)
Returns the index and distance of the Nearest point according to the distance vector index
Parameters
———-
pt : ndarray
The point that we need to fing its Nearest
dvi : int
The distance vectoor index
Returns
——-
int
The index of the Nearest point
float
The distance between the point and the Nearest point
Parameters
———-
pt : ndarray
The point that we need to fing its Nearest
dvi : int
The distance vectoor index
Returns
——-
int
The index of the Nearest point
float
The distance between the point and the Nearest point
getNearestPoint(electedIndex)
Selection operation: Selects the Nearest index and distance according to
the current index of the distance vector for the Elected
Parameters
———-
electedIndex : int
The index of the Elected
Returns
——-
int
The index of the Nearest
float
The distance between the Nearest and the Elected
the current index of the distance vector for the Elected
Parameters
———-
electedIndex : int
The index of the Elected
Returns
——-
int
The index of the Nearest
float
The distance between the Nearest and the Elected
getRandomAssignedPoint()
Election operation: selects a random point from the list of assigned points
Parameters
———-
N/A
Returns
——-
int
The index of the random Elected
Parameters
———-
N/A
Returns
——-
int
The index of the random Elected
init(k, IR)
Initializes the variables and data structures,
and creates the initial points and distance k-dimensional tree
Parameters
———-
IR : float
The indexing ratio, 0 <= IR <= 1
k : int
Number of clusters
Returns
——-
N/A
and creates the initial points and distance k-dimensional tree
Parameters
———-
IR : float
The indexing ratio, 0 <= IR <= 1
k : int
Number of clusters
Returns
——-
N/A
isPointInCluster(pointIndex)
Checks if point is already assigned to a cluster
Parameters
———-
pointIndex : int
The index of the point to be checked
assignerIndex: int
The index of the Assigner point for the point to be checked
Returns
——-
bool
true/false indicating if the point is already assigned to a cluster
Parameters
———-
pointIndex : int
The index of the point to be checked
assignerIndex: int
The index of the Assigner point for the point to be checked
Returns
——-
bool
true/false indicating if the point is already assigned to a cluster
moveNearestToElectedCluster(electedIndex, nearestIndex, distance)
Assignment operation: changes the cluster of the Nearest to the cluster of the Elected.
The Nearest is already assigned
Parameters
———-
electedIndex : int
The index of the Elected
nearestIndex: int
The index of the Nearest
distance: float
The distance between the Elected and the Nearest
Returns
——-
N/A
The Nearest is already assigned
Parameters
———-
electedIndex : int
The index of the Elected
nearestIndex: int
The index of the Nearest
distance: float
The distance between the Elected and the Nearest
Returns
——-
N/A
shouldPointMoveToNearerCluster(nearestIndex, nearestDist)
Checks if the Nearest should move to the cluster of the Elected
Parameters
———-
nearestIndex : int
The index of the Nearest point
nearestDist: float
The distance between the Elected and the Nearest
Returns
——-
bool
true/false if the Nearest should move to the cluster of the Elected
Parameters
———-
nearestIndex : int
The index of the Nearest point
nearestDist: float
The distance between the Elected and the Nearest
Returns
——-
bool
true/false if the Nearest should move to the cluster of the Elected
updateAssignmentsTree(pointIndex, assignerIndex)
Updates the assignment tree. The assignment tree contains the points that
are already assigned and their assigners and children in a tree data structure
Parameters
———-
pointIndex : int
The index of the point to be updated/added
assignerIndex: int
The index of the Assigner point for the point to be updated/added
Returns
——-
N/A
are already assigned and their assigners and children in a tree data structure
Parameters
———-
pointIndex : int
The index of the point to be updated/added
assignerIndex: int
The index of the Assigner point for the point to be updated/added
Returns
——-
N/A