Skip to content

Commit

Permalink
* invert distances after checking for outliers
Browse files Browse the repository at this point in the history
* check for outliers in weights
  • Loading branch information
mogres committed Oct 9, 2023
1 parent 469ebe6 commit bff176e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cellpack/autopack/Gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,16 @@ def set_weights_by_mode(self):

self.scaled_distances = self.get_normalized_values(self.distances)

if self.invert == "distance":
self.scaled_distances = 1.0 - self.scaled_distances

if (max(self.scaled_distances) > 1.0) or (min(self.scaled_distances) < 0.0):
if (numpy.nanmax(self.scaled_distances) > 1.0) or (
numpy.nanmin(self.scaled_distances) < 0.0
):
raise ValueError(
"CHECK CALCULATED DISTANCES",
f"Max: {max(self.scaled_distances)}, Min: {min(self.scaled_distances)}",
)

if self.invert == "distance":
self.scaled_distances = 1.0 - self.scaled_distances
if self.weight_mode == "linear":
self.weight = 1.0 - self.scaled_distances
elif self.weight_mode == "square":
Expand All @@ -232,6 +234,12 @@ def set_weights_by_mode(self):
# normalize the weight
self.weight = self.get_normalized_values(self.weight)

if (numpy.nanmax(self.weight) > 1.0) or (numpy.nanmin(self.weight) < 0.0):
raise ValueError(
"CHECK CALCULATED WEIGHTS",
f"Max: {max(self.weight)}, Min: {min(self.weight)}",
)

self.weight[numpy.isnan(self.weight)] = 0

if self.invert == "weight":
Expand Down

0 comments on commit bff176e

Please sign in to comment.