Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

create uniform distribution over a specific sequence with noise

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)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading