generating random variable between 0 and 1 with probabilities

5 vues (au cours des 30 derniers jours)
william Smith
william Smith le 10 Mar 2019
Commenté : william Smith le 10 Mar 2019
Hi all,
I have two questions please:
1) how do i generate a random number either 0 or 1 with equal chances of accept and reject 50-50 chance?
2) how do i generate a random number either 0 or 1 with percent shift in probablity in order to accept "bias' between -0.5 and 0.5
if percent shift=0 then 50-50 chance of accept
if percent shift=0.1 then 60% accept - 40% reject
if percent shift=0.2 then 70% accept - 30% reject
if percent shift=0.3 then 80% accept - 20% reject
if percent shift=0.4 then 90% accept - 20% reject
if percent shift=0.5 then 100% accept - 0% reject
if percent shift=-0.1 then 40% accept - 60% reject
if percent shift=-0.2 then 30% accept - 70% reject
if percent shift=-0.3 then 20% accept - 80% reject
if percent shiftt=-0.4 then 10% accept - 90% reject
if percent shift=-0.5 then 0% accept - 100% reject
Thanks!
  2 commentaires
Walter Roberson
Walter Roberson le 10 Mar 2019
If the percent_shift is 0.4 then you total 110% probability.
william Smith
william Smith le 10 Mar 2019
sorry typo erro

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Mar 2019
rand() < (percent_shift + 0.5)
  5 commentaires
Walter Roberson
Walter Roberson le 10 Mar 2019
The assignment to i before the function definition is in a different workspace than the function uses. Inside your function, both i (lower-case I) and l (lower-case L) are undefined. You also switch back and forth between using i or l as the subscript.
You assign a value to choice_ in the case of bias 0.5 but you never use that variable.
You only assign a value to the output variable choice_1 in the case that the input bias is -0.5
You try to test 0.5 and -0.5 for equality using = as the comparison operator, but = is only ever assignment (except some cases having to do with older versions of the symbolic toolbox.) == is the comparison test.
You input customer_1 but you never use it.
You use choice_1 to pass a size argument to rand() but you have not defined choice_1 by that point.
It is not clear what your intended output is. Is it the random variable such as 0.013433807 ? Is it 0.0 or 0.1 (double precision numbers) ? Is it uint8(0) or uint8(1) ? Is it false or true (logical values) ?
Why are you indexing bias? Are you expecting it to be a vector of values?
Each of your cases appears to have the same action except for 0.5 and -0.5 . Why not just test those two specifically, like
if bias(i) == 0.5
choice_ = 1;
elseif bias(i) == -0.5
choice_1 = 0;
else
rand(choice_1) < (bias(i) + 0.5)
end
william Smith
william Smith le 10 Mar 2019
Awsesome!
Thank you so much!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by