Commit 2def30adb804d0f642b0adea5e6bce675a7a0307

Authored by Anthex
1 parent b05581a2

minor fixes/changes

Showing 2 changed files with 21 additions and 22 deletions   Show diff stats
1 1
2 -from structure import * 2 +from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter
3 import sys 3 import sys
4 4
5 Tf = [] #cells table 5 Tf = [] #cells table
6 6
7 -testSample = RSSVector(-26, -42, -13, -46)  
8 -testSample2 = RSSVector(-26, -42, -13, -46)  
9 -testSample3 = RSSVector(-26, -42, -13, -46)  
10 -  
11 -testSamples = []  
12 -testSamples.extend([testSample, testSample2, testSample3]) 7 +testSamples = [RSSVector(-26, -42, -13, -46), RSSVector(-26, -42, -13, -46), RSSVector(-26, -42, -13, -46)]
  8 +testSample = testSamples[0]
13 9
14 #cells Table initialization 10 #cells Table initialization
15 for i in range (0, 3): 11 for i in range (0, 3):
@@ -18,15 +14,15 @@ for i in range (0, 3): @@ -18,15 +14,15 @@ for i in range (0, 3):
18 Tf[i].append([]) 14 Tf[i].append([])
19 15
20 #known fingerprints 16 #known fingerprints
21 -Tf[0][0] = Cell(RSSVector(-38,-27,-54,-13), Location(2,2))  
22 -Tf[0][1] = Cell(RSSVector(-74,-62,-48,-33), Location(2,6))  
23 -Tf[0][2] = Cell(RSSVector(-13,-28,-12,-40), Location(2,10))  
24 -Tf[1][0] = Cell(RSSVector(-34,-27,-38,-41), Location(6,2))  
25 -Tf[1][1] = Cell(RSSVector(-64,-48,-72,-35), Location(6,6))  
26 -Tf[1][2] = Cell(RSSVector(-45,-37,-20,-15), Location(6,10))  
27 -Tf[2][0] = Cell(RSSVector(-17,-50,-44,-33), Location(10,2))  
28 -Tf[2][1] = Cell(RSSVector(-27,-28,-32,-45), Location(10,6))  
29 -Tf[2][2] = Cell(RSSVector(-30,-20,-60,-40), Location(10,10)) 17 +Tf[0][0] = newCell(-38,-27,-54,-13,2,2)
  18 +Tf[0][1] = newCell(-74,-62,-48,-33,2,6)
  19 +Tf[0][2] = newCell(-13,-28,-12,-40,2,10)
  20 +Tf[1][0] = newCell(-34,-27,-38,-41,6,2)
  21 +Tf[1][1] = newCell(-64,-48,-72,-35,6,6)
  22 +Tf[1][2] = newCell(-45,-37,-20,-15,6,10)
  23 +Tf[2][0] = newCell(-17,-50,-44,-33,10,2)
  24 +Tf[2][1] = newCell(-27,-28,-32,-45,10,6)
  25 +Tf[2][2] = newCell(-30,-20,-60,-40,10,10)
30 26
31 def main(args): 27 def main(args):
32 #### K neighbours #### 28 #### K neighbours ####
@@ -44,5 +40,5 @@ def main(args): @@ -44,5 +40,5 @@ def main(args):
44 40
45 #### Markov #### 41 #### Markov ####
46 42
47 - return 0; 43 + return 0
48 main(sys.argv) 44 main(sys.argv)
49 \ No newline at end of file 45 \ No newline at end of file
@@ -44,6 +44,9 @@ class Cell(): @@ -44,6 +44,9 @@ class Cell():
44 self.Likeliness = .0 # Probability of Markov model 44 self.Likeliness = .0 # Probability of Markov model
45 self.pastCount = 1 45 self.pastCount = 1
46 46
  47 +def newCell(n1, n2, n3, n4, l1, l2):
  48 + return Cell(RSSVector(n1,n2,n3,n4), Location(l1,l2))
  49 +
47 def KNeighbors(fingerprints, sample): 50 def KNeighbors(fingerprints, sample):
48 ''' 51 '''
49 Returns the 4 closest cells to the given sample and fills sample distance data 52 Returns the 4 closest cells to the given sample and fills sample distance data
@@ -52,15 +55,15 @@ def KNeighbors(fingerprints, sample): @@ -52,15 +55,15 @@ def KNeighbors(fingerprints, sample):
52 :return Cell[4]: the 4 nearest cells 55 :return Cell[4]: the 4 nearest cells
53 ''' 56 '''
54 distances = [] 57 distances = []
  58 + neighbours = []
55 for row in fingerprints: 59 for row in fingerprints:
56 for currentItem in row: 60 for currentItem in row:
57 dist = abs(currentItem.v.n1 - sample.n1) \ 61 dist = abs(currentItem.v.n1 - sample.n1) \
58 - + abs(currentItem.v.n2 - sample.n2) \  
59 - + abs(currentItem.v.n3 - sample.n3) \  
60 - + abs(currentItem.v.n4 - sample.n4) 62 + + abs(currentItem.v.n2 - sample.n2) \
  63 + + abs(currentItem.v.n3 - sample.n3) \
  64 + + abs(currentItem.v.n4 - sample.n4)
61 distances.append((dist, currentItem)) 65 distances.append((dist, currentItem))
62 - distances = sorted(distances, key=ig(0))  
63 - neighbours = [] 66 + distances = sorted(distances, key=ig(0))
64 for k in range (0,4): 67 for k in range (0,4):
65 neighbours.append(distances[k][1]) 68 neighbours.append(distances[k][1])
66 sample.distances.append(distances[k][0]) 69 sample.distances.append(distances[k][0])