Coder Social home page Coder Social logo

savgol's Introduction

savgol

Provides implementations of Savitzky-Golay smoothing (filtering).

The gem is based on the scipy implementation (gives exactly the same result). A good explanation of the process may be found here on stackexchange.

Examples

Evenly spaced data

Array implementation (object oriented)

require 'savgol/array'
data = [1, 2, 3, 4, 3.5, 5, 3, 2.2, 3, 0, -1, 2, 0, -2, -5, -8, -7, -2, 0, 1, 1]
# window size = 5, polynomial order = 3
data.savgol(5,3)

Module implementation

require 'savgol'
data = [1, 2, 3, 4, 3.5, 5, 3, 2.2, 3, 0, -1, 2, 0, -2, -5, -8, -7, -2, 0, 1, 1]
# window size = 5, polynomial order = 3
Savgol.savgol(data, 5,3)

Uneven data

The speed gain of the Savitzky-Golay filter is lost when interpolating unevenly spaced data and devolves into simple polynomial linear regression [At least I believe they are equivalent in complexity since both require a matrix pseudo-inverse calculation as the most complex operation]. Even though it may be much slower, a filter that handles unevenly spaced data may be useful in some cases.

require 'savgol'
xvals = %w(-1 0 2 3 4 7 8 10 11 12 13 14 17 18).map &:to_f
yvals = %w(-2 1 0 1 1 3 4 7  8  9  7  4  1   2).map {|v| v.to_f + 30 }

Interpolate at the given x-values

Savgol.savgol_uneven(xvals, yvals, 5, 2)

Interpolate at a new set of x values

new_xvals = xvals.map {|v| v + 0.5 }
Savgol.savgol_uneven(xvals, yvals, 5, 2, new_xvals: new_xvals)

Installation

gem install savgol

TODO

  • Implement for Scriruby's Nmatrix and NArray.
  • Implement smoothing for unevenly sampled data.

Copyright

MIT license. See LICENSE.txt.

savgol's People

Contributors

jtprince avatar beny avatar vassilios avatar

Watchers

 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.