Skip to content
Snippets Groups Projects
Commit 3b89a43e authored by Raphael's avatar Raphael
Browse files

added normalisation with dictionnary

parent 29df63e3
No related branches found
No related tags found
1 merge request!6Develop
...@@ -224,8 +224,22 @@ class AISTrajectory: ...@@ -224,8 +224,22 @@ class AISTrajectory:
l2 = l2_angle(dat, radius) l2 = l2_angle(dat, radius)
self.df[f"angle_l2"] = l2 self.df[f"angle_l2"] = l2
def normalize(self, features, normalization_type="min-max"): def normalize(self, features, normalization_type="min-max", dictionary=None):
normalization_dict = {} normalization_dict = None
if dictionary is not None:
if dictionary["type"] == "min-max":
for f in features:
minimum = dictionary[f"{f}_minimum"]
maximum = dictionary[f"{f}_maximum"]
self.df[f] = (self.df[f] - minimum) / (maximum - minimum)
elif dictionary["type"] == "standardization":
for f in features:
mean = dictionary[f"{f}_mean"]
std = dictionary[f"{f}_std"]
self.df[f] = (self.df[f] - mean) / std
else:
normalization_dict = {"type": normalization_type}
if normalization_type == "min-max": if normalization_type == "min-max":
for f in features: for f in features:
minimum = self.df[f].min() minimum = self.df[f].min()
...@@ -235,7 +249,6 @@ class AISTrajectory: ...@@ -235,7 +249,6 @@ class AISTrajectory:
normalization_dict[f"{f}_maximum"] = maximum normalization_dict[f"{f}_maximum"] = maximum
elif normalization_type == "standardization": elif normalization_type == "standardization":
normalisation_factors = ("standardization", {})
for f in features: for f in features:
mean = self.df[f].mean() mean = self.df[f].mean()
std = self.df[f].std() std = self.df[f].std()
...@@ -249,7 +262,8 @@ class AISTrajectory: ...@@ -249,7 +262,8 @@ class AISTrajectory:
else: else:
raise ValueError(f"{normalization_type} not a valid normalization method. Must be on of [min-max, " raise ValueError(f"{normalization_type} not a valid normalization method. Must be on of [min-max, "
f"standardization]") f"standardization]")
return normalization_type, normalization_dict
return normalization_dict
def compute_derivative(self, field): def compute_derivative(self, field):
dt = self.df['ts_sec'].diff() / 60 dt = self.df['ts_sec'].diff() / 60
......
...@@ -9,6 +9,7 @@ def make_feature_vectors(trajectories, features=None, ...@@ -9,6 +9,7 @@ def make_feature_vectors(trajectories, features=None,
zero = [0 for _ in range(nb_classes)] zero = [0 for _ in range(nb_classes)]
for trajectory in trajectories: for trajectory in trajectories:
trajectory.df.dropna(inplace=True)
if len(trajectory.df.index) > length_list: if len(trajectory.df.index) > length_list:
trajectory.df['ts'] = trajectory.df.index trajectory.df['ts'] = trajectory.df.index
trajectory.compute_all_derivatives() trajectory.compute_all_derivatives()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment