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

Watchers

郑大钱爱喝西湖龙井 avatar James Cloos avatar

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.