Created
July 20, 2018 00:46
-
-
Save enijkamp/d6f5c879b24b6291a1efe63711b44bfc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import numpy as np | |
POINTS_PER_WF = int(1e4) | |
X_SPACE = np.linspace(0, 100, POINTS_PER_WF) | |
def make_waveform_with_noise(): | |
def add_noise(vec): | |
stdev = float(np.random.uniform(0, 0.2)) | |
return vec + np.random.normal(0, stdev, size=len(vec)) | |
f = np.random.choice((np.sin, np.cos)) | |
wf = f(X_SPACE * np.random.normal(scale=5)) * np.random.normal(scale=5) + np.random.normal(scale=50) | |
return wf, add_noise(wf) | |
def generate_training_data(batch_size, rescaling = 1e-3): | |
while True: | |
x = np.empty((batch_size, POINTS_PER_WF, 1)) | |
y = np.empty((batch_size, POINTS_PER_WF, 1)) | |
for sample in range(batch_size): | |
valid_wf, noisy_wf = make_waveform_with_noise() | |
x[sample, :, :] = noisy_wf.reshape((1, POINTS_PER_WF, 1)) * rescaling | |
y[sample, :, :] = valid_wf.reshape((1, POINTS_PER_WF, 1)) * rescaling | |
yield x, y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment