extension of symbols or probabilities
조회 수: 2 (최근 30일)
이전 댓글 표시
i am having this p=[ 0.3,0.25, 0.20, 0.10, 0.05, 0.04, 0.04, .02]; these are 8 symbols suppose A,B,C,D,E,F,G,H
now i want to extend these from 8 to 64
how to do that? using these above probabilities
댓글 수: 4
답변 (4개)
Walter Roberson
2013년 6월 2일
My guess at what you want is
oldx = linspace(0,1,8);
newx = linspace(0,1,64);
newp = interp1(oldx, p, newx);
plot(oldx, p, 'b.', newx, newp, 'g')
The new entries will be linear interpolations of the old ones. You might prefer to use a non-linear interpolation.
댓글 수: 1
Walter Roberson
2013년 6월 2일
ndim = 3; %8 to the how many?
[t{1:ndim}] = ndgrid(p);
newp = prod(cat(ndim+1, t{:}), ndim+1);
The answers are now in the n-dimensional matrix newp; e.g., BDH is newp(2,4,8)
Azzi Abdelmalek
2013년 6월 2일
편집: Azzi Abdelmalek
2013년 6월 2일
s='A':'H'
p=[ 0.3,0.25, 0.20, 0.10, 0.05, 0.04, 0.04, .02]
idx=arrangement(1:8,2)
new_s=s(idx)
new_p=prod(p(idx),2)
out=[cellstr(new_s) num2cell(new_p)]
%-----------------------------------------------------------------
function y=arrangement(v,n)
m=length(v);
y=zeros(m^n,n);
for k = 1:n
y(:,k) = repmat(reshape(repmat(v,m^(n-k),1),m*m^(n-k),1),m^(k-1),1);
end
댓글 수: 5
Walter Roberson
2013년 6월 3일
The A[sub n][super k] given in that article is the same as the P(n,k) in Permutations, and your formula looks to me like the probability mass function of the Multinomial Distribution
I haven't worked through to see if your formula is correct. Even if it is, I would think that the version I gave in my answer (starting with "ndim = 3" is a lot easier to understand. Yours might require a factor of ndim less memory, though.
Image Analyst
2013년 6월 2일
My guess at what he wants:
probabilityTable = p' * p
probabilityTable =
0.09 0.075 0.06 0.03 0.015 0.012 0.012 0.006
0.075 0.0625 0.05 0.025 0.0125 0.01 0.01 0.005
0.06 0.05 0.04 0.02 0.01 0.008 0.008 0.004
0.03 0.025 0.02 0.01 0.005 0.004 0.004 0.002
0.015 0.0125 0.01 0.005 0.0025 0.002 0.002 0.001
0.012 0.01 0.008 0.004 0.002 0.0016 0.0016 0.0008
0.012 0.01 0.008 0.004 0.002 0.0016 0.0016 0.0008
0.006 0.005 0.004 0.002 0.001 0.0008 0.0008 0.0004
It's a 2D table of the probability of that pair, so you just enter in the two letters as indexes. For example, probabilityTable(1,1) = 0.03 * 0.03 = 0.009 just like he wanted. Of course you could convert to a 1D table if you wanted:
probabilityTable = probabilityTable(:);
댓글 수: 2
Image Analyst
2013년 6월 3일
You're right. I didn't notice at first because I saw the reshape(). I actually think it's more convenient to use the 2D version than the 1D version which he requested.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!