Fits

Functions

Details

Collection of fitting functions

fits.demo_ransac()[source]

Find the best-fit circle in an image, using the RANSAC algorithm

fits.fit_circle(x, y)[source]

Determine the best-fit circle to given datapoints.

Parameters:

x : array (N,)

x-values.

y : array (N,)

corresponding y-values.

Returns:

center : array (2,)

x/y coordinates of center of the circle

radius : float

Circle radius.

fits.fit_exp(tFit, yFit)[source]

Calculates best-fit parameters for the exponential decay to an offset.

Parameters:

tFit : array (N,)

Time values.

yFit : array (N,)

Function values

Returns:

offset : float

Function offset/bias.

amp : float

Amplitude of exponential function

tau : float

Decay time.

fits.fit_line(x, y, alpha=0.05, newx=[], plotFlag=1)[source]

Linear regression fit.

Parameters:

x : ndarray

Input / Predictor.

y : ndarray

Input / Estimator.

alpha : float

Confidence limit [default=0.05]

newx : float or ndarray

Values for which the fit and the prediction limits are calculated (optional)

plotFlag: int, optional :

1 = plot, 0 = no_plot [default]

Returns:

a : float

Intercept

b : float

Slope

ci : ndarray

Lower and upper confidence interval for the slope

info : dictionary

contains return information on - residuals - var_res - sd_res - alpha - tval - df

newy : list(ndarray)

Predictions for (newx, newx-ciPrediction, newx+ciPrediction)

Notes

Example data and formulas are taken from D. Altman, “Practical Statistics for Medicine”

Examples

>>> import numpy as np
>>> from fitLine import fitLine
>>> x = np.r_[0:10:11j]
>>> y = x**2
>>> (a,b,(ci_a, ci_b),_)=fitLine(x,y)    
fits.fit_sin(tList, yList, freq)[source]

Fit a sine wave with a known frequency to a given set of data.

y = amplitude * sin(2*pi*freq * tList + phase*pi/180) + bias

Parameters:

yList : array

datapoints

tList : float

time base, in sec

freq : float

in Hz

Returns:

phase : float

in degrees

amplitude : float

bias : float

Examples

>>> (phase, amp, offset) = thLib.fitSin.fitSine(t, data, freq)
fits.regress(x, y, alpha=0.05)[source]

Linear regression and confidence intervals, for a linear regression y = k * x + d

(kd, ci) = regress(x,y,[alpha=0.05])

Parameters:

x : ndarray (N,)

predictors

y : ndarray(N,)

responses

alpha: float :

Defines the 100*(1-alpha)% confidence level in ci.

Returns:

k : float

estimated slope

d : float

estimated intercept

ci : ndarray (2,)

confidence intervals for the slope

See also

fit_line

Examples

>>> x = arange(100)
>>> y = 0.3*x + 10 + randn(len(x))
>>> (kd, ci) = thLib.fits.regress(x,y)

Table Of Contents

Previous topic

Rotation Matrices

Next topic

Signal Processing Utilities

This Page