diff --git a/main.py b/main.py index cd0b0c6..b61bdc0 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,11 @@ -from structure import * +from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter import sys Tf = [] #cells table -testSample = RSSVector(-26, -42, -13, -46) -testSample2 = RSSVector(-26, -42, -13, -46) -testSample3 = RSSVector(-26, -42, -13, -46) - -testSamples = [] -testSamples.extend([testSample, testSample2, testSample3]) +testSamples = [RSSVector(-26, -42, -13, -46), RSSVector(-26, -42, -13, -46), RSSVector(-26, -42, -13, -46)] +testSample = testSamples[0] #cells Table initialization for i in range (0, 3): @@ -18,15 +14,15 @@ for i in range (0, 3): Tf[i].append([]) #known fingerprints -Tf[0][0] = Cell(RSSVector(-38,-27,-54,-13), Location(2,2)) -Tf[0][1] = Cell(RSSVector(-74,-62,-48,-33), Location(2,6)) -Tf[0][2] = Cell(RSSVector(-13,-28,-12,-40), Location(2,10)) -Tf[1][0] = Cell(RSSVector(-34,-27,-38,-41), Location(6,2)) -Tf[1][1] = Cell(RSSVector(-64,-48,-72,-35), Location(6,6)) -Tf[1][2] = Cell(RSSVector(-45,-37,-20,-15), Location(6,10)) -Tf[2][0] = Cell(RSSVector(-17,-50,-44,-33), Location(10,2)) -Tf[2][1] = Cell(RSSVector(-27,-28,-32,-45), Location(10,6)) -Tf[2][2] = Cell(RSSVector(-30,-20,-60,-40), Location(10,10)) +Tf[0][0] = newCell(-38,-27,-54,-13,2,2) +Tf[0][1] = newCell(-74,-62,-48,-33,2,6) +Tf[0][2] = newCell(-13,-28,-12,-40,2,10) +Tf[1][0] = newCell(-34,-27,-38,-41,6,2) +Tf[1][1] = newCell(-64,-48,-72,-35,6,6) +Tf[1][2] = newCell(-45,-37,-20,-15,6,10) +Tf[2][0] = newCell(-17,-50,-44,-33,10,2) +Tf[2][1] = newCell(-27,-28,-32,-45,10,6) +Tf[2][2] = newCell(-30,-20,-60,-40,10,10) def main(args): #### K neighbours #### @@ -44,5 +40,5 @@ def main(args): #### Markov #### - return 0; + return 0 main(sys.argv) \ No newline at end of file diff --git a/structure.py b/structure.py index f3d9756..3753507 100644 --- a/structure.py +++ b/structure.py @@ -44,6 +44,9 @@ class Cell(): self.Likeliness = .0 # Probability of Markov model self.pastCount = 1 +def newCell(n1, n2, n3, n4, l1, l2): + return Cell(RSSVector(n1,n2,n3,n4), Location(l1,l2)) + def KNeighbors(fingerprints, sample): ''' Returns the 4 closest cells to the given sample and fills sample distance data @@ -52,15 +55,15 @@ def KNeighbors(fingerprints, sample): :return Cell[4]: the 4 nearest cells ''' distances = [] + neighbours = [] for row in fingerprints: for currentItem in row: dist = abs(currentItem.v.n1 - sample.n1) \ - + abs(currentItem.v.n2 - sample.n2) \ - + abs(currentItem.v.n3 - sample.n3) \ - + abs(currentItem.v.n4 - sample.n4) + + abs(currentItem.v.n2 - sample.n2) \ + + abs(currentItem.v.n3 - sample.n3) \ + + abs(currentItem.v.n4 - sample.n4) distances.append((dist, currentItem)) - distances = sorted(distances, key=ig(0)) - neighbours = [] + distances = sorted(distances, key=ig(0)) for k in range (0,4): neighbours.append(distances[k][1]) sample.distances.append(distances[k][0]) -- libgit2 0.21.4