Frage

I have channel measurements which has values > 20,000, which has to be divided into discrete levels, as in my case K=8 and which has to be mapped to channel measurements with states. I have to find state-transition probability matrix for this in Matlab.

My question is, I need to know how to divide these values into 8 states and to find the state-transition probability matrix for these 8 states in Matlab.

War es hilfreich?

Lösung

Here is a made-up example:

%# some random vector (load your data here instead)
x = randn(1000,1);

%# discretization/quantization into 8 levels
edges = linspace(min(x),max(x),8+1);
[counts,bins] = histc(x, edges);

%# fix last level of histc output
last = numel(counts);
bins(bins==last) = last - 1;
counts(last-1) = counts(last-1) + counts(last);
counts(last) = [];

%# show histogram
bar(edges(1:end-1), counts, 'histc')

%# transition matrix
trans = full(sparse(bins(1:end-1), bins(2:end), 1));
trans = bsxfun(@rdivide, trans, sum(trans,2));

A few things to note:

  • Discretization is performed simply by dividing the whole range of data into 8 bins. This is done using histc. Note that due to the way the function works, we had to combine the last two counts and fix the bins accordingly.

  • the transition matrix is computed by first counting the co-occurrences using a less-known call form of the sparse function. The accumarray could have also been used. The count matrix is then normalized to obtain probabilities that sum to one.

  • You mentioned that your MC model should only allow transitions between adjacent states (1 to 2 or 8 to 7, but not between 2 and 5). I did not enforce this fact since this should be a property of the data itself, which is not applicable in this example with random data.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top