estimation probability over the part of an array

조회 수: 14 (최근 30일)
terance
terance 2011년 5월 24일
[EDIT: 20110524 10:11 CDT - reformat - WDR]
Hello!
I have an array of data and I want to estimate the mean probability over the window of this array. I wrote the following code, but it shows me zeros except the last window of an array.
function y=pm(x,length)
for i=1:size(x)-length
m=mean(x(i:i+length));
s=std(x(i:i+length));
k(i)=probability_estimate(x(i:i+length),m,s);
end;
y=k;
end
function y=probability_estimate(x,m,s)
for i=1:length(x)
k(i)=lognpdf(x(i),m,s);
end;
y=mean(k);
end
>>d=pm(x,length);
would you be so kind to explain to me how to correct this code? Thank you for your answers!

답변 (4개)

Andrei Bobrov
Andrei Bobrov 2011년 5월 24일
function y=probability_estimate(x,m,s)
y=mean(lognpdf(x,m,s));
end
EDIT
idxs = bsxfun(@plus,1:l,(0:length(x)-l)');
outcell = arrayfun(@(y)mean(lognpdf(x(idxs(y,:)),...
mean(x(idxs(y,:))),std(x(idxs(y,:))))),1:size(idxs,1),'un',0);
d = [outcell{:}]';
your "length" -> "l"
with loop:
s1 = size(idxs,1);
d = zeros(s1,1);
for j = 1:s1
y = x(idxs(j,:));
d(j) = mean(lognpdf(y),mean(y),std(y));
end
  댓글 수: 1
terance
terance 2011년 5월 24일
spasibo za otvet!a vi mojete poyasnit etot kod?mne ne yasno chto meniat' nyjno?

댓글을 달려면 로그인하십시오.


terance
terance 2011년 5월 24일
still isn't solved((

Walter Roberson
Walter Roberson 2011년 5월 24일
size(x) is a two-element array. i=1:size(x)-length is not going to do what you want. Are you working with an array or with a row vector or with a column vector?
Also, please do not use a variable named "length" as you are very likely to run in to difficulties with the function of that name.
  댓글 수: 1
terance
terance 2011년 5월 24일
I'm working with an 1 dimensional array.
I have a sample, named x(e.x. x=[1 2 3 4 5 6 7]) and I need to estimate the following:
1)I choose th size of the window (length=2,step=1), so I have the following windows: [1 2], [2 3] [3 4] [4 5] [5 6][6 7]
2)over each window, I have to calculate the probability of each window-element and then returnn the mean of the probabilities of each elements in the window (the probability is log-normal, with mean over the window and std over the window)

댓글을 달려면 로그인하십시오.


terance
terance 2011년 5월 24일
problem is solved, here is the corrected code (thx god for debugging!=))
function y=pm(x,L)
a=length(x);
for i=1:a-L
m=mean(x(i:i+L));
s=std(x(i:i+L));
k(i)=probability_estimate(x(i:i+L),m,s);
end;
y=k;
end
function y=probability_estimate(x,m,s) for z=1:length(x) k(z)=normcdf(x(z),m,s); end; y=mean(k); end

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by