フィルターのクリア

How can I choose non-repeating values with a probability of 90% and 10% ?

1 回表示 (過去 30 日間)
giancarlo maldonado cardenas
giancarlo maldonado cardenas 2022 年 2 月 17 日
コメント済み: Wasseem Khardawi 2022 年 2 月 19 日
Hello friends, how can I choose values ​​that do not repeat with a probability of 90% and 10%?
let me explain myself better.
For example I have a vector:
vector = [43 19 63 60 19 27 6]
So what I have done so far with my algorithm is that if the numbers that are inside the vector are not repeated, I assign a binary code of "1", on the other hand, if any number inside the vector is repeated, I assign a binary code of "0". ", as can be seen in the image below.
now I want to solve the following problem, that, if the numbers within the vector are not repeated, they have a 90% probability of assigning the binary code "1" and a 10% probability of assigning the binary code "0", on the other hand if the numbers within the vector are repeated with a 100% probability of being assigned the binary code "0".
for example:
taking the variable :
vector = [43 19 63 60 19 27 6]
numbers that are not repeated we have 43,63,60,27 and 6.
then it would have to be randomly assigned the binary code "1" with a 90% probability and the binary code "0" with a 10% probability.
taking into account that the probability is assigned randomly
then the result would be something like this.
I touch 90% to 43 so it is assigned the binary code "1"
I touch 90% to 63 so it is assigned the binary code "1"
I touch 10% to 60 so it is assigned the binary code "0"
I touch 90% to 27 so it is assigned the binary code "1"
I touch 90% to 6 so it is assigned the binary code "1"
Now the repeated numbers of the vector are 19,19.
then with 100% the binary code of "0" is assigned
19 is assigned the binary code "0" >> with 100%
19 is assigned the binary code "0" >> with 100%
in the end my matrix would look like this
43 "1"
19 "0"
63 "1"
60 "0"
19 "0"
27 "1"
6 "1"
thank you very much in advance

採用された回答

Voss
Voss 2022 年 2 月 18 日
To generate a number that has value 1 with 90% probability and value 0 with 10% probability, you can use randi() to generate a random integer between 1 and 10, then use the condition that the integer is greater than 1. It will be greater than 1 90% of the time (so the condition will be true) and (less than or) equal to 1 10% of the time (and the condition will be false). Convert the condition from logical to double, and you have your number(s). A demonstration with 10000 random numbers obeying this distribution:
x = double(randi(10,1,10000) > 1);
nnz(x)
ans = 9000

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLTE Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by