Giter Site home page Giter Site logo

j2kun / svd Goto Github PK

View Code? Open in Web Editor NEW
102.0 11.0 41.0 5.79 MB

Python code implementing the power method for Singular Value Decomposition

Home Page: https://jeremykun.com/2016/05/16/singular-value-decomposition-part-2-theorem-proof-algorithm/

Python 98.13% Shell 1.87%
svd algorithm linear-algebra python programming optimization

svd's Introduction

SVD

An implementation of the greedy algorithm for SVD, using the power method for the 1-dimensional case.

For the post Singular Value Decomposition Part 2: Theorem, Proof, Algorithm

And the first (motivational) post in the series: Singular Value Decomposition Part 1: Perspectives on Linear Algebra

Setup

Run the following to set up all the requirements needed to run the code in this repository.

$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ bash setup.sh   # downloads relevant NLP corpora from nltk

Then run python3 topicmodel.py for the main topic-model routine, svd.py for the core svd algorithm, and demo.py for the numpy examples from the post.

When finished, run $ deactivate to exit the virtual environment.

svd's People

Contributors

eugenelet avatar j2kun avatar waynemystir 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  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  avatar  avatar  avatar  avatar  avatar  avatar

svd's Issues

Fails on singularity.

If the matrix is not full-ranked (one at least one of the dimensions, the SVD gives wrong results for the eigenvalues and eigenvectors that corresponds to the eigenvalues should be 0.

License

Please kindly add license, Sir. Thank you.

Wrong A matrix?

    if n > m:
        v = svd_1d(matrixFor1D, epsilon=epsilon)  # next singular vector
        u_unnormalized = np.dot(A, v)
        sigma = norm(u_unnormalized)  # next singular value
        u = u_unnormalized / sigma
    else:
        u = svd_1d(matrixFor1D, epsilon=epsilon)  # next singular vector
        v_unnormalized = np.dot(A.T, u)
        sigma = norm(v_unnormalized)  # next singular value
        v = v_unnormalized / 

In the above code you multiply by A or A.T. Shouldn't you be using the updated matrix: matrixFor1D or matrixFor1D.T?

Fails on square matrices

It seems that this method fails on square matrices (all of the time). Is there anything theoretical that I'm missing about this method?

How to compute non-reduced SVD?

Hi!

First of all, thanks a lot for this implementation! ๐Ÿ˜Š I couldn't find any other better implementation in Python.

Your implementation looks like it's computing reduced SVD. But I'm trying to implement SVD for the case when full_matrices=True as in torch.svd. Is there anyway I can modify your implementation for full SVD calculation?

Looking towards your help.

Regards,
Rahul Bhalley

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.