Pseudorandom sequence with costrains with frequent and infrequent elements
Afficher commentaires plus anciens
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
the cyclist
le 10 Jan 2023
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.)
Alice B
le 11 Jan 2023
Réponses (1)
John D'Errico
le 10 Jan 2023
Modifié(e) : John D'Errico
le 10 Jan 2023
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])
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
Alice B
le 11 Jan 2023
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!