generate random numbers with biased probabilities in keras

Asked 1 years ago, Updated 1 years ago, 90 views

I'm trying to touch Keras.I have an image of what I want to do, but I don't know which keyword to search on Google.
How do I create a program that:
I don't know how to look it up on Google, so I asked you a question.

  • Use numbers as learning data
  • Be sure to output five random numbers separated by commas
  • Random number output should be biased with learning data

A pure random number from 1 to 5 is generated in the first one such as (1,2,3,4,5).However, when learning "1" from the learning data, the generation rate of "1" becomes high when the random number is generated.When learning the number "99" in the learning data, random numbers "99" are also output.

python tensorflow keras

2022-09-29 20:29

1 Answers

Assume that multiple integers are listed as learning data and prepared.No matter how large the learning data is, it doesn't matter.

Example 1:

a=[1,2,3,4,5]

Example 2:

 a = [1, 2, 3, 4, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 5, 5, 5,

The easiest way to generate one random number according to the integers in this list (that is, the probability of each number being proportional) is to use random.choice.

from random import choice

a = [1, 2, 3, 4, 5, 2, 3, 4, 5, 3, 4, 4, 5, 5 ]

print(choice(a))

If you draw a histogram, you can see that it is actually biased.

from random import choice
import matplotlib.pyplot asplt
import numpy as np

a = [1, 2, 3, 4, 5, 2, 3, 4, 5, 3, 4, 4, 5, 5 ]

numbers = [choice(a) for_in range(15000)]

plt.hist(number, bins=np.range(min(a), max(a)+2)-0.5, rwidth=0.3)
plt.show()

Enter a description of the image here

Then, you can put five of them together and output them separately.For example, the following program outputs 5 random numbers/times x 10 random numbers = 50 random numbers.

from random import choice

a = [1, 2, 3, 4, 5, 2, 3, 4, 5, 3, 4, 4, 5, 5 ]

for_in range(10):
    numbers = [choice(a) for_in range(5)]
    print(','.join(str(n)for n in numbers))

Enter a description of the image here


2022-09-29 20:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.