vendredi 10 février 2017

Sample my data according to a gaussian distribution

I have generated data and need to select samples according to a specific distribution.

My data are images and steering angles, where each image has an angle assigned to it. I plotted the data in a histogram over all steering angles, which are values between [-1, 1]. For my application, it is important how often each steering angle is represented, which is why I'd like to be able to "shape it" into common distributions by randomly selecting and dropping angles and corresponding images. In this case, I'd like to sample it according to a Gaussian N(0, 0.3) distribution.

What I've come up with so far was only to crop the top (I thought I'd need a uniform distribution at first) with this code:

hist_y_data = np.histogram(y_data, bins=200)
number_samples_bin = hist_y_data[0]
range_samples_bin = hist_y_data[1]
# To introduce randomness, let's shuffle the data
X, y = shuffle(X_data_paths, y_data)

length_y = len(y)
i = 0
for counter in range(length_y):
    for j in range(len(number_samples_bin)-1):
        if y[i] >= range_samples_bin[j] and y[i] < range_samples_bin[j+1]:
            if number_samples_bin[j] >= 200:
                # os.remove('data/' + X_data_paths[i])
                y.pop(i)
                X.pop(i)
                number_samples_bin[j] -= 1
                i -= 1
                break
    i += 1

That resulting histogram is: enter image description here

What I really would need is to trim the data according to a Gaussian distribution with N(0, 0.3). How would I do that?




Aucun commentaire:

Enregistrer un commentaire