Skip to content
Snippets Groups Projects
Commit a8566ff6 authored by tomrink's avatar tomrink
Browse files

snapshot..

parent 6b83ae44
Branches
No related tags found
No related merge requests found
...@@ -435,13 +435,14 @@ def make_histogram(values, edges): ...@@ -435,13 +435,14 @@ def make_histogram(values, edges):
return h return h
def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=0.01, seed=None, copy=True): def normalize(data, param, mean_std_dict, copy=True):
if copy:
data = data.copy()
if mean_std_dict.get(param) is None: if mean_std_dict.get(param) is None:
return data return data
if copy:
data = data.copy()
shape = data.shape shape = data.shape
data = data.flatten() data = data.flatten()
...@@ -449,12 +450,6 @@ def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=0.01, see ...@@ -449,12 +450,6 @@ def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=0.01, see
data -= mean data -= mean
data /= std data /= std
if add_noise:
if seed is not None:
np.random.seed(seed)
rnd = np.random.normal(loc=0, scale=noise_scale, size=data.size)
data += rnd
not_valid = np.isnan(data) not_valid = np.isnan(data)
data[not_valid] = 0 data[not_valid] = 0
...@@ -463,6 +458,23 @@ def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=0.01, see ...@@ -463,6 +458,23 @@ def normalize(data, param, mean_std_dict, add_noise=False, noise_scale=0.01, see
return data return data
def add_noise(data, noise_scale=0.01, seed=None, copy=True):
if copy:
data = data.copy()
shape = data.shape
data = data.flatten()
if seed is not None:
np.random.seed(seed)
rnd = np.random.normal(loc=0, scale=noise_scale, size=data.size)
data += rnd
data = np.reshape(data, shape)
return data
def denormalize(data, param, mean_std_dict, copy=True): def denormalize(data, param, mean_std_dict, copy=True):
if copy: if copy:
data = data.copy() data = data.copy()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment