Merge branch 'main' into website
This commit is contained in:
commit
8c44ac56e6
2 changed files with 26 additions and 15 deletions
34
engine.py
34
engine.py
|
|
@ -6,7 +6,7 @@ import overpy
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import scipy
|
import scipy
|
||||||
# import random
|
import random
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
@ -19,12 +19,12 @@ BRANDS: dict[str, str] = {
|
||||||
CACHE_FOLDER = Path(".cache")
|
CACHE_FOLDER = Path(".cache")
|
||||||
|
|
||||||
LOCS_COUNT = 5
|
LOCS_COUNT = 5
|
||||||
DISTS_COUNT = 5
|
DISTS_COUNT = 2
|
||||||
|
|
||||||
FORMAT_FACTOR = 1e6 # μm
|
FORMAT_FACTOR = 1e3 # μm
|
||||||
FIRST_SEP = ':'
|
FIRST_SEP = ':'
|
||||||
OTHER_SEP = ','
|
OTHER_SEP = ','
|
||||||
LOC_SEP = ';'
|
LOC_SEP = '; '
|
||||||
|
|
||||||
cached_dists = {}
|
cached_dists = {}
|
||||||
cached_series = {}
|
cached_series = {}
|
||||||
|
|
@ -137,17 +137,25 @@ def trilaterate(stations: list[StationT], disp: bool = False) -> tuple[float, fl
|
||||||
Each station is of the format ((lat, lon), distance).
|
Each station is of the format ((lat, lon), distance).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
res = scipy.optimize.minimize(
|
best_err = None
|
||||||
lambda pos: trilat_error(stations, pos),
|
best = (0., 0.)
|
||||||
# stations[0][0],
|
|
||||||
(0.0, 0.0),
|
|
||||||
method='Nelder-Mead',
|
|
||||||
)
|
|
||||||
|
|
||||||
if not res.success:
|
for pos, _ in stations:
|
||||||
print("WARNING: Optimisation failed.")
|
res = scipy.optimize.minimize(
|
||||||
|
lambda pos: trilat_error(stations, pos),
|
||||||
|
# stations[0][0],
|
||||||
|
pos,
|
||||||
|
method='Nelder-Mead',
|
||||||
|
)
|
||||||
|
|
||||||
return res.x
|
if not res.success:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if best_err is None or res.fun < best_err:
|
||||||
|
best = res.x
|
||||||
|
best_err = res.fun
|
||||||
|
|
||||||
|
return best
|
||||||
|
|
||||||
|
|
||||||
def encode_greggs(loc: int) -> list[float]:
|
def encode_greggs(loc: int) -> list[float]:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from engine import encode_greggs, decode_greggs, encode, decode, format_location, parse_location, spherical_dist, fetch_data
|
from engine import encode_greggs, decode_greggs, encode, decode, format_location, parse_location, spherical_dist, fetch_data, format_dist, parse_dist
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import time
|
import time
|
||||||
|
|
@ -62,8 +62,11 @@ def test_encode_decode_greggs():
|
||||||
encoded = encode_greggs(i)
|
encoded = encode_greggs(i)
|
||||||
# tqdm.write(f"Encoding took {time.monotonic() - t:.3f}s")
|
# tqdm.write(f"Encoding took {time.monotonic() - t:.3f}s")
|
||||||
|
|
||||||
|
stringified = ",".join(map(format_dist, encoded))
|
||||||
|
parsed = [parse_dist(s.strip()) for s in stringified.split(",")]
|
||||||
|
|
||||||
# t = time.monotonic()
|
# t = time.monotonic()
|
||||||
decoded = decode_greggs(encoded)
|
decoded = decode_greggs(parsed)
|
||||||
# tqdm.write(f"Decoding took {time.monotonic() - t:.3f}s")
|
# tqdm.write(f"Decoding took {time.monotonic() - t:.3f}s")
|
||||||
|
|
||||||
if i != decoded:
|
if i != decoded:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue