Commit 47b2cf0e authored by Luc Maisonobe's avatar Luc Maisonobe

Allow observing all evaluations in OD.

parent fabfad12
......@@ -29,6 +29,7 @@ import org.hipparchus.optim.ConvergenceChecker;
import org.hipparchus.optim.nonlinear.vector.leastsquares.EvaluationRmsChecker;
import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresBuilder;
import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresOptimizer;
import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresOptimizer.Optimum;
import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem;
import org.hipparchus.optim.nonlinear.vector.leastsquares.ParameterValidator;
import org.hipparchus.util.Incrementor;
......@@ -76,8 +77,8 @@ public class BatchLSEstimator {
/** Last orbit. */
private Orbit orbit;
/** Last least squares problem evaluation. */
private LeastSquaresProblem.Evaluation lspEvaluation;
/** Optimum found. */
private Optimum optimum;
/** Counter for the evaluations. */
private Incrementor evaluationsCounter;
......@@ -326,36 +327,25 @@ public class BatchLSEstimator {
public boolean converged(final int iteration,
final LeastSquaresProblem.Evaluation previous,
final LeastSquaresProblem.Evaluation current) {
// save the last evaluations
lspEvaluation = current;
// notify the observer
if (observer != null) {
try {
observer.iterationPerformed(iterationsCounter.getCount(),
evaluationsCounter.getCount(),
orbit,
estimatedPropagatorParameters,
estimatedMeasurementsParameters,
new Provider(),
lspEvaluation);
} catch (OrekitException oe) {
throw new OrekitExceptionWrapper(oe);
}
}
final double lInf = current.getPoint().getLInfDistance(previous.getPoint());
return lInf <= parametersConvergenceThreshold;
}
});
// set up the problem to solve
final LeastSquaresProblem problem = new TappedLSProblem(lsBuilder.build(),
model,
estimatedOrbitalParameters,
estimatedPropagatorParameters,
estimatedMeasurementsParameters);
try {
// solve the problem
optimizer.optimize(new TappedLSProblem(lsBuilder.build(), model));
optimum = optimizer.optimize(problem);
// create a new configured propagator with all estimated parameters
return model.createPropagator(lspEvaluation.getPoint());
return model.createPropagator(optimum.getPoint());
} catch (MathRuntimeException mrte) {
throw new OrekitException(mrte);
......@@ -372,12 +362,11 @@ public class BatchLSEstimator {
return Collections.unmodifiableMap(evaluations);
}
/** Get the last {@link org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem.Evaluation
* least squares problem evaluation}.
* @return last least squares problem evaluation
/** Get the optimum found.
* @return optimum found after last call to {@link #estimate()}
*/
public LeastSquaresProblem.Evaluation getLastLSPEvaluation() {
return lspEvaluation;
public Optimum getOptimum() {
return optimum;
}
/** Get the number of iterations used for last estimation.
......@@ -403,14 +392,32 @@ public class BatchLSEstimator {
/** Multivariate function model. */
private final Model model;
/** Estimated orbital parameters. */
private final ParameterDriversList estimatedOrbitalParameters;
/** Estimated propagator parameters. */
private final ParameterDriversList estimatedPropagatorParameters;
/** Estimated measurements parameters. */
private final ParameterDriversList estimatedMeasurementsParameters;
/** Simple constructor.
* @param problem underlying problem
* @param model multivariate function model
* @param estimatedOrbitalParameters estimated orbital parameters
* @param estimatedPropagatorParameters estimated propagator parameters
* @param estimatedMeasurementsParameters estimated measurements parameters
*/
TappedLSProblem(final LeastSquaresProblem problem,
final Model model) {
this.problem = problem;
this.model = model;
final Model model,
final ParameterDriversList estimatedOrbitalParameters,
final ParameterDriversList estimatedPropagatorParameters,
final ParameterDriversList estimatedMeasurementsParameters) {
this.problem = problem;
this.model = model;
this.estimatedOrbitalParameters = estimatedOrbitalParameters;
this.estimatedPropagatorParameters = estimatedPropagatorParameters;
this.estimatedMeasurementsParameters = estimatedMeasurementsParameters;
}
/** {@inheritDoc} */
......@@ -458,7 +465,28 @@ public class BatchLSEstimator {
/** {@inheritDoc} */
@Override
public Evaluation evaluate(final RealVector point) {
return problem.evaluate(point);
// perform the evaluation
final Evaluation evaluation = problem.evaluate(point);
// notify the observer
if (observer != null) {
try {
observer.evaluationPerformed(iterationsCounter.getCount(),
evaluationsCounter.getCount(),
orbit,
estimatedOrbitalParameters,
estimatedPropagatorParameters,
estimatedMeasurementsParameters,
new Provider(),
evaluation);
} catch (OrekitException oe) {
throw new OrekitExceptionWrapper(oe);
}
}
return evaluation;
}
}
......
......@@ -32,10 +32,11 @@ import org.orekit.utils.ParameterDriversList;
*/
public interface BatchLSObserver {
/** Notification callback for the end of each iteration.
/** Notification callback for the end of each evaluation.
* @param iterationsCount iterations count
* @param evaluationscount evaluations count
* @param evaluationsCount evaluations count
* @param orbit current estimated orbit
* @param estimatedOrbitalParameters estimated orbital parameters
* @param estimatedPropagatorParameters estimated propagator parameters
* @param estimatedMeasurementsParameters estimated measurements parameters
* @param evaluationsProvider provider for measurements evaluations resulting
......@@ -44,13 +45,14 @@ public interface BatchLSObserver {
* @param lspEvaluation current evaluation of the underlying {@link LeastSquaresProblem
* least squares problem}
* @exception OrekitException if some problem occurs (for example evaluationProviders not
* being able to porvide an evaluation)
* being able to provide an evaluation)
*/
void iterationPerformed(int iterationsCount, int evaluationscount, Orbit orbit,
ParameterDriversList estimatedPropagatorParameters,
ParameterDriversList estimatedMeasurementsParameters,
EvaluationsProvider evaluationsProvider,
LeastSquaresProblem.Evaluation lspEvaluation)
void evaluationPerformed(int iterationsCount, int evaluationsCount, Orbit orbit,
ParameterDriversList estimatedOrbitalParameters,
ParameterDriversList estimatedPropagatorParameters,
ParameterDriversList estimatedMeasurementsParameters,
EvaluationsProvider evaluationsProvider,
LeastSquaresProblem.Evaluation lspEvaluation)
throws OrekitException;
}
......@@ -105,17 +105,24 @@ public class BatchLSEstimatorTest {
estimator.setMaxIterations(10);
estimator.setMaxEvaluations(20);
estimator.setObserver(new BatchLSObserver() {
int last = 0;
int lastIter = 0;
int lastEval = 0;
/** {@inheritDoc} */
@Override
public void iterationPerformed(int iterationsCount, int evaluationscount,
Orbit orbit,
ParameterDriversList estimatedPropagatorParameters,
ParameterDriversList estimatedMeasurementsParameters,
EvaluationsProvider evaluationsProvider,
Evaluation lspEvaluation) throws OrekitException {
Assert.assertEquals(last + 1, iterationsCount);
last = iterationsCount;
public void evaluationPerformed(int iterationsCount, int evaluationscount,
Orbit orbit,
ParameterDriversList estimatedOrbitalParameters,
ParameterDriversList estimatedPropagatorParameters,
ParameterDriversList estimatedMeasurementsParameters,
EvaluationsProvider evaluationsProvider, Evaluation lspEvaluation)
throws OrekitException {
if (iterationsCount == lastIter) {
Assert.assertEquals(lastEval + 1, evaluationscount);
} else {
Assert.assertEquals(lastIter + 1, iterationsCount);
}
lastIter = iterationsCount;
lastEval = evaluationscount;
Assert.assertEquals(measurements.size(), evaluationsProvider.getNumber());
try {
evaluationsProvider.getEvaluation(-1);
......@@ -175,12 +182,12 @@ public class BatchLSEstimatorTest {
estimator.setObserver(new BatchLSObserver() {
/** {@inheritDoc} */
@Override
public void iterationPerformed(int iterationsCount, int evaluationscount,
public void evaluationPerformed(int iterationsCount, int evaluationscount,
Orbit orbit,
ParameterDriversList estimatedOrbitalParameters,
ParameterDriversList estimatedPropagatorParameters,
ParameterDriversList estimatedMeasurementsParameters,
EvaluationsProvider evaluationsProvider,
Evaluation lspEvaluation) throws DummyException {
EvaluationsProvider evaluationsProvider, Evaluation lspEvaluation) throws DummyException {
throw new DummyException();
}
});
......
......@@ -244,14 +244,16 @@ public class OrbitDetermination {
/** {@inheritDoc} */
@Override
public void iterationPerformed(final int iterationsCount, final int evaluationsCount,
public void evaluationPerformed(final int iterationsCount, final int evaluationsCount,
final Orbit orbit,
final ParameterDriversList estimatedOrbitalParameters,
final ParameterDriversList estimatedPropagatorParameters,
final ParameterDriversList estimatedMeasurementsParameters,
final EvaluationsProvider evaluationsProvider,
final EvaluationsProvider evaluationsProvider,
final LeastSquaresProblem.Evaluation lspEvaluation) {
PVCoordinates currentPV = orbit.getPVCoordinates();
final String format = " %2d %2d %13.6f %12.9f %16.12f %s %s %s %s%n";
final String format0 = " %2d %2d %16.12f %s %s %s %s%n";
final String format = " %2d %2d %13.6f %12.9f %16.12f %s %s %s %s%n";
final EvaluationCounter<Range> rangeCounter = new EvaluationCounter<Range>();
final EvaluationCounter<RangeRate> rangeRateCounter = new EvaluationCounter<RangeRate>();
final EvaluationCounter<Angular> angularCounter = new EvaluationCounter<Angular>();
......@@ -275,21 +277,36 @@ public class OrbitDetermination {
pvCounter.add(evaluation);
}
}
System.out.format(Locale.US, format,
iterationsCount, evaluationsCount,
Vector3D.distance(previousPV.getPosition(), currentPV.getPosition()),
Vector3D.distance(previousPV.getVelocity(), currentPV.getVelocity()),
lspEvaluation.getRMS(),
rangeCounter.format(8), rangeRateCounter.format(8),
angularCounter.format(8), pvCounter.format(8));
if (logStream != null) {
logStream.format(Locale.US, format,
iterationsCount, evaluationsCount,
Vector3D.distance(previousPV.getPosition(), currentPV.getPosition()),
Vector3D.distance(previousPV.getVelocity(), currentPV.getVelocity()),
lspEvaluation.getRMS(),
rangeCounter.format(8), rangeRateCounter.format(8),
angularCounter.format(8), pvCounter.format(8));
if (evaluationsCount == 1) {
System.out.format(Locale.US, format0,
iterationsCount, evaluationsCount,
lspEvaluation.getRMS(),
rangeCounter.format(8), rangeRateCounter.format(8),
angularCounter.format(8), pvCounter.format(8));
if (logStream != null) {
logStream.format(Locale.US, format0,
iterationsCount, evaluationsCount,
lspEvaluation.getRMS(),
rangeCounter.format(8), rangeRateCounter.format(8),
angularCounter.format(8), pvCounter.format(8));
}
} else {
System.out.format(Locale.US, format,
iterationsCount, evaluationsCount,
Vector3D.distance(previousPV.getPosition(), currentPV.getPosition()),
Vector3D.distance(previousPV.getVelocity(), currentPV.getVelocity()),
lspEvaluation.getRMS(),
rangeCounter.format(8), rangeRateCounter.format(8),
angularCounter.format(8), pvCounter.format(8));
if (logStream != null) {
logStream.format(Locale.US, format,
iterationsCount, evaluationsCount,
Vector3D.distance(previousPV.getPosition(), currentPV.getPosition()),
Vector3D.distance(previousPV.getVelocity(), currentPV.getVelocity()),
lspEvaluation.getRMS(),
rangeCounter.format(8), rangeRateCounter.format(8),
angularCounter.format(8), pvCounter.format(8));
}
}
previousPV = currentPV;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment