Q: Making white noise in Python

Asked 1 years ago, Updated 1 years ago, 134 views

I want to put white noise in the function I made. For example,

def black_box_functon(x,y):
    return -x ** 2 - (y - 1) ** 2 + 1

I made this function, and I want to return it by adding white noise. What should I do? The code for making white noise is as follows.

import numpy
import matplotlib.pyplot as plt

mean = 0
std = 1 
num_samples = 1000
samples = numpy.random.normal(mean, std, size=num_samples)

plt.plot(samples)
plt.show()

Can we apply this to the expression above?

python-3.x

2022-09-22 15:35

2 Answers

I'd like to add white noise here and return it.

According to your requirements, the function has been worked to return additional white noise.
* Additional cost: KRW 20,000

def black_box_functon(x,y):
    return str(-x ** 2 - (y - 1) ** 2 + 1) + ' white noise'


2022-09-22 15:35

The joke code I posted earlier seems to have done its job, so to write down a serious answer... I don't know numpy and I don't know math, but the noise you're talking about is roughly

For a function that provides a continuous output value according to the input value, an error randomly added to the output value is

I think you're talking about that.

If that's all, the basic outline is actually no different from the joke code I posted before .

import random

def black_box_function_with_noise(x, y, range = 1000) :
    return (-x ** 2 - (y - 1) ** 2 + 1) + (random.randrange(-1 * range, range) / float(1000))

print(black_box_function_with_noise(-3, 1))
print(black_box_function_with_noise(-3, 1))
print(black_box_function_with_noise(-3, 1))
# -8.268
# -7.238
# -8.377

Isn't the numpy code you uploaded just a random number of glass between -1 and 1 as many as samples Then numpy is not the point. The key is to get a random rational number between -1 and 1.

Do some research.


2022-09-22 15:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.