其他分享
首页 > 其他分享> > MHT代码阅读(4)

MHT代码阅读(4)

作者:互联网

MHT代码阅读(4)

4. generateGlobalHypothesis

4.1 论文内容

在这里插入图片描述

4.2 代码阅读

  1. 初始化
    • clustersNo:族群数量
    • bestHypothesis:最好假设
    • bestScore:最高得分
    • trackIndexInTrees:轨迹序号
    • selectedTrackIDs:选择的轨迹ID
  2. 进入外循环(循环次数是clustersNo的大小)
    • 初始化 adjacencyMat(邻接垫):最后一行和最后一列当哑结点
    • 初始化 weightMat(权重垫):第一行最后一列的元素当作哑结点
    • 初始化 trackIndexInTrees{i,1}
    • 初始化 nodesNo=size(clusters{i},1):第i个族群的根节点数、可以理解为第i个族群的轨迹的数量?(其中r=size(A,1)该语句返回的是矩阵A的行数, c=size(A,2) 该语句返回的是矩阵A的列数)
    • 进入内循环(循环次数是nodesNo的大小)
      1. 初始化 familyID1,leafNodeInd1,IDsel,trackID,index1,trackIndexInTrees{i,1}(index1,:)
      2. 分配节点权重
      3. 分数错误修复
      4. [此处有疑问]:初始化ICL(不兼容轨迹树集),如果ICL只有一行,进入判断,如果index1 ~= index2则报错;
      5. 进入判断,直到 compatibleTracksID 非空为止,如果两个轨道兼容,则分配 1。
      6. 退出内循环
    • 将隔离节点连接到虚拟节点。
    • 对角线设置为0
    • 错误检查

4.3 代码附录

function [bestHypothesis,bestScore,trackIndexInTrees,selectedTrackIDs]=...
    generateGlobalHypothesis(scoreTreeSet,idTreeSet,...
    incompabilityListTreeSet,clusters,ICL_clusters,other_param)
    
    %初始化
    clustersNo=length(clusters);
    bestHypothesis=cell(clustersNo,1);
    bestScore=cell(clustersNo,1);
    trackIndexInTrees=cell(clustersNo,1);
    selectedTrackIDs=[];
    if clustersNo == 0    
        return
    end
    %进入循环
    for i=1:clustersNo
       adjacencyMat=zeros(other_param.currentTrackNo(i)+1, other_param.currentTrackNo(i)+1);  % the last row and column for the dummy node 最后一行和最后一列当哑结点
       weightMat=zeros(1, other_param.currentTrackNo(i)+1);    % the last element for the dummy node 第一行的最后一列的元素当作哑结点
       trackIndexInTrees{i,1}=zeros(other_param.currentTrackNo(i),2);   
       nodesNo=size(clusters{i},1); %其中r=size(A,1)该语句返回的是矩阵A的行数, c=size(A,2) 该语句返回的是矩阵A的列数
       %进入内循环
       for j=1:nodesNo            
          familyID1=clusters{i}(j,1);
          leafNodeInd1=clusters{i}(j,2);
          IDsel=idTreeSet(familyID1).get(leafNodeInd1);
          trackID=IDsel(2);
          index1=find(ICL_clusters{i} == trackID);
          trackIndexInTrees{i,1}(index1,:)=[familyID1 leafNodeInd1];

          % assign a node weight   分配节点权重  
          if weightMat(index1) ~= 0
              error('something wrong happend in the weight matrix');
          end
          scoreSel=scoreTreeSet(familyID1).get(leafNodeInd1);
          % score bug fixed 分数错误修复
          if scoreSel(1) > 1.1*(1/other_param.const)
               weightMat(index1)=scoreSel(1);
          else
               weightMat(index1)=1.1*(1/other_param.const);
          end      
          ICL=incompabilityListTreeSet(familyID1).get(leafNodeInd1);  
          if size(ICL,1) == 1 
               index2=find(ICL_clusters{i} == ICL(2));           
               compatibleTracksID=ICL_clusters{i}(ICL_clusters{i} ~= ICL(2));
               if index1 ~= index2
                  error('error happened in the ICL of the confirmed track'); 
               end
          else         
               [compatibleTracksID, index2]=setdiff(ICL_clusters{i},ICL(:,2),'rows');
               index2=index2';
          end
          if isempty(compatibleTracksID)
              continue;
          end
          % assign 1 if two tracks are compatible 如果两个轨道兼容,则分配 1
          adjacencyMat(index1,index2)=1;
       end
       weightMat=other_param.const*weightMat;
       % connect an isolated node to a dummy node. 将隔离节点连接到虚拟节点。
       % NOTE : A single node is not considered as a clique in Cliquer.    注意:在 Cliquer 中,单个节点不被视为集团。  
       weightMat(end)=1.1; 
       index=find(sum(adjacencyMat(1:end-1,1:end-1)') == 0);%哪一列的和是0
       for k=index
           adjacencyMat(k,end)=1;
           adjacencyMat(end,k)=1;
       end
       % set the diagonal terms to zero 对角线设置为0
       adjacencyMat(logical(eye(size(adjacencyMat))))=0;
       % error check 错误检查
       if ~isequal(adjacencyMat,adjacencyMat')
           error('the adjacency matrix is not symmetric');
       end
       if length(weightMat)<50
           bestHypothesis_tmp=CliqueFunc3(adjacencyMat, weightMat);
       else
           bestHypothesis_tmp=mcts_main(adjacencyMat, weightMat);
       end
       
%        try 
%            bestHypothesis_tmp=CliqueFunc3(adjacencyMat, weightMat);
%        catch
%            bestHypothesis_tmp=mcts_main(adjacencyMat, weightMat);
%            disp("hhh")
%        end
       
%        if ((size(adjacencyMat,1)>50 && sum(sum(adjacencyMat))/size(adjacencyMat,1)^2 > 0.5))||(size(adjacencyMat,1)>80)
%            disp('aaa')
%            bestHypothesis_tmp=mcts_main(adjacencyMat, weightMat);%使用启发式搜索
%        else
%            bestHypothesis_tmp=CliqueFunc3(adjacencyMat, weightMat);%使用精确算法 
%        end
       bestHypothesis_tmp=bestHypothesis_tmp(:,1:end-1);
       weightMat=weightMat(1:end-1);
       if size(bestHypothesis_tmp,1) > 1
            bestTracks=~~sum(bestHypothesis_tmp);
       else
            bestTracks=bestHypothesis_tmp;
       end
       index=find(bestTracks == 1);
       selectedTrackIDs_tmp=zeros(length(index),1);
       for k=1:length(index)
           IndSel=trackIndexInTrees{i,1}(index(k),:);
           IDSel=idTreeSet(IndSel(1)).get(IndSel(2));
           selectedTrackIDs_tmp(k)=IDSel(2);
       end
       selectedTrackIDs=[selectedTrackIDs; selectedTrackIDs_tmp];
       score=zeros(size(bestHypothesis_tmp,1),1);
       for k=1:size(bestHypothesis_tmp,1)
            score(k)=sum(weightMat(logical(bestHypothesis_tmp(k,:))));
       end
       [~, index_tmp]=max(score);   
       bestHypothesis{i,1}=bestHypothesis_tmp(index_tmp,:);
       bestScore{i,1}=weightMat;
    end
end

标签:tmp,end,假设,代码,weightMat,bestHypothesis,阅读,adjacencyMat,MHT
来源: https://blog.csdn.net/qq_43456781/article/details/120516645