Skip to content

Commit

Permalink
Add "positive_semidefinite" DataProcessor normalisation method
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-andersson committed Jul 28, 2024
1 parent d18f999 commit 88a9818
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion deepsensor/data/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(
self.verbose = verbose

# List of valid normalisation method names
self.valid_methods = ["mean_std", "min_max"]
self.valid_methods = ["mean_std", "min_max", "positive_semidefinite"]

def save(self, folder: str):
"""Save DataProcessor config to JSON in `folder`"""
Expand Down Expand Up @@ -293,6 +293,8 @@ def get_config(self, var_ID, data, method=None):
params = {"mean": float(data.mean()), "std": float(data.std())}
elif method == "min_max":
params = {"min": float(data.min()), "max": float(data.max())}
elif method == "positive_semidefinite":
params = {"min": float(data.min()), "std": float(data.std())}
if self.verbose:
print(f"Done. {var_ID} {method} params={params}")
self.add_to_config(
Expand Down Expand Up @@ -507,6 +509,9 @@ def map_array(
elif method == "min_max":
m = (params["max"] - params["min"]) / 2
c = (params["max"] + params["min"]) / 2
elif method == "positive_semidefinite":
m = params["std"]
c = params["min"]
if not unnorm:
c = -c / m
m = 1 / m
Expand Down Expand Up @@ -599,6 +604,7 @@ def __call__(
method (str, optional): Normalisation method. Options include:
- "mean_std": Normalise to mean=0 and std=1 (default)
- "min_max": Normalise to min=-1 and max=1
- "positive_semidefinite": Normalise to min=0 and std=1
Returns:
:class:`xarray.DataArray` | :class:`xarray.Dataset` | :class:`pandas.DataFrame` | List[:class:`xarray.DataArray` | :class:`xarray.Dataset` | :class:`pandas.DataFrame`]:
Expand Down

0 comments on commit 88a9818

Please sign in to comment.