Commit b05581a294d3764f81524811913faff08600a76d
1 parent
23328613
simplified function
Showing
2 changed files
with
9 additions
and
10 deletions
Show diff stats
main.py
@@ -39,7 +39,7 @@ def main(args): | @@ -39,7 +39,7 @@ def main(args): | ||
39 | print ("\ndistances : " + str(testSample.distances)) | 39 | print ("\ndistances : " + str(testSample.distances)) |
40 | 40 | ||
41 | #### Barycenter #### | 41 | #### Barycenter #### |
42 | - a = resolve_barycenter(neighborsCells, testSample) | 42 | + a = resolve_barycenter(neighborsCells, testSample.distances) |
43 | print(a.toString()) | 43 | print(a.toString()) |
44 | 44 | ||
45 | #### Markov #### | 45 | #### Markov #### |
structure.py
@@ -68,17 +68,16 @@ def KNeighbors(fingerprints, sample): | @@ -68,17 +68,16 @@ def KNeighbors(fingerprints, sample): | ||
68 | 68 | ||
69 | 69 | ||
70 | 70 | ||
71 | -def resolve_barycenter(neighbourCells, sample): | 71 | +def resolve_barycenter(nC, d): |
72 | ''' | 72 | ''' |
73 | Returns the weighted barycenter of the 4 neighbouring cells | 73 | Returns the weighted barycenter of the 4 neighbouring cells |
74 | - :param Cell[4] neighbourCells: Array containing the 4 closest cells | ||
75 | - :param RSSIVector sample: Sample of the mobile terminal | 74 | + :param Cell[4] nC: (neighborCells) Array containing the 4 closest cells |
75 | + :param distance[4] d: distances of the sample of the mobile terminal | ||
76 | :return Location: Estimated location of the mobile terminal (return None if error) | 76 | :return Location: Estimated location of the mobile terminal (return None if error) |
77 | ''' | 77 | ''' |
78 | - d = sample.distances #shorter notation | ||
79 | - a1,a2,a3,a4 = 1 / (1+d[0]/d[1]+d[0]/d[2]+d[0]/d[3]),\ | ||
80 | - 1 / (1+d[1]/d[0]+d[1]/d[2]+d[1]/d[3]),\ | ||
81 | - 1 / (1+d[2]/d[1]+d[2]/d[0]+d[2]/d[3]),\ | ||
82 | - 1 / (1+d[3]/d[1]+d[3]/d[2]+d[3]/d[0]) | ||
83 | - 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 | 78 | + return None if len(nC) != 4 else \ |
79 | + 1 / (1+d[0]/d[1]+d[0]/d[2]+d[0]/d[3])*nC[0].location \ | ||
80 | + + 1 / (1+d[1]/d[0]+d[1]/d[2]+d[1]/d[3])*nC[1].location \ | ||
81 | + + 1 / (1+d[2]/d[1]+d[2]/d[0]+d[2]/d[3])*nC[2].location \ | ||
82 | + + 1 / (1+d[3]/d[1]+d[3]/d[2]+d[3]/d[0])*nC[3].location | ||
84 | 83 | ||
85 | \ No newline at end of file | 84 | \ No newline at end of file |