engine: add disp flag
This commit is contained in:
parent
be46d2e059
commit
2e83c934e9
1 changed files with 5 additions and 5 deletions
10
engine.py
10
engine.py
|
|
@ -96,13 +96,13 @@ def trilat_error(stations: list[StationT], position: tuple[float, float]) -> flo
|
||||||
return sum(sq_errors) / len(sq_errors)
|
return sum(sq_errors) / len(sq_errors)
|
||||||
|
|
||||||
|
|
||||||
def trilaterate(stations: list[StationT]) -> tuple[float, float]:
|
def trilaterate(stations: list[StationT], disp: bool = False) -> tuple[float, float]:
|
||||||
"""Trilaterate a position, given a list of stations.
|
"""Trilaterate a position, given a list of stations.
|
||||||
|
|
||||||
Each station is of the format ((lat, lon), distance).
|
Each station is of the format ((lat, lon), distance).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return scipy.optimize.fmin(lambda pos: trilat_error(stations, pos), (0., 0.))
|
return scipy.optimize.fmin(lambda pos: trilat_error(stations, pos), (0., 0.), disp=disp)
|
||||||
|
|
||||||
|
|
||||||
def encode(location: tuple[float, float]) -> EncodedLocation:
|
def encode(location: tuple[float, float]) -> EncodedLocation:
|
||||||
|
|
@ -131,7 +131,7 @@ def encode(location: tuple[float, float]) -> EncodedLocation:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def decode(location: EncodedLocation) -> tuple[float, float]:
|
def decode(location: EncodedLocation, disp: bool = False) -> tuple[float, float]:
|
||||||
"""Decode into a location."""
|
"""Decode into a location."""
|
||||||
|
|
||||||
# form the distances matrix
|
# form the distances matrix
|
||||||
|
|
@ -161,7 +161,7 @@ def decode(location: EncodedLocation) -> tuple[float, float]:
|
||||||
|
|
||||||
# part 2: trilaterate
|
# part 2: trilaterate
|
||||||
stations: list[StationT] = [(greggs_raw[g], location[i][0]) for i, g in enumerate(closest_greggs)]
|
stations: list[StationT] = [(greggs_raw[g], location[i][0]) for i, g in enumerate(closest_greggs)]
|
||||||
return trilaterate(stations)
|
return trilaterate(stations, disp=disp)
|
||||||
|
|
||||||
|
|
||||||
def format_dist(dist: float) -> str:
|
def format_dist(dist: float) -> str:
|
||||||
|
|
@ -199,7 +199,7 @@ def main():
|
||||||
parsed = parse_location(formatted)
|
parsed = parse_location(formatted)
|
||||||
print("Parsed:", parsed, end="\n\n")
|
print("Parsed:", parsed, end="\n\n")
|
||||||
|
|
||||||
decoded = decode(encoded)
|
decoded = decode(encoded, disp=True)
|
||||||
print("Decoded:", decoded, end="\n\n")
|
print("Decoded:", decoded, end="\n\n")
|
||||||
|
|
||||||
error = spherical_dist(np.array(coords), np.array(decoded))
|
error = spherical_dist(np.array(coords), np.array(decoded))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue