Giter Club home page Giter Club logo

ruby-svd's Introduction

Ruby SVD

Singular Value Decomposition for Ruby with no dependency on GSL or LAPACK.

About

Ruby SVD provides an interface to the Numerical Recipies C implementation of an SVD matrix decomposer. It also includes an extension to the native Ruby Matrix class with a simple LSA method (decomposes the matrix, transposes matrix V, diagonalises the S array into a matrix, then removes all but the two leading terms in S to compress the original matrix to two dimensions).

Sample Usage

require 'ruby-svd'

tdm = SVDMatrix.new(4, 2)
tdm.set_row(0, [1,0])
tdm.set_row(1, [1,0])
tdm.set_row(2, [0,1])
tdm.set_row(3, [0,1])

puts "== Term document matrix:"
p tdm

puts "\n== Decomposing matrix:"
lsa = LSA.new(tdm)
p lsa

puts "\n== Classifying new column vector: [1, 0.5, 0, 0.5]"
puts "Format is [column, similarity]"
ranks = lsa.classify_vector([1,0.5,0,0.5])
p ranks

sorted_ranks = ranks.sort_by(&:last).reverse
puts "\n== Vector most similar to column #{sorted_ranks.first[0]}"
p tdm.column(sorted_ranks.first[0])

ruby-svd's People

Contributors

willcannings 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

Watchers

 avatar  avatar  avatar

ruby-svd's Issues

Reorder the singular values?

In Ruby-SVD project, it seems that the function svdcmp in file 'svd.h' didn't sort the singular values in ascend order, either the singular values matrix of LSA's result, is it right?

need example in the readme

Hi Will,

Could you provide one simple example of LSA or SVDMatrix in use? I love the approach, but I am having problems using your library.

Darius

Segfault on large SVDs

Is there a practical limit on the size of the matrix I can pass into the SVD? I'm getting seg faults when I try a 100x200 matrix.

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.