按特征向量对特征向量排序(关联排序) [英] Sorting eigenvectors by their eigenvalues (associated sorting)

查看:157
本文介绍了按特征向量对特征向量排序(关联排序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个未分类的特征值向量和一个相关的特征向量矩阵.我想针对特征值的排序集对矩阵的列进行排序.(例如,如果eigenvalue [3]移至eigenvalue [2],我希望特征向量矩阵的第3列移至第2列.)

I have an unsorted vector of eigenvalues and a related matrix of eigenvectors. I'd like to sort the columns of the matrix with respect to the sorted set of eigenvalues. (e.g., if eigenvalue[3] moves to eigenvalue[2], I want column 3 of the eigenvector matrix to move over to column 2.)

我知道我可以通过 std :: sort O(N log N)中对特征值进行排序.不用滚动我自己的排序算法,如何确定矩阵的列(相关的特征向量)以及它们的特征值在排序时就遵循了?

I know I can sort the eigenvalues in O(N log N) via std::sort. Without rolling my own sorting algorithm, how do I make sure the matrix's columns (the associated eigenvectors) follow along with their eigenvalues as the latter are sorted?

推荐答案

通常只创建一个类似这样的结构:

Typically just create a structure something like this:

struct eigen { 
    int value;
    double *vector;

    bool operator<(eigen const &other) const { 
        return value < other.value;
    }
};

或者,将特征值/特征向量放入 std :: pair 中-尽管我更喜欢 eigen.value eigen.vector something.first something.second .

Alternatively, just put the eigenvalue/eigenvector into an std::pair -- though I'd prefer eigen.value and eigen.vector over something.first and something.second.

这篇关于按特征向量对特征向量排序(关联排序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆