Pseudorandom sequence with costrains with frequent and infrequent elements

Hello everyone,
I would need to create a sequence in pseudorandom order. In this sequence I have a vector of 150 elements, formed by two values :one frequent , present 70% of the times and one infrequent present 30% of the times. I want to create a pseudorandom order in which the infrequent element is preceded by at least two frequent elements. How can I do this?
vector_to_rand= repmat({'frequent' 'frequent' 'frequent' 'frequent' 'frequent' 'frequent' 'frequent' 'infrequent' 'infrequent' 'infrequent'},1,15);

2 commentaires

I have two questions:
  • In the sequence of 150 elements, do you want 70% frequent values for every sequence generated, or just on average statistically across all the generated sequences?
  • Is the "two frequent values must precede the infrequent value" something that just applies to the sequence as a whole, or does it apply to each instance of the infrequent value within the sequence? (Your repmat-generated sequence violates the latter requirement.)
Hi,
  • I need that the 70% frequent values is maintained for every sequence generated.
  • I need that al least two frequent values must precede an infrequent value bu it could be also three or five or more, like in "random" way.
Thank for any help you could provide.

Connectez-vous pour commenter.

Réponses (1)

Simple.
Start with the requirement. You have a sequence where you want 150 elements, 30% of them to be the infrequent case. But ALWAYS , the infrequent case MUST be proceeded by two of the frequent ones. I'll pick 1 and 0 for the two cases, with zero being the frequent one.
seq = repmat([0 0 1],[1,45])
seq = 1×135
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1
There are 135 elements in that sequence. Biut you want 150 total elements. So just insert 15 more zeros. Is it peseudo-random? Just barely so, but you have left me with almost no flexibility for more randomness than that.
Or, I suppose you might have started with a random number of 001 segments. Use randi to decide now many 1 eleemtns you want, all totaled. Then insert some number of additional zeros to get to a total sequence length of 150. And, yes, I suppose you will then ask me how to insert elements into a vector. One simple solutino is to use this tool from the file exchange:

1 commentaire

Thanks for your response but in this way I get a not pseudrandom sequence, my idea is then to use
rand_vector=vector_to_rand(randperm(150));

Connectez-vous pour commenter.

Produits

Question posée :

le 10 Jan 2023

Commenté :

le 11 Jan 2023

Community Treasure Hunt

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

Start Hunting!

Translated by