Home > Mobile >  create uniform distribution over a specific sequence with noise
create uniform distribution over a specific sequence with noise

Time:11-06

what is the best way to draw samples x that have this distribution with size n? if it was uniformly

c = [0.5,0.6,0,0,0.4,0,0.2,0.2,0.1,0.1,0.1] with n = 11

in case I want to increase the noise could of use this np.random.rand(n)?

CodePudding user response:

numpy.random.uniform will let you generate "n" unformly distributed samples between a given "low" and "high" limit.

For example:

import numpy as np

lower_limit = 3
upper_limit = 7
number_of_samples = 11

c = np.random.uniform(lower_limit, upper_limit, number_of_samples)

print (c)

produces:

[6.96837557 6.31203767 6.49680613 6.46568161 3.77999427 3.8421241
 6.27406087 4.60471307 4.5874396  3.7439116  4.69739617]

The range between your "lower" and "upper" limit might be regarded as a proxy for "noisiness" of the samples.

Documentation here: https://numpy.org/doc/stable/reference/random/generated/numpy.random.uniform.html

If what you're trying to do is "add noise" to a given list of values, you could generate a uniformly distributed array of random numbers to represent the "noise" and add this noise to your original list of values. For example:

noiseless_values = np.linspace(1, 10, num = 10)
noisy_values = noiseless_values * np.random.uniform(0.9, 1.1, len(noiseless_values))

for noiseless, noisy in zip(noiseless_values, noisy_values):
    print (f'{noiseless:<6}: {noisy:}')

...produces:

1.0   : 1.071975105690119
2.0   : 1.9508717288907071
3.0   : 2.8448791935778157
4.0   : 4.175151052483082
5.0   : 5.056205712396034
6.0   : 6.4584524295884735
7.0   : 6.3247828913239985
8.0   : 8.730239323071011
9.0   : 8.37164223683849
10.0  : 9.133076473380891

Hope this helps.

  • Related