LMedSRobustRangingPositionEstimator2D.java
/*
* Copyright (C) 2019 Alberto Irurueta Carro (alberto@irurueta.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.irurueta.navigation.indoor.position;
import com.irurueta.geometry.Point2D;
import com.irurueta.navigation.LockedException;
import com.irurueta.navigation.indoor.RadioSource;
import com.irurueta.navigation.indoor.RadioSourceLocated;
import com.irurueta.navigation.indoor.RangingFingerprint;
import com.irurueta.navigation.indoor.RangingReading;
import com.irurueta.navigation.lateration.LMedSRobustLateration2DSolver;
import com.irurueta.numerical.robust.RobustEstimatorMethod;
import java.util.List;
/**
* Robustly estimates 2D position using located radio sources and their ranging readings
* at unknown locations and using LMedS algorithm to discard outliers.
* This kind of estimator can be used to robustly determine the 2D position of a given
* device by getting ranging readings at an unknown location of different radio sources
* whose 2D locations are known.
*/
public class LMedSRobustRangingPositionEstimator2D extends RobustRangingPositionEstimator2D {
/**
* Constructor.
*/
public LMedSRobustRangingPositionEstimator2D() {
super();
init();
}
/**
* Constructor.
*
* @param sources located radio sources used for lateration.
* @throws IllegalArgumentException if provided sources is null or the number of
* provided sources is less than the required minimum.
*/
public LMedSRobustRangingPositionEstimator2D(final List<? extends RadioSourceLocated<Point2D>> sources) {
super();
init();
internalSetSources(sources);
}
/**
* Constructor.
*
* @param fingerprint fingerprint containing ranging readings at an unknown location
* for provided located radio sources.
* @throws IllegalArgumentException if provided fingerprint is null.
*/
public LMedSRobustRangingPositionEstimator2D(
final RangingFingerprint<? extends RadioSource, ? extends RangingReading<?
extends RadioSource>> fingerprint) {
super();
init();
internalSetFingerprint(fingerprint);
}
/**
* Constructor.
*
* @param sources located radio sources used for lateration.
* @param fingerprint fingerprint containing ranging readings at an unknown location
* for provided located radio sources.
* @throws IllegalArgumentException if either provided sources or fingerprint is null
* or the number of provided sources is less than the required minimum.
*/
public LMedSRobustRangingPositionEstimator2D(
final List<? extends RadioSourceLocated<Point2D>> sources,
final RangingFingerprint<? extends RadioSource, ? extends RangingReading<?
extends RadioSource>> fingerprint) {
super();
init();
internalSetSources(sources);
internalSetFingerprint(fingerprint);
}
/**
* Constructor.
*
* @param listener listener in charge of handling events.
*/
public LMedSRobustRangingPositionEstimator2D(final RobustRangingPositionEstimatorListener<Point2D> listener) {
super(listener);
init();
}
/**
* Constructor.
*
* @param sources located radio sources used for lateration.
* @param listener listener in charge of handling events.
* @throws IllegalArgumentException if provided sources is null or the number of
* provided sources is less than the required minimum.
*/
public LMedSRobustRangingPositionEstimator2D(
final List<? extends RadioSourceLocated<Point2D>> sources,
final RobustRangingPositionEstimatorListener<Point2D> listener) {
super(listener);
init();
internalSetSources(sources);
}
/**
* Constructor.
*
* @param fingerprint fingerprint containing ranging readings at an unknown
* location for provided location radio sources.
* @param listener listener in charge of handling events.
* @throws IllegalArgumentException if provided fingerprint is null.
*/
public LMedSRobustRangingPositionEstimator2D(
final RangingFingerprint<? extends RadioSource, ? extends RangingReading<?
extends RadioSource>> fingerprint,
final RobustRangingPositionEstimatorListener<Point2D> listener) {
super(listener);
init();
internalSetFingerprint(fingerprint);
}
/**
* Constructor.
*
* @param sources located radio sources used for lateration.
* @param fingerprint fingerprint containing readings at an unknown location for
* provided located radio sources.
* @param listener listener in charge of handling events.
* @throws IllegalArgumentException if either provided sources or fingerprint is
* null or the number of provided sources is less than the required minimum.
*/
public LMedSRobustRangingPositionEstimator2D(
final List<? extends RadioSourceLocated<Point2D>> sources,
final RangingFingerprint<? extends RadioSource, ? extends RangingReading<?
extends RadioSource>> fingerprint,
final RobustRangingPositionEstimatorListener<Point2D> listener) {
super(listener);
init();
internalSetSources(sources);
internalSetFingerprint(fingerprint);
}
/**
* Returns threshold to be used to keep the algorithm iterating in case that
* best estimated threshold using median of residuals is not small enough.
* Once a solution is found that generates a threshold below this value, the
* algorithm will stop.
* The stop threshold can be used to prevent the LMedS algorithm to iterate
* too many times in cases where samples have a very similar accuracy.
* For instance, in cases where proportion of outliers is very small (close
* to 0%), and samples are very accurate (i.e. 1e-6), the algorithm would
* iterate for a long time trying to find the best solution when indeed
* there is no need to do that if a reasonable threshold has already been
* reached.
* Because of this behaviour the stop threshold can be set to a value much
* lower than the one typically used in RANSAC, and yet the algorithm could
* still produce even smaller thresholds in estimated results.
*
* @return stop threshold to stop the algorithm prematurely when a certain
* accuracy has been reached.
*/
public double getStopThreshold() {
return ((LMedSRobustLateration2DSolver) laterationSolver).getStopThreshold();
}
/**
* Sets threshold to be used to keep the algorithm iterating in case that
* best estimated threshold using median of residuals is not small enough.
* Once a solution is found that generates a threshold below this value,
* the algorithm will stop.
* The stop threshold can be used to prevent the LMedS algorithm to iterate
* too many times in cases where samples have a very similar accuracy.
* For instance, in cases where proportion of outliers is very small (close
* to 0%), and samples are very accurate (i.e. 1e-6), the algorithm would
* iterate for a long time trying to find the best solution when indeed
* there is no need to do that if a reasonable threshold has already been
* reached.
* Because of this behaviour the stop threshold can be set to a value much
* lower than the one typically used in RANSAC, and yet the algorithm could
* still produce even smaller thresholds in estimated results.
*
* @param stopThreshold stop threshold to stop the algorithm prematurely
* when a certain accuracy has been reached.
* @throws IllegalArgumentException if provided value is zero or negative.
* @throws LockedException if this solver is locked.
*/
public void setStopThreshold(final double stopThreshold) throws LockedException {
((LMedSRobustLateration2DSolver) laterationSolver).setStopThreshold(stopThreshold);
}
/**
* Returns method being used for robust estimation.
*
* @return method being used for robust estimation.
*/
@Override
public RobustEstimatorMethod getMethod() {
return RobustEstimatorMethod.LMEDS;
}
/**
* Initializes robust lateration solver.
*/
private void init() {
laterationSolver = new LMedSRobustLateration2DSolver(trilaterationSolverListener);
}
}