Giter Site home page Giter Site logo

erikerlandson / snowball Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 2.0 1.19 MB

Monotonic smoothing splines for the JVM

License: Apache License 2.0

Scala 5.11% Java 94.13% HTML 0.76%
scala spline spline-interpolation monotonic java monotone monotone-splines monotonic-splines

snowball's Introduction

snowball

Monotonic smoothing splines for the JVM ecosystem and Apache Commons Math.

Documentation

API javadoc is available at: https://erikerlandson.github.io/snowball/java/api/

A few examples are below.

Features

  • Fit monotonic interpolating splines to data, including data that has noise or is otherwise non-monotonic.
  • Enforce equality constraints of the form s(x) = y, where s is the spline function
  • Enforce gradient constraints of the form ds(x)/dx = g
  • Enforce inequality constraints of the form s(x) < y and s(x) > y

How to use snowball in your project

The snowball package is implemented in java, and so it can be used in both java and scala. It is built on, and designed to work with, Apache Commons Math 3.6.

using SBT

libraryDependencies ++= Seq(
  "com.manyangled" % "snowball" % "0.3.0"
  )

using maven

<dependency>
  <groupId>com.manyangled</groupId>
  <artifactId>snowball</artifactId>
  <version>0.3.0</version>
  <type>pom</type>
</dependency>
<dependency>
  <groupId>com.manyangled</groupId>
  <artifactId>gibbous</artifactId>
  <version>0.3.0</version>
  <type>pom</type>
</dependency>

Examples

Java

import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction;
import com.manyangled.snowball.analysis.interpolation.MonotonicSplineInterpolator;

double[] x = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
double[] y = { 0.0, 0.05, 0.02, 0.3, 0.5, 0.7, 0.99, 0.95, 1.0 };
MonotonicSplineInterpolator interpolator = new MonotonicSplineInterpolator();
PolynomialSplineFunction s = interpolator.interpolate(x, y);

Scala REPL

$ sbt test:console
scala> import com.manyangled.snowball.analysis.interpolation._, com.manyangled.gnuplot4s._
import com.manyangled.snowball.analysis.interpolation._
import com.manyangled.gnuplot4s._

scala> val interpolator = new MonotonicSplineInterpolator()
interpolator: com.manyangled.snowball.analysis.interpolation.MonotonicSplineInterpolator = com.manyangled.snowball.analysis.interpolation.MonotonicSplineInterpolator@6834fd1b

scala> val xdata = Array(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)
xdata: Array[Double] = Array(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)

scala> val ydata = Array(0.0, 0.2, 0.05, 0.3, 0.5, 0.7, 0.95, 0.8, 1.0)
ydata: Array[Double] = Array(0.0, 0.2, 0.05, 0.3, 0.5, 0.7, 0.95, 0.8, 1.0)

scala> val s = interpolator.interpolate(xdata, ydata)
s: org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction = org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction@5852d898

scala> Session().block("data", xdata.zip(ydata)).block("spline", (1.0 to 9.0 by 0.1).map { x => (x, s.value(x)) }).plot(Plot().block("data").using(1,2).style(PlotStyle.Points)).plot(Plot().block("spline").using(1,2).style(PlotStyle.Lines)).term(Dumb().size(80,40)).render

scala> 
                                                                                       
                                                                                
    1 +-+------+--------+-------+--------+--------+--------+-------+------+-A   
      +        +        +       +        +        +        +       +     ####   
      |                                             $data uAing 1:2   #A#   |   
      |                                           $spline using 1:######### |   
      |                                                        ###          |   
      |                                                     ###             |   
      |                                                   ##                |   
  0.8 +-+                                                ##        A      +-+   
      |                                               ###                   |   
      |                                             ##                      |   
      |                                           A#                        |   
      |                                           #                         |   
      |                                         ##                          |   
      |                                       ##                            |   
  0.6 +-+                                    #                            +-+   
      |                                     #                               |   
      |                                    #                                |   
      |                                  A#                                 |   
      |                                 ##                                  |   
      |                                #                                    |   
      |                               #                                     |   
  0.4 +-+                            #                                    +-+   
      |                            ##                                       |   
      |                          ##                                         |   
      |                         A                                           |   
      |                        #                                            |   
      |                      ##                                             |   
      |                   ###                                               |   
  0.2 +-+      A        ##                                                +-+   
      |                ##                                                   |   
      |             ###                                                     |   
      |          ###                                                        |   
      |      ####                                                           |   
      |   ###           A                                                   |   
      ####     +        +       +        +        +        +       +        +   
    0 A-+------+--------+-------+--------+--------+--------+-------+------+-+   
      1        2        3       4        5        6        7       8        9   
                                                                                

References:

  1. H. Fujioka and H. Kano: Monotone smoothing spline curves using normalized uniform cubic B-splines, Trans. Institute of Systems, Control and Information Engineers, Vol. 26, No. 11, pp. 389โ€“397, 2013

  2. Hiroyuki KANO, Hiroyuki FUJIOKA, and Clyde F. MARTIN, Optimal Smoothing Spline with Constraints on Its Derivatives, SICE Journal of Control, Measurement, and System Integration, Vol.7, No. 2, pp. 104โ€“111, March 2014

  3. M. Nagahara, Y. Yamamoto, C. Martin, Quadratic Programming for Monotone Control Theoretic Splines, SICE, 2010.

  4. M. Egerstedt and C. Martin. Monotone Smoothing Splines. Mathematical Theory of Networks and Systems. Perpignan, France, June 2000.

snowball's People

Contributors

erikerlandson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

snowball's Issues

Migration to oss.sonatype

Hello, this would be really useful for an upcoming scala project, would you maybe need help for the migration ? I see you have already gibbous on it.
Thanks for your help

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.