diff --git a/main.py b/main.py index 89c79ea..accae22 100644 --- a/main.py +++ b/main.py @@ -3,8 +3,13 @@ from structure import * 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]) #cells Table initialization for i in range (0, 3): @@ -12,6 +17,7 @@ for i in range (0, 3): for k 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)) @@ -23,24 +29,20 @@ Tf[2][1] = Cell(RSSVector(-27,-28,-32,-45), Location(10,6)) Tf[2][2] = Cell(RSSVector(-30,-20,-60,-40), Location(10,10)) def main(args): - - print(Tf[1][1].v.n2) - - + #### K neighbours #### print("\nk neighbors of test sample : ") neighborsCells = KNeighbors(Tf, testSample) for k in neighborsCells: print("(", k.location.x, ";", k.location.y, ")") + #### Distances #### print ("\ndistances : " + str(testSample.distances)) - testLoc = Location(3,4,5) - loc2 = Location(1,2,3) - print((testLoc+loc2).toString()) - + #### Barycenter #### a = resolve_barycenter(neighborsCells, testSample) - print(a.toString) - return 0; + print(a.toString()) + #### Markov #### + return 0; main(sys.argv) \ No newline at end of file diff --git a/structure.py b/structure.py index 5c6aba1..81296e9 100644 --- a/structure.py +++ b/structure.py @@ -1,4 +1,4 @@ -from operator import itemgetter +from operator import itemgetter as ig class RSSVector(): distances = [] @@ -41,7 +41,8 @@ class Cell(): def __init__(self, v_, loc): self.v = v_ self.location = loc - + self.Likeliness = .0 # Probability of Markov model + self.pastCount = 1 def KNeighbors(fingerprints, sample): ''' @@ -58,7 +59,7 @@ def KNeighbors(fingerprints, sample): + abs(currentItem.v.n3 - sample.n3) \ + abs(currentItem.v.n4 - sample.n4) distances.append((dist, currentItem)) - distances = sorted(distances, key=itemgetter(0)) + distances = sorted(distances, key=ig(0)) neighbours = [] for k in range (0,4): neighbours.append(distances[k][1]) @@ -72,9 +73,12 @@ def resolve_barycenter(neighbourCells, sample): Returns the weighted barycenter of the 4 neighbouring cells :param Cell[4] neighbourCells: Array containing the 4 closest cells :param RSSIVector sample: Sample of the mobile terminal - :return Location: Estimated location of the mobile terminal + :return Location: Estimated location of the mobile terminal (return None if error) ''' d = sample.distances #shorter notation - a1,a2,a3,a4 = 1 / (1+d[0]/d[1]+d[0]/d[2]+d[0]/d[3]), 1 / (1+d[1]/d[0]+d[1]/d[2]+d[1]/d[3]), 1 / (1+d[2]/d[1]+d[2]/d[0]+d[2]/d[3]), 1 / (1+d[3]/d[1]+d[3]/d[2]+d[3]/d[0]) - return a1*neighbourCells[0].location + a2*neighbourCells[1].location + a3*neighbourCells[1].location + a4*neighbourCells[1].location + a1,a2,a3,a4 = 1 / (1+d[0]/d[1]+d[0]/d[2]+d[0]/d[3]),\ + 1 / (1+d[1]/d[0]+d[1]/d[2]+d[1]/d[3]),\ + 1 / (1+d[2]/d[1]+d[2]/d[0]+d[2]/d[3]),\ + 1 / (1+d[3]/d[1]+d[3]/d[2]+d[3]/d[0]) + return None if a1+a2+a3+a4 != 1.0 else a1*neighbourCells[0].location + a2*neighbourCells[1].location + a3*neighbourCells[2].location + a4*neighbourCells[3].location \ No newline at end of file -- libgit2 0.21.4