2

是否有可能将零替换为A1,将 1替换为 0,其A概率固定但不同?

例如:

A = [0 1 1 0 1 0 1 0]我想用概率 1/4 用 1 替换 0,用概率 1/3 用 0 替换 1。

我正在尝试这样的事情,但它不适用于概率。我这里的数组是Sent,它的 0 和 1 不是均匀分布的,但有一定的概率(3/7 的 0 和 4/7 的 1),它被捕获在Sent变量中,但现在我需要将它更改为Received,它有不同的可能性。

prob=3/7; 
n=100;
pdatodo=1/3;
pdotoda=1/4;
Sent=rand(n,1)>prob;
Received=Sent;
Sent(Received == 0) = 1>pdotoda; Sent(Received == 1) = 0>pdatodo;
4

2 回答 2

2
A = [0,1,1,0,1,0,1,0]

%// first remember the positions of the orginal 1s and 0s
i0 = find(A==0); 
i1 = find(A==1);

p0to1 = 1/4;
p1to0 = 1/3;

%//Create the replacements vectors that will have the size of the original number of 0s and 1s respectively
r0to1 = rand(size(A(i0))) < p0to1;
r1to0 = rand(size(A(i1))) < p1to0

%//Put the replacement vectors in the correct indices (found at the start)
A(i0(r0to1)) = 1;
A(i1(r1to0)) = 0;
于 2013-09-30T06:45:34.040 回答
1
A = [0,1,1,0,1,0,1,0];
p1to0 = 1/3;
p0to1 = 1/4;

%// Find transition probability for each element
transitionProb = A*p1to0 + (1-A)*p0to1;

%// Flip the bits with corresponding ptransition probability
A = xor(A, rand(size(A)) < transitionProb);

您可以通过将概率设置为零(期望没有变化)和一(期望所有位都被翻转)来测试这一点。

于 2013-09-30T08:33:29.250 回答