Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Robust Regression for arbitrary non-linear functions

License

NotificationsYou must be signed in to change notification settings

gsubramani/robust-nonlinear-regression

Repository files navigation

Fitting a known model robustly to data using bayesian iteration. The two implementations use

  • RANSAC
  • M-Estimates

The robust part is implemented, fitting the function is not. Modelfitting is borrowed from the scipy.minimize. Feel free to use a different model fitting method.

alt text

Requirements

numpy is the only pre-requisite forrobust_lsq.py.robust_lsq.py requires a least squares fitting function(or some other fitting function),such asscipy.optimize.minimize. Please see examplemodels.py.

robust_lsq.py

  • numpy

models.py

  • scipy
  • numpy

test.py

  • scipy
  • numpy
  • matplotlib

Setup

Please runtest.py for an example of fitting a straight lineto data robustly with bayesian estimation.

How does it work?

The key idea is to determine the samples that fit the model best.Bayesian updates are used. Bayes rule is given by:

P(data/model) = P(model/data)*P(data)/p(model)

P(data/model) := normalization(P(model/data)*P(data))

Note:

  1. P(model) is a constant and can be ignored.
  2. In the next iteration P(data/model) becomes P(data).

ALGORITHM

From an implementation perspective, these are the steps:

  1. Build P(data) uniform distribution (or with prior knowledge) over data.

  2. Sample n samples from data distribution.

  3. Fit model to the selected n samples.Essentially we are selecting(sampling) the best model given the data.This is the P(model/data) step.

  4. Estimate a probability distribution: P(data/model).

    1. These are the errors of the data given the selected model.
    2. It is wise to use a function such as arctan(1/errors)so errors are not amplified and create a useless probability distribution.
  5. Compute P(data) with update: P(data/model) = normalize(P(data/model)*P(data))

    1. Normalize probability distribution.
    2. This is the bayesian update step.
  6. Go to step 2. and iterate until desired convergence of P(data).

RANSAC

For a RANSAC flavor of bayesian robust fitting, k samples are selected to fit the model.

In classical RANSAC:

  1. The minimum number of samples (k) to fit a model is used.
  2. k samples are randomly selected p times.
  3. The best set in p of k samples that fit all the data is selected.

In this bayesian flavor:

  1. k samples are selected and fit using least squares (or something else).
  2. Samples are selected from a probability distribution estimated using bayesian updates.

M-Estimates

This is similar to RANSAC except when fitting the model, all samples are used tofit the model but are weighed according to their probability distribution.The probability distribution(weights) is updated using bayesian updates.

Outlier detection

The probability distribution over the data P(data) provides a way toperform outlier detection. Simply apply a threshold over this distribution.

License

Copyright 2018 Guru Subramani

Permission is hereby granted, free of charge,to any person obtaining a copy of this software andassociated documentation files (the "Software"),to deal in the Software without restriction,including without limitation the rights to use, copy,modify, merge, publish, distribute, sublicense,and/or sell copies of the Software,and to permit persons to whom the Softwareis furnished to do so, subject to the followingconditions:

The above copyright notice and this permissionnotice shall be included in all copies or substantialportions of the Software.

THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSEAND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORSOR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THEUSE OR OTHER DEALINGS IN THE SOFTWARE.


[8]ページ先頭

©2009-2025 Movatter.jp