分享

LSA

 lzqkean 2013-07-22

1) Term Document矩阵进行svd, 得到 TSD'     

 

2) 对于新文档构成的列向量Q, 计算其文档坐标 Dq=Q'TS"

 

3) Dq 与 DS的行向量计算夹角, 判断距离

 

因此看, LSA的作用是进行相关性判断

 

SVD的作用: 降维。 降维的同时达到了潜在语义索引的目的。

 

SVD、降维之后得到近似term document矩阵A

A*A'中的元素(i,j)表示第iterm与第jterm的相关性

A'*A中的元素(i,j)表示第idoc与第jdoc的相关性

A = TSD = TSh (DSh)' 中的元素(i,j)表示第iterm在各个doc中的权重   Sh表示S1/2

 

可以采用TS DS从而不用计算A*A'的方式完成所有计算


  1.  Matrix trainMatrix = new Matrix(trainValues);    //Term Document  
  2.  // svd requires rows >= columns, so transpose data if necessary  
  3.  if (m_numAttributes < m_numInstances) {  
  4.    m_transpose = true;  
  5.    trainMatrix = trainMatrix.transpose();  
  6.  }  
  7.  SingularValueDecomposition trainSVD = trainMatrix.svd();  
  8.  m_u = trainSVD.getU(); // left singular vectors  
  9.  m_s = trainSVD.getS(); // singular values  
  10.  m_v = trainSVD.getV(); // right singular vectors  
  11.    
  12.  // find actual rank to use  
  13.  int maxSingularValues = trainSVD.rank();  
  14.  for (int i = 0; i < m_s.getRowDimension(); i ) {  
  15.    m_sumSquaredSingularValues  = m_s.get(i, i) * m_s.get(i, i);  
  16.  }  
  17.  //TODO 计算、得到要求的特征值个数及其值。 特征值个数保存在m_actualRank中  
  18.    
  19.  // lower matrix ranks, adjust for transposition (if necessary), and  
  20.  // compute matrix for transforming future instances  
  21.  if (m_transpose) {  
  22.    Matrix tempMatrix = m_u;  
  23.    m_u = m_v;  
  24.    m_v = tempMatrix;  
  25.  }  
  26.  //降维。。。。。。。。  
  27.  m_u = m_u.getMatrix(0, m_u.getRowDimension() - 1, 0, m_actualRank - 1);  
  28.  m_s = m_s.getMatrix(0, m_actualRank - 1, 0, m_actualRank - 1);  
  29.  m_v = m_v.getMatrix(0, m_v.getRowDimension() - 1, 0, m_actualRank - 1);  
  30.   
  31.  //what。。。???  
  32. /** Will hold the matrix used to transform instances to the new feature space */  
  33.  // Dq=Q'TS", 得到文档q在new space中的坐标. 该式从何而来???  
  34.  //TS" 作何理解?  DS" 作何理解?  "表示求逆  
  35.  m_transformationMatrix = m_u.times(m_s.inverse());  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多