필터 지우기
필터 지우기

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 CenterFile Exchange에서 Markov Chain Models에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by