Re: random distribution of number sequences
- From: John D'Errico <woodchips@xxxxxxxxxxxxxxxx>
- Date: Wed, 17 Aug 2005 13:18:54 GMT
In article <ef113aa.1@xxxxxxxxxxxxxxxx>, Hubsi <huebchen@xxxxxx> wrote:
> thanx a lot!
> your right, it was my fault! i have mistake 1 for 0. Now i ll try it
> once more:
> i need a function (for a drop out function) which consists of ones
> and zeros. the percentage of zeros / ones can be entered. for
> example: 70% ones and 30% zeros. these 30% zeros are again divided
> into different percentages of sequences of zeros. for example: 5% of
> [0], 10% of [0 0], and so on, up to 100% of the 30% zeros. the
> sequences should be stochastical (within the 30%).
> i hope my question is now understandable...
Yeah, but I like your other question better. It was soooo
easy to answer. ;-) This question is not so easy.
I'd start by focusing on the sub-sequence order of "arrival"
and the total number of subsequences. If we know the total
number of sub-sequences, then we can back out the total
expected sample time, or go in the other direction.
So if we choose to sample n sub-sequences of all zeros,
suppose they will have lengths and probabilities:
sequence_lengths = [1 2 3 4];
P_zero = [.4 .2 .3 .1];
Now choose the order of n sub-sequences.
n = 500;
r = rand(1,n);
[junk,sind] = histc(r,cumsum([0,P_zero]));
seq_len = sequence_length(sind);
The total number of zeros in all of these sequences
will be sum(seq_len). So we can compute the total
length of the overall sequence as (approximately)
fraction_zero = 0.3;
overall_length = sum(seq_len)/fraction_zero;
We need to step back here and consider our goals
again. What is the distribution of ones between
sub-sequences of zero? There can be subtle variations
in our choice here. I'll be arbitrary though.
total_ones = overall_length - sum(seq_len);
Lets build up the complete sequence. Partition the
ones in our sequence into random chunks, a total of
n+1 of them. What I really want here is a partition
of the integer total_ones into exactly n+1 positive
integers. The approach I take here is a hack.
seq_ones = round(diff(sort(rand(1,n+1)*total_ones)));
seq_ones(seq_ones==0) = 1;
Now lets build up the complete sequence.
sequence = ones(1,sum(seq_len) + sum(seq_ones));
L = 0;
for i = 1:n;
L = L + seq_ones(i);
sequence(L+(1:seq_len(i))) = 0;
L = L + seq_len(i);
end
As a check, the total nomber of ones should be roughly
70% of the overall sequence.
sum(sequence)/3559
ans =
0.7036
At this point, feel free to shorten the sequence, or
append more to get a sequence of a given length.
John
--
The best material model of a cat is another, or
preferably the same, cat.
A. Rosenblueth, Philosophy of Science, 1945
.
- References:
- random distribution of number sequences
- From: Hubsi
- Re: random distribution of number sequences
- From: John D'Errico
- Re: random distribution of number sequences
- From: Hubsi
- random distribution of number sequences
- Prev by Date: PULSTRAN
- Next by Date: Re: cdma demonstration
- Previous by thread: Re: random distribution of number sequences
- Next by thread: Re: random distribution of number sequences
- Index(es):
Relevant Pages
|
Loading