score:0
You have two problems. One is that quad
returns a tuple with the value and an estimate of the error, and the other is in how you are vectorizing. You don't want to vectorize on the vectors parameter. np.vectorize
has a for loop, so there is no performance gain from doing it yourself:
def func(x, p):
""" Convolution of gaussian and rectangle is a gaussian integral.
Parameters: A, mu, sigma, a"""
A, mu, sigma, a = p
return quad(lambda t: gaus(x-t,A,mu,sigma),-a,a)[0]
def vfunc(x, *p):
evaluations = numpy.array([func(i, p) for i in x])
return evaluations
Note that I have taken the *
in func
away, but not from gaus
. Also, I am selecting the first output of quad
.
Whereas this solves your problem, to fit a convolution you may consider going to Fourier space. The Fourier transform of a convolution is the product of the transforms of the functions, and this is going to simplify your life a lot. Furthermore, once in Fourier space you may consider applying a low-pass filter to reduce noise. 210 data points are high enough to get good results.
Also, if you need more powerful algorithms, you should consider iminuit, using ROOT's long proven Minuit.
Credit To: stackoverflow.com
Related Query
- Fit gaussian integral function to data
- How to use leastsq function from scipy.optimize in python to fit both a straight line and a quadratic line to data sets x and y
- Gaussian Fit on noisy and 'interesting' data set
- Double integral with function and sampled data Python
- Python 2D Gaussian Fit with NaN Values in Data
- Curve fit an exponential decay function in Python using given data points
- How to fit 2-D function if some of the data points are NaNs?
- Type error on my fit function using gaussian process in scikit
- Fit data with a lognormal function via Maximum Likelihood estimators
- Using scipy to calculate integral over time series data without function
- fit a power law function to the data with both x and y errors
- Why I am not able to fit a sigmoid function to this data using scipy.optimize.curve_fit?
- Fit erf function to data
- Python: fit data with gaussian rising and exponential decay
- Fit lognormal function to count data
- Printing optimized parameters of a function to fit data
- Fit function to experimental data using curve_fit with two independent variables
- scipy.optimize.curve_fit weird behaviour when trying to fit gaussian to data
- Fit data within two function bounds
- Fitting a single gaussian to 'noisy' data yields a poor fit in some cases
- How do I fit a sine curve to my data with pylab and numpy?
- Fitting a 2D Gaussian function using scipy.optimize.curve_fit - ValueError and minpack.error
- Fit a curve for data made up of two distinct regimes
- How to fit a polynomial curve to data using scikit-learn?
- How to fit polynomial to data with error bars
- Maintaining a ratio when splitting up data in python function
- fit multiple gaussians to the data in python
- Fit data to all possible distributions and return the best fit
- numpy generate data from linear function
- probability density function from histogram in python to fit another histrogram
More Query from same tag
- when i import numpy and pandas in jupyter it gives error same in spider but in spider works after starting new kernel
- What is the most efficient way to create a DataFrame from two unrelated series?
- How can I read 10-bit Raw image? which contain RGB-IR data
- Cython with numpy how to get rid of fancy indexing (no call to Python)
- Does a random seed set via numpy.random.seed maintain across submodules?
- Is there a way to write a python function that will create 'N' arrays? (see body)
- How do I make this partition in my numpy array?
- PIL, numpy and matplotlib produce a plot that has vastly different colors from the original image
- Why python bulit-in functions such as sum(),max(),min() can be used to calculate the numpy's datatype ndarray?
- Finding a function that fits several arguments
- How to call an element in a numpy array?
- Why is it ok to have an index with lists as values but not ok for columns?
- How to define a callable function whenever the value of any element in the list gets changed?
- String comparison in Numpy
- From an array of indices how to create Python ranges?