フィルターのクリア

Hi ...how to generate transition probability matrix using markov property for acceleration and velocity ?

2 ビュー (過去 30 日間)
I want to generate a transition probability matrix for acceleration and velocity ,but the problem is I don't have data for acceleration and velocity so I want to use rand command to generate a random values.I already found a code for acceleration and velocity data but in this code they have loaded a data and from that data they generate the TPM matrix .But in my case I want to use a rand command for accel and velocity in order build the TPM matrix .How can I do it?Thank you.
function transMat = mwExample
load('Sample data set mathworks.mat')
%%First bin data into categories
speedBinN = 5;
aceelBinN = 5;
speed = binit( data(:,2), linspace(min(data(:,2)),max(data(:,2)),speedBinN) ); % bin them into categories
accel = binit( data(:,3), linspace(min(data(:,3)),max(data(:,3)),aceelBinN) );
%%count up transitions
transCountMat = zeros(speedBinN,aceelBinN,speedBinN,aceelBinN);
for ii = 1:size(data,1)-1
transCountMat( speed(ii),accel(ii),speed(ii+1),accel(ii+1) ) = transCountMat( speed(ii),accel(ii),speed(ii+1),accel(ii+1) ) + 1;
end
%%calculate probabilities
sumOverPossibleDestinations = sum( sum(transCountMat, 4), 3);
transMat = bsxfun( @rdivide, transCountMat, sumOverPossibleDestinations )

回答 (1 件)

Sarah Mohamed
Sarah Mohamed 2018 年 1 月 3 日
Assuming 'data' contains the speed and acceleration loaded from the sample file, you can build a matrix of uniformly distributed random numbers using the 'rand' function.
It looks like 'data' is just a 2D matrix. If column 2 of 'data' contains the speed and column 3 contains the acceleration, you could create a random 2D matrix with three columns via:
data = rand(100, 3);
For more on this function, you may refer to the documentation link below:
  2 件のコメント
Harini pushparaj
Harini pushparaj 2018 年 1 月 4 日
@ Sarah Mohamed ...Thank you so much for the reply..I tried that way initally but it showed me error saying
Index exceeds matrix dimensions.
Error in markov (line 9)
transCountMat( speed(ii),accel(ii),speed(ii+1),accel(ii+1) ) = transCountMat(
speed(ii),accel(ii),speed(ii+1),accel(ii+1) ) + 1;
Harini pushparaj
Harini pushparaj 2018 年 1 月 4 日
This was my code ..what should I modify to attain the probability matrix
data = rand(100, 3)
speedBinN = 5;
aceelBinN = 5;
speed = histc( data(:,2), linspace(min(data(:,2)),max(data(:,2)),speedBinN) ); % bin them into categories
accel = histc( data(:,3), linspace(min(data(:,3)),max(data(:,3)),aceelBinN) );
%%count up transitions
transCountMat = zeros(speedBinN,aceelBinN,speedBinN,aceelBinN);
for ii = 1:size(data,1)-1
transCountMat( speed(ii),accel(ii),speed(ii+1),accel(ii+1) ) = transCountMat( speed(ii),accel(ii),speed(ii+1),accel(ii+1) ) + 1;
end
%%calculate probabilities
sumOverPossibleDestinations = sum( sum(transCountMat, 4), 3);
transMat = bsxfun( @rdivide, transCountMat, sumOverPossibleDestinations )

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMarkov Chain Models についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by