-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor improvements to orbit determination types (#149)
* Add calculate_max_outliers * Use adam_core's OrbitDeterminationObservations * Change differential correction, merge and extend to accept a Propagator type * Change to FittedOrbits and FittedOrbitMembers to match adam_core's class definitions
- Loading branch information
Showing
10 changed files
with
169 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
from .fitted_orbits import * | ||
# noqa: F401 | ||
from .fitted_orbits import ( | ||
FittedOrbits, | ||
FittedOrbitMembers, | ||
assign_duplicate_observations, | ||
) | ||
from .outliers import calculate_max_outliers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import numpy as np | ||
|
||
|
||
def calculate_max_outliers( | ||
num_obs: int, min_obs: int, contamination_percentage: float | ||
) -> int: | ||
""" | ||
Calculate the maximum number of allowable outliers. Linkages may contain err | ||
oneuos observations that need to be removed. This function calculates the maximum number of | ||
observations that can be removed before the linkage no longer has the minimum number | ||
of observations required. The contamination percentage is the maximum percentage of observations | ||
that allowed to be erroneous. | ||
Parameters | ||
---------- | ||
num_obs : int | ||
Number of observations in the linkage. | ||
min_obs : int | ||
Minimum number of observations required for a valid linkage. | ||
contamination_percentage : float | ||
Maximum percentage of observations that allowed to be erroneous. Range is [0, 100]. | ||
Returns | ||
------- | ||
outliers : int | ||
Maximum number of allowable outliers. | ||
""" | ||
assert ( | ||
num_obs >= min_obs | ||
), "Number of observations must be greater than or equal to the minimum number of observations." | ||
assert ( | ||
contamination_percentage >= 0 and contamination_percentage <= 100 | ||
), "Contamination percentage must be between 0 and 100." | ||
|
||
max_outliers = num_obs * (contamination_percentage / 100) | ||
outliers = np.min([max_outliers, num_obs - min_obs]).astype(int) | ||
return outliers |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pytest | ||
|
||
from ..outliers import calculate_max_outliers | ||
|
||
|
||
def test_calculate_max_outliers(): | ||
# Test that the function returns the correct number of outliers given | ||
# the number of observations, minimum number of observations, and | ||
# contamination percentage in a few different cases. | ||
min_obs = 3 | ||
num_obs = 10 | ||
contamination_percentage = 50 | ||
outliers = calculate_max_outliers(num_obs, min_obs, contamination_percentage) | ||
assert outliers == 5 | ||
|
||
min_obs = 6 | ||
num_obs = 10 | ||
contamination_percentage = 50 | ||
outliers = calculate_max_outliers(num_obs, min_obs, contamination_percentage) | ||
assert outliers == 4 | ||
|
||
min_obs = 6 | ||
num_obs = 6 | ||
contamination_percentage = 50 | ||
outliers = calculate_max_outliers(num_obs, min_obs, contamination_percentage) | ||
assert outliers == 0 | ||
|
||
|
||
def test_calculate_max_outliers_assertions(): | ||
# Test that the function raises an assertion error when the number of observations | ||
# is less than the minimum number of observations. | ||
min_obs = 10 | ||
num_obs = 6 | ||
contamination_percentage = 50 | ||
with pytest.raises( | ||
AssertionError, | ||
match=r"Number of observations must be greater than or equal to the minimum number of observations.", | ||
): | ||
outliers = calculate_max_outliers(num_obs, min_obs, contamination_percentage) | ||
|
||
# Test that the function raises an assertion error when the contamination percentage | ||
# is less than 0. | ||
min_obs = 10 | ||
num_obs = 10 | ||
contamination_percentage = -50 | ||
with pytest.raises( | ||
AssertionError, match=r"Contamination percentage must be between 0 and 1." | ||
): | ||
outliers = calculate_max_outliers(num_obs, min_obs, contamination_percentage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.