src.KNN.validationKNN module

class src.KNN.validationKNN.ValidationKNN

Bases: PyQt5.QtCore.QObject

The Validation KNN microservice

Parameters

QObject (QObject) – So that we can use QT signal/slots

addTransformedPoints(request, context)

Add points from transformerService to buffer to validate later.

Parameters
  • request (gRPC) – standard gRPC (contains the messages).

  • request.vectors ([vector]) – contains protoKNN Vector object for each transformed point

  • context (gRPC) – standard gRPC

Returns

returns void

Return type

gRPC empty

calcAccuracy()

Calculates the accuracy of each nearest neighbours comparison.

Returns

float}: contains a amount of nearest neighbours as key and the corresponding accuracy as float (0-100%)

Return type

{int

clearPoints(request, context)

Clear transformed points buffer so all previously added points are removed.

Parameters
  • request (gRPC) – standard gRPC (contains the messages)

  • context (gRPC) – standard gRPC

Returns

returns void

Return type

gRPC empty

clearVariables()

Clear all the variables to default

compareKNNBatch(originalVectors, transformedVectors, nNeighbours)

Compares the nearest neighbours of a batch of vectors with their full dimensial value and transformed value.

Parameters
  • originalVectors ([[float]]) – List/array of full dimensional vectors

  • transformedVectors ([[float, float]]) – List/array of transformed vectors

  • nNeighbours (int) – Number of nearest neighbours that should be compared per vector (k in kNN).

Returns

Amount of correct nearest neighbours found with amount of total nearest neighbours. (None, None) on failure.

Return type

(int, int)

compareKNNs(originalVectors, transformedVectors)

Compares the kNNs of a batch of full dimensional vectors to transformed vectors. Compares for multiple k values.

Parameters
  • originalVectors ([[float]]) – List/array of full dimensional vectors

  • transformedVectors ([[float, float]]) – List/array of transformed vectors

Returns

if comparisons were succesful

Return type

bool

connectToOriginalKNN()

Connects to the kNN service to request the nearest neighbours of full dimensional vectors.

Returns

if connecting was succesful

Return type

bool

getAccuracy(request, context)

Gets the accuracy per nearest neighbour amount.

Parameters
  • request (gRPC) – standard gRPC (contains the messages)

  • context (gRPC) – standard gRPC

Returns

contains a list of nearest neighbours and a list with the corresponding accuracy per nearest neighbour

Return type

gRPC accuracyKNN

getOriginalNNBatch(vectors, nNeighbours)

Requests the kNN of a batch of full dimensional vectors from the kNN service.

Parameters
  • vectors ([[float]]) – List/array of full dimensional vectors

  • nNeighbours (int) – Number of nearest neighbours requested

Returns

Per vector a list of nearest neighbours. Shape = (len(vectors), nNeighbours)

Return type

np.array([[int]])

getProgress(request, context)

Implementation for the getProgress gRPC request

Parameters
  • request (gRPC) – standard gRPC (contains the messages)

  • context (gRPC) – standard gRPC

Returns

contains the integer of current progress

Return type

gRPC progressKNN

startKNNService(request, context)

Setup the KNN serive

Parameters
  • request (gRPC) – standard gRPC (contains the messages)

  • context (gRPC) – standard gRPC

Returns

returns void

Return type

gRPC empty

stopKNNService(request, context)

Stop the current service

Parameters
  • request (gRPC) – standard gRPC (contains the messages)

  • context (gRPC) – standard gRPC

Returns

returns void

Return type

gRPC empty

updateKNN()

Create a new kNN model on the transformed points.

Returns

Returns the transformed points used by the model.

This prevents the ValidationKNN from getting out of sync when more points are added during updateKNN.

Return type

[numpy.array([float, float])]

updatePercentage()

Recalculate the current percentage

validateProjection()

Calculate the accuracy of the transformed (projected) points compared to the original kNN with the full dimensions.

Returns

float}: contains a amount of nearest neighbours as key and the corresponding accuracy as float (0-100%)

Return type

{int

src.KNN.validationKNN.printMessage(message)

Print the coloured message so that we can see in the output which microservice printed it

Parameters

message (string) – The actual message

src.KNN.validationKNN.serveServer()

Setup the GRPC server