Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update solver.py #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions mlat/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from mlat import geodesy, constants, profile
from mlat import config
import numpy as np

# The core of it all. Not very big, is it?
# (Admittedly the entire least-squares solver is hidden within scipy..)
Expand All @@ -36,7 +37,7 @@


def _residuals(x_guess, pseudorange_data, altitude, altitude_error):
"""Return an array of residuals for a position guess at x_guess versus
"""Return the sum of squared residuals for a position guess at x_guess versus
actual measurements pseudorange_data and altitude."""

(*position_guess, offset) = x_guess
Expand All @@ -53,7 +54,8 @@ def _residuals(x_guess, pseudorange_data, altitude, altitude_error):
_, _, altitude_guess = geodesy.ecef2llh(position_guess)
res.append((altitude - altitude_guess) / altitude_error)

return res
# return the sum of squared residuals
return np.sum(np.array(res)**2)


@profile.trackcpu
Expand Down Expand Up @@ -91,19 +93,19 @@ def solve(measurements, altitude, altitude_error, initial_guess):
math.sqrt(variance) * constants.Cair)
for receiver, timestamp, variance in measurements]
x_guess = [initial_guess[0], initial_guess[1], initial_guess[2], 0.0]
x_est, cov_x, infodict, mesg, ler = scipy.optimize.leastsq(
res = scipy.optimize.minimize(
_residuals,
x_guess,
args=(pseudorange_data, altitude, altitude_error),
full_output=True,
maxfev=config.SOLVER_MAXFEV)
method='BFGS',
options={'maxiter': config.SOLVER_MAXFEV})

if ler in (1, 2, 3, 4):
if res.success:
#glogger.info("solver success: {0} {1}".format(ler, mesg))

# Solver found a result. Validate that it makes
# some sort of physical sense.
(*position_est, offset_est) = x_est
(*position_est, offset_est) = res.x

if offset_est < 0 or offset_est > 500e3:
#glogger.info("solver: bad offset: {0}".formaT(offset_est))
Expand All @@ -118,10 +120,10 @@ def solve(measurements, altitude, altitude_error, initial_guess):
# #glogger.info("solver: bad range: {0}".format(d))
# return None

if cov_x is None:
if res.hess_inv is None:
return position_est, None
else:
return position_est, cov_x[0:3, 0:3]
return position_est, res.hess_inv[0:3, 0:3]

else:
# Solver failed
Expand Down
Loading