You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
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.
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:
In the next iteration P(data/model) becomes P(data).
ALGORITHM
From an implementation perspective, these are the steps:
Build P(data) uniform distribution (or with prior knowledge) over data.
Sample n samples from data distribution.
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.
Estimate a probability distribution: P(data/model).
These are the errors of the data given the selected model.
It is wise to use a function such as arctan(1/errors)so errors are not amplified and create a useless probability distribution.
Compute P(data) with update: P(data/model) = normalize(P(data/model)*P(data))
Normalize probability distribution.
This is the bayesian update step.
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:
The minimum number of samples (k) to fit a model is used.
k samples are randomly selected p times.
The best set in p of k samples that fit all the data is selected.
In this bayesian flavor:
k samples are selected and fit using least squares (or something else).
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.
About
Robust Regression for arbitrary non-linear functions