Coder Social home page Coder Social logo

regression's Introduction

Regression

Summary

The Regression Object can be used to calculate an analytic approximation of a given set of value pairs. The result is a linear combination of chosen basis functions which fit the given values the best. The calculated parameters are saved within the Regression object. The resulting function is a fit of the given value pairs. The function, its first or second derivative can be evaluated at any given position or sampled over a given interval.

The implementation is losly based on

http://bl.ocks.org/jonahwilliams/62be9996afe5c2531625

Tryout at https://goclemens.github.io/Regression/example/smoothingSplines.html

This example is in the example folder of the repository

Usage

Example

Given is a dataset with points in 2D space in the form of x-coordinates X and corresponding y-coordinates Y. The input data needs to be sorted by x-value. As basis we choose a truncated power basis (basically cubic splines) and as regualizer for the linear regression problem the squared second derivative (sq2ndDer).

var data = {
  X: [0.1,0.4,1,1.5,1.9,2.1,2.8,3,4.2,4.9,5.7,6.8,7.3,8.2,8.4,9.2,9.8],
  Y: [1,2,1,2,1,1,2,3,4,5,6,7,8,8,9,6,5]
};

var options = {
  data: data,
  basis: "trunc-power",
  regualizer: "Sq2ndDer",
  lambda: 0.1
};

var regression = new Regression(options);
regression.calcRegression();

var fittedValues = regression.sample([-0.1,10],100);

example fit Plot of the given data and the sampled values of the regression function fittedValues (done with d3.js).

Options

  • data: Object { X: Array, Y: Array }

    The value pairs have to be presorted by x-value from smaller to higher. The data object must contain at least two value pairs.

  • basis: String

    • "trunc-power" (default)

      basically a cubic polynomial basis

    • "linear"

      a linear and a constant basis function

  • regualizer: String

    • "Sq2ndDer" (default)
    • "ridge"
    • "none"
  • knots: Array or false (default false)

    Positions for the knots for the basis functions. False will result in an automatic choose for the knots (usully the point positions itself)

  • lambda: Number >0 (default 0.01)

    prefactor for the regualizer, works as a smoothing parameter

All Methods

  • Regression.setBasis(basisId)

    Sets the used basis for the linear regression to basisId.

  • Regression.calcRegression(options)

    Triggers the calculation of the regression and overides the existing options with options (optional).

  • Regression.sample(interval,resolution)

    Samples the regression function for the given interval with the given resolution. Triggers Regression.calcRegression() if not done yet.

  • Regression.sampleDer(interval,resolution)

    Samples the 1st derivative of the regression function for the given interval with the given resolution. Triggers Regression.calcRegression() if not done yet.

  • Regression.sample2ndDer(interval,resolution)

    Samples the 2nd derivative of the regression function for the given interval with the given resolution. Triggers Regression.calcRegression() if not done yet.

  • Regression.eval(position)

    Evaluates the regression function at the given position. Triggers Regression.calcRegression() if not done yet.

  • Regression.evalDer(postion)

    Evaluates the 1st derivative of the regression function at the given position. Triggers Regression.calcRegression() if not done yet.

  • Regression.eval2ndDer(position)

    Evaluates the 2nd derivative of the regression function at the given position. Triggers Regression.calcRegression() if not done yet.

  • Regression.evalIntegral(interval)

    Evaluates the definite integral of the regression function over the given interval. Triggers Regression.calcRegression() if not done yet.

  • Regression.roots()

    Gives the roots of the regression function.

  • Regression.rootsDer()

    Gives the roots of the derivative of the regression function.

  • Regression.roots2ndDer()

    Gives the roots of the second derivative of the regression function.

  • Regression.extrema()

    Returns an object containing the minima, maxima and saddlepoints of the regression function.

    {
        min: [],
        max: [],
        saddle: []
    }
  • Regression.analyticString() !experimental!

    Returns a string which represents the analytic function given by the regression.

regression's People

Contributors

goclemens avatar

Watchers

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.