필터 지우기
필터 지우기

Matlab Help: Matrix Reduction Algorithm ???

조회 수: 2 (최근 30일)
Usman  Ali
Usman Ali 2012년 5월 7일
답변: mehrdad 2013년 11월 9일
hello every one.. i am a bit new to matlab so have no vocabulary of commands or how thing work as vector matrices or etc etc.. so i would like to develop a prototype or an algorithm for scenario reduction in matlab( each row of a matrix is called as single scenario).
the steps of this algorithms are
1) for any given matrix, find the distance matrix which show euclidean distance between each and every row of original matrix.
2) find the min: value in distance matrix.
3) delete that row with min elemenet value and with min: probabilty of occurance.
4) construct seperate matrix which contain only these deleted rows
5) reconstruct distance matrix with preserved row (without deleted rows).
6) repeat untill the desired numb of rows are preserved.
So I started with a simple 3x3 matrix and i wrote few lines as follow.
--------------------------------------
% suppose any matrix e.g
x=[5 3 1; 2 5 6; 1 3 2];
dist_mat = squeeze(sqrt(sum(bsxfun(@minus,x,reshape(x',1,size(x,2),size(x,1))).^2,2)));
dist_mat(~dist_mat)=inf;
row_min = min(dist_mat);
min_value = min (row_min);
[r c]= find(d==min_value); % shows the position of the minimum element, r= which row and c= which column
so the results i get are
d =
Inf 6.1644 4.1231
6.1644 Inf 4.5826
4.1231 4.5826 Inf
min_value =
4.1231
r =
3
1
c =
1
3
thanks to 'Sean de Wolski' for correcting the dist_mat command.
in my e.g, the min value is in [3,1] and [1,3]. i.e D13=D31, this is correct.
let every row has its own probability, i.e P1= 0.2, P2=0.4, P3=0.4 (total P=1) since the min value = 4.1231 lying in 1st and 3rd row, we can delete either Row1 or Row3, but since the probabilty of Row1 < Row3 so row1 should be selected for deletion. i do not have any thing in mind how to delete this row, rearrange the dist_mat and write a new mat with this deleted row.
I m really sorry for so long post but i wanted to make thing more clear... i hope to get some +ve responses...
Thanks alot in Advance

채택된 답변

Johann
Johann 2012년 8월 8일
편집: Johann 2012년 8월 16일
Hello Usman Ali,
the following code works for me:
% scennum_fav is the favored scenario number after reduction
scennum_fav=250;
% Initial scenario numbers, my matrix to be reduced is CO2_scen [1000x234]
scennum_int=size(CO2_scen,1);
% In the beginning all scenarios are equiprobable
scenprob=ones(scennum_int,1)*1/scennum_int;
% scenario reduciton algorithm
while size(CO2_scen,1)>scennum_fav
% Calculate euclidean distances
dist_mat = queeze(sqrt(sum(bsxfun(@minus,CO2_scen,reshape(CO2_scen',1,size(CO2_scen,2),size(CO2_scen,1))).^2,2)));
dist_mat(~dist_mat)=inf;
row_min = min(dist_mat);
min_value = min (row_min);
[row column]= find(dist_mat==min_value); % shows the position of the minimum element, r= which row and c= which column
% Remove scenario with smallest distance and adding its probability to reference scenario (the scenario to be removed is independent of its probability)
if scenprob(row(1))>scenprob(row(2))
CO2_scen(row(2),:)=[];
scenprob(row(1),:)=scenprob(row(1),:)+scenprob(row(2),:);
scenprob(row(2),:)=[];
elseif scenprob(row(1))<scenprob(row(2))
CO2_scen(row(1),:)=[];
scenprob(row(2,:))=scenprob(row(2,:))+scenprob(row(1,:));
scenprob(row(1),:)=[];
else
CO2_scen(row(2),:)=[];
scenprob(row(1,:))=scenprob(row(1,:))+scenprob(row(2,:));
scenprob(row(2),:)=[];
end
end
I hope this was helpful even though your question was a few month ago. Johann
  댓글 수: 2
mehrdad
mehrdad 2013년 7월 3일
Dear Johann,
This is Kantrovich Method?
Johann
Johann 2013년 7월 19일
Dear mehrdad,
unfortunately I dont know Kantrovich.

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

추가 답변 (1개)

mehrdad
mehrdad 2013년 11월 9일
Dear Johann,
In your code ,you define: scennum_fav=250,in your idea how can add Stopping rule for scenario reduction,means,the code ,automatically after done optimization,given the scennum_fav (not given the scennum_fav as input).
Thank you ,

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by