Commit 417e1bef96f8f60201e0fd84b645d8aac00579d6
1 parent
1b1ed7e2
small improvements
Showing
3 changed files
with
5 additions
and
7 deletions
Show diff stats
main.py
1 | -from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel, MarkovValue | 1 | +from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel |
2 | from random import random | 2 | from random import random |
3 | from math import floor | 3 | from math import floor |
4 | 4 |
structure.py
@@ -239,7 +239,7 @@ def KNeighbors(fingerprints, sample): | @@ -239,7 +239,7 @@ def KNeighbors(fingerprints, sample): | ||
239 | :param sample: Mobile terminal sample | 239 | :param sample: Mobile terminal sample |
240 | :return: the 4 nearest cells | 240 | :return: the 4 nearest cells |
241 | ''' | 241 | ''' |
242 | - distances, neighbours = [], [] | 242 | + distances = [] |
243 | for row in fingerprints: | 243 | for row in fingerprints: |
244 | for currentItem in row: | 244 | for currentItem in row: |
245 | dist = abs(currentItem.v.n1 - sample.n1) \ | 245 | dist = abs(currentItem.v.n1 - sample.n1) \ |
@@ -248,10 +248,8 @@ def KNeighbors(fingerprints, sample): | @@ -248,10 +248,8 @@ def KNeighbors(fingerprints, sample): | ||
248 | + abs(currentItem.v.n4 - sample.n4) | 248 | + abs(currentItem.v.n4 - sample.n4) |
249 | distances.append((dist, currentItem)) | 249 | distances.append((dist, currentItem)) |
250 | distances = sorted(distances, key=ig(0)) | 250 | distances = sorted(distances, key=ig(0)) |
251 | - for k in range (0,4): | ||
252 | - neighbours.append(distances[k][1]) | ||
253 | - sample.distances.append(distances[k][0]) | ||
254 | - return neighbours | 251 | + sample.distances = [x[0] for x in distances][:4] |
252 | + return [x[1] for x in distances][:4] | ||
255 | 253 | ||
256 | 254 | ||
257 | 255 |
test_structure.py