private Coordinate Positioning_Knn(List <AdjustedFingerprinting> fingerprintings) { /* run the knn classifier on the data */ KnnClassifier classifier = new KnnClassifier(); /* After fetching and processing the fingerprinting data, I am able to get the class count. * Basically, each of the reference point is a class to be classified to. */ int numClasses = IndoorPositioningClient.GetPoints(environment.EnvironmentId).Count; int gatewayCount = fingerprintings[0].RssiValueAndGateway.Count; /* get the Rssi values of the beacon in question from the server */ RssiValue[] rssiValues = IndoorPositioningClient.GetRssi(gatewayCount); /* we will use also gateway count on the area as K constant */ Coordinate coordinate = classifier.Classify(rssiValues, fingerprintings, numClasses, 3); return(coordinate); }
private Coordinate Positioning_KnnProximity(List <AdjustedFingerprinting> fingerprintings) { int k = 3; /* run the knn classifier on the data */ KnnClassifier classifier = new KnnClassifier(); /* After fetching and processing the fingerprinting data, I am able to get the class count. * Basically, each of the reference point is a class to be classified to. */ int numClasses = IndoorPositioningClient.GetPoints(environment.EnvironmentId).Count; int gatewayCount = fingerprintings[0].RssiValueAndGateway.Count; /* get the Rssi values of the beacon in question from the server */ RssiValue[] rssiValues = IndoorPositioningClient.GetRssi(gatewayCount); /* we will use also gateway count on the area as K constant */ CoordinateAndDistance[] cooDist = classifier.GetNearestNeighbors(rssiValues, fingerprintings, numClasses, k); Coordinate coordinateFirstAndSecondLine = new Coordinate(); Coordinate coordinateFirstAndThirdLine = new Coordinate(); Coordinate coordinateSecondAndThirdLine = new Coordinate(); /* Create a vector from the coordinates */ /* Measure the first point of crossing the first and second line*/ DoubleMatrix matrixFirstAndSecondLine = new DoubleMatrix(new double[, ] { { cooDist[0].coordinate.Xaxis - cooDist[1].coordinate.Xaxis, cooDist[0].coordinate.Yaxis - cooDist[1].coordinate.Yaxis }, { cooDist[0].coordinate.Xaxis - cooDist[2].coordinate.Xaxis, cooDist[0].coordinate.Yaxis - cooDist[2].coordinate.Yaxis } }); /* If the determinant value of the matrix is 0, it means this matrix cannot be inverted. * We can have the exact point values with one of the reference points. */ if (NMathFunctions.Determinant(matrixFirstAndSecondLine) == 0) { return(classifier.Vote(cooDist, fingerprintings, numClasses, k)); } //matrixFirstAndSecondLine = matrixFirstAndSecondLine.Transform((p) => p * 2); DoubleMatrix inversedMatrixFirstAndSecondLine = NMathFunctions.Inverse(matrixFirstAndSecondLine); DoubleVector vectorFirstAndSecondLine = new DoubleVector(new double[] { cooDist[0].coordinate.GetNormPow() - cooDist[1].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[1].GetDistPow(), cooDist[0].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[2].GetDistPow() }); vectorFirstAndSecondLine = vectorFirstAndSecondLine.Transform((p) => p / 2); DoubleVector coordinateVectorFirstAndSecondLine = NMathFunctions.Product(inversedMatrixFirstAndSecondLine, vectorFirstAndSecondLine); coordinateFirstAndSecondLine.Xaxis = (int)coordinateVectorFirstAndSecondLine[0]; coordinateFirstAndSecondLine.Yaxis = (int)coordinateVectorFirstAndSecondLine[1]; /* Measure the first point of crossing the first and third line*/ DoubleMatrix matrixFirstAndThirdLine = new DoubleMatrix(new double[, ] { { cooDist[0].coordinate.Xaxis - cooDist[1].coordinate.Xaxis, cooDist[0].coordinate.Yaxis - cooDist[1].coordinate.Yaxis }, { cooDist[1].coordinate.Xaxis - cooDist[2].coordinate.Xaxis, cooDist[1].coordinate.Yaxis - cooDist[2].coordinate.Yaxis } }); /* If the determinant value of the matrix is 0, it means this matrix cannot be inverted. * We can have the exact point values with one of the reference points. */ if (NMathFunctions.Determinant(matrixFirstAndThirdLine) == 0) { return(classifier.Vote(cooDist, fingerprintings, numClasses, k)); } //matrixFirstAndThirdLine = matrixFirstAndThirdLine.Transform((p) => p * 2); DoubleMatrix inversedMatrixFirstAndThirdLine = NMathFunctions.Inverse(matrixFirstAndThirdLine); DoubleVector vectorFirstAndThirdLine = new DoubleVector(new double[] { cooDist[0].coordinate.GetNormPow() - cooDist[1].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[1].GetDistPow(), cooDist[1].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[1].GetDistPow() + cooDist[2].GetDistPow() }); vectorFirstAndThirdLine = vectorFirstAndThirdLine.Transform((p) => p / 2); DoubleVector coordinateVectorFirstAndThirdLine = NMathFunctions.Product(inversedMatrixFirstAndThirdLine, vectorFirstAndThirdLine); coordinateFirstAndThirdLine.Xaxis = (int)coordinateVectorFirstAndThirdLine[0]; coordinateFirstAndThirdLine.Yaxis = (int)coordinateVectorFirstAndThirdLine[1]; /* Measure the first point of crossing the first and third line*/ DoubleMatrix matrixSecondAndThirdLine = new DoubleMatrix(new double[, ] { { cooDist[0].coordinate.Xaxis - cooDist[2].coordinate.Xaxis, cooDist[0].coordinate.Yaxis - cooDist[2].coordinate.Yaxis }, { cooDist[1].coordinate.Xaxis - cooDist[2].coordinate.Xaxis, cooDist[1].coordinate.Yaxis - cooDist[2].coordinate.Yaxis } }); /* If the determinant value of the matrix is 0, it means this matrix cannot be inverted. * We can have the exact point values with one of the reference points. */ if (NMathFunctions.Determinant(matrixSecondAndThirdLine) == 0) { return(classifier.Vote(cooDist, fingerprintings, numClasses, k)); } //matrixSecondAndThirdLine = matrixSecondAndThirdLine.Transform((p) => p * 2); DoubleMatrix inversedMatrixSecondAndThirdLine = NMathFunctions.Inverse(matrixSecondAndThirdLine); DoubleVector vectorSecondAndThirdLine = new DoubleVector(new double[] { cooDist[0].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[2].GetDistPow(), cooDist[1].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[1].GetDistPow() + cooDist[2].GetDistPow() }); vectorSecondAndThirdLine = vectorSecondAndThirdLine.Transform((p) => p / 2); DoubleVector coordinateVectorSecondAndThirdLine = NMathFunctions.Product(inversedMatrixSecondAndThirdLine, vectorSecondAndThirdLine); coordinateSecondAndThirdLine.Xaxis = (int)coordinateVectorSecondAndThirdLine[0]; coordinateSecondAndThirdLine.Yaxis = (int)coordinateVectorSecondAndThirdLine[1]; //DoubleMatrix matrixFirstAndThirdLine = new DoubleMatrix(new double[,] //{ // { // cooDist[0].coordinate.Xaxis - cooDist[1].coordinate.Xaxis, // cooDist[0].coordinate.Yaxis - cooDist[1].coordinate.Yaxis // }, // { // cooDist[0].coordinate.Xaxis - cooDist[2].coordinate.Xaxis, // cooDist[0].coordinate.Yaxis - cooDist[2].coordinate.Yaxis // }, // { // cooDist[1].coordinate.Xaxis - cooDist[2].coordinate.Xaxis, // cooDist[1].coordinate.Yaxis - cooDist[2].coordinate.Yaxis // } //}); //DoubleMatrix inversedMatrix = NMathFunctions.Inverse(matrix); //DoubleVector vector = new DoubleVector(new double[] //{ // cooDist[0].coordinate.GetNormPow() - cooDist[1].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[1].GetDistPow(), // cooDist[0].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[0].GetDistPow() + cooDist[2].GetDistPow(), // cooDist[1].coordinate.GetNormPow() - cooDist[2].coordinate.GetNormPow() - cooDist[1].GetDistPow() + cooDist[2].GetDistPow() //}); //DoubleVector coordinateVector = NMathFunctions.Product(inversedMatrix, vector); //coordinate.Xaxis = (int)coordinateVector[0]; //coordinate.Xaxis = (int)coordinateVector[1]; //Matrix linesMatrix = new Matrix( // cooDist[0].coordinate.Xaxis - cooDist[1].coordinate.Xaxis, // cooDist[0].coordinate.Yaxis - cooDist[1].coordinate.Yaxis, // cooDist[0].coordinate.Xaxis - cooDist[2].coordinate.Xaxis, // cooDist[0].coordinate.Yaxis - cooDist[2].coordinate.Yaxis, // cooDist[1].coordinate.Xaxis - cooDist[2].coordinate.Xaxis, // cooDist[1].coordinate.Yaxis - cooDist[2].coordinate.Yaxis); ////Vector distances = new Vector( //// coordinateAndDistances[0].coordinate.Xaxis - coordinateAndDistances[1].coordinate.Xaxis,); int xaxis = (coordinateFirstAndSecondLine.Xaxis + coordinateFirstAndThirdLine.Xaxis + coordinateSecondAndThirdLine.Xaxis) / 3; int yaxis = (coordinateFirstAndSecondLine.Yaxis + coordinateFirstAndThirdLine.Yaxis + coordinateSecondAndThirdLine.Yaxis) / 3; Debug.WriteLine("Xaxis:" + xaxis); Debug.WriteLine("Yaxis:" + yaxis); return(new Coordinate() { Xaxis = xaxis, Yaxis = yaxis }); }