我正在使用WiFi进行室内定位项目,我想使用WKNN作为算法。我从GitHub找到了类似的项目。这是Algorithms类的一部分:
/**
* Calculates the Weighted Average of the K locations that have the shortest
* distances D
*
* @param LocDistance_Results_List
* Locations-Distances pairs sorted by distance
* @param K
* The number of locations used
* @return The estimated user location, or null for error
*/
private static String calculateWeightedAverageKDistanceLocations(ArrayList<LocDistance> LocDistance_Results_List, int K) {
double LocationWeight = 0.0f;
double sumWeights = 0.0f;
double WeightedSumX = 0.0f;
double WeightedSumY = 0.0f;
String[] LocationArray = new String[2];
float x, y;
int K_Min = K < LocDistance_Results_List.size() ? K : LocDistance_Results_List.size();
// Calculate the weighted sum of X and Y
for (int i = 0; i < K_Min; ++i) {
if (LocDistance_Results_List.get(i).getDistance() != 0.0) {
LocationWeight = 1 / LocDistance_Results_List.get(i).getDistance();
} else {
LocationWeight = 100;
}
LocationArray = LocDistance_Results_List.get(i).getLocation().split(" ");
try {
x = Float.valueOf(LocationArray[0].trim()).floatValue();
y = Float.valueOf(LocationArray[1].trim()).floatValue();
} catch (Exception e) {
return null;
}
sumWeights += LocationWeight;
WeightedSumX += LocationWeight * x;
WeightedSumY += LocationWeight * y;
}
WeightedSumX /= sumWeights;
WeightedSumY /= sumWeights;
return WeightedSumX + " " + WeightedSumY;
}
我的问题是,我们实际上可以从算法中找到x和y坐标吗?还是我必须做另一种方法,例如三边测量才能找到坐标?还是我可以使用任何好的文章或示例?