문제

I'm having trouble determining the probability of transitions to a bin in MatLab.

I have two long sequences of x,y coordinates:

-73.9613487200000   -46.5918895000000
-74.3247836300000   -46.3739157100000
-74.1687114000000   -45.9507475300000
-74.0608490800000   -45.7491954000000
-74.1341642000000   -45.0915414400000
-73.8393784300000   -44.6707425700000
-73.8145227800000   -44.4084257500000
-74.5435599500000   -43.7561156500000
-74.2601082600000   -43.3275746200000
-74.5393861400000   -42.6844697600000
-74.1746965800000   -42.4732404300000
-73.8951934100000   -42.1678074600000
-73.7448163600000   -41.7981857300000
-73.4435398100000   -41.8730435200000
....

with the goal of determining the probability of transitioning to a bin (e.g., x>90 x<100 & y>90 y<100) from any previous bin. To be clear, I'd like to eventually create a matrix of probability values in every 10x10 bin.

Defining the bin size and sorting the data is easy enough

xbins = -100:10:100;
ybins = -100:10:100;
xNumBins = numel(xbins); yNumBins = numel(ybins);

but mostly I may be having a problem with indexing.

Thank you for any help/suggestions.

도움이 되었습니까?

해결책

So to start with you need to transform you data matrix to a binned data matrix, B (or basically just bin all the data). You can do it like this:

bins = -100:10:100;
B = arrayfun(@(x)find(x<=bins,1,'first')-1,data);

Now you need to count the transistions and create a grid. You can do this simply by going T = accumarray(B,1) but for understanding here is is as a for loop:

n = numel(bins)-1;
T = zeros(n);
for k = 1:size(B,1)
    T(B(k,1),B(k,2)) = T(B(k,1),B(k,2)) + 1;
end

and then to convert from this sort of joint histogram to a probability matrix

T = T/sum(T(:))

example:

a = rand(10,2)

a =

    0.0534    0.1632
    0.8664    0.4751
    0.3270    0.6687
    0.2016    0.4313
    0.8158    0.6065
    0.8493    0.4217
    0.3997    0.3960
    0.5845    0.1684
    0.5499    0.3672
    0.5886    0.4045

and

bins = 0:0.2:1;

do the calc:

B = arrayfun(@(x)find(x<=bins,1,'first')-1,data);
T = accumarray(B,1,[numel(bins)-1, numel(bins)-1])/size(B,1);

T =

    0.1000         0         0         0         0
         0    0.1000    0.1000    0.1000         0
    0.1000    0.1000    0.1000         0         0
         0         0         0         0         0
         0         0    0.2000    0.1000         0

which is correct. You can see that 20% of the data transition from bin 5 to bin 3 for example and that corresponds to rows 2 and 6 from my a matrix above.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top