Coder Social home page Coder Social logo

clustering's People

Contributors

pthimon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

clustering's Issues

We need the Eigenvalue/Eigenvectors of the Laplacian, not the affinity matrix

Hi,

there is a little mistake in your implementation, for the spectral clustering, the laplacian has to be calculated from the affinity matrix and then the eigenvalue decomposition follows. Should be:

SpectralClustering::SpectralClustering(Eigen::MatrixXd& data, int numDims):
mNumDims(numDims),
mNumClusters(0)
{
//TODO normalise affinity matrix?
// NO: we need Eigenvectors of Laplacian, not the Affinity Matrix !!!!
Eigen::MatrixXd Deg = Eigen::MatrixXd::Zero(data.rows(),data.cols());

for ( int i=0; i < data.cols(); i++) {
    Deg(i,i)=1/(sqrt((data.row(i).sum())) );
}
Eigen::MatrixXd Lapla = Deg * data * Deg;

Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> s(Lapla, true);
    // Change ends here
Eigen::VectorXd val = s.eigenvalues();
Eigen::MatrixXd vec = s.eigenvectors();

//sort eigenvalues/vectors
int n = data.cols();
for (int i = 0; i < n - 1; ++i) {
    int k;
    val.segment(i, n - i).maxCoeff(&k);
    if (k > 0) {
        std::swap(val[i], val[k + i]);
        vec.col(i).swap(vec.col(k + i));
    }
}

//choose the number of eigenvectors to consider
if (mNumDims < vec.cols()) {
    mEigenVectors = vec.block(0,0,vec.rows(),mNumDims);
} else {
    mEigenVectors = vec;
}

}

Example of clustering point with 2 dimension

Hi pthimon,

Thanks for your example of STSC and your code.
Could you please offer another example of 2D point clustering such as example shown in STSC ?

Best regards,
Che-Cheng

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.