curve-fitting

Fitting a sum to data in Python

旧城冷巷雨未停 提交于 2019-12-04 16:24:33
Given that the fitting function is of type: I intend to fit such function to the experimental data (x,y=f(x)) that I have. But then I have some doubts: How do I define my fitting function when there's a summation involved? Once the function defined, i.e. def func(..) return ... is it still possible to use curve_fit from scipy.optimize? Because now there's a set of parameters s_i and r_i involved compared to the usual fitting cases where one has few single parameters. Finally are such cases treated completely differently? Feel a bit lost here, thanks for any help. This is very well within reach

fit using lsqcurvefit

半世苍凉 提交于 2019-12-04 14:03:31
I want to fit some data to a lorentz function but I figure problems with fitting when I use parameters which are of different orders of magnitude. This my lorentz function: function [ value ] = lorentz( x,x0,gamma,amp ) value = amp * gamma^2 ./ ((x-x0).^2 + gamma^2); end Now the script to generate sample data: x = linspace(2e14,6e14,200); x0 = 4.525e14; gamma = 0.5e14; amp = 2e-14; y = lorentz(x,x0,gamma,amp); And the script for fitting lorentz to the sample data: params = [4.475e14;0.4e14;1.8e-14]; opts = optimset('TolFun',1e-60,'TolX',1e-50,'Display','Iter'); fitfunc = @(params,x) lorentz(x

fit to time series using Gnuplot

别说谁变了你拦得住时间么 提交于 2019-12-04 13:44:07
I am a big fan of Gnuplot and now I would like to use the fit-function for time series. My data set is like: 1.000000 1.000000 0.999795 0.000000 0.000000 0.421927 0.654222 -25.127700 1.000000 1994-08-12 1.000000 2.000000 0.046723 -0.227587 -0.689491 0.328387 1.000000 0.000000 1.000000 1994-08-12 2.000000 1.000000 0.945762 0.000000 0.000000 0.400038 0.582360 -8.624480 1.000000 1995-04-19 2.000000 2.000000 0.060228 -0.056367 -0.680224 0.551019 1.000000 0.000000 1.000000 1995-04-19 3.000000 1.000000 1.016430 0.000000 0.000000 0.574478 0.489638 -3.286880 1.000000 1995-07-15 And my fitting script:

scipy curve_fit error: divide by zero encountered

╄→尐↘猪︶ㄣ 提交于 2019-12-04 12:13:37
I've been trying to fit a function to some data for a while using scipy.optimize.curve_fit: from __future__ import (print_function, division, unicode_literals, absolute_import) import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as mpl x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) y = np.array([20.8, 20.9, 22.9, 25.2, 26.9, 28.3, 29.5, 30.7, 31.8, 32.9, 34.0, 35.3, 36.4, 37.5, 38.6, 39.6, 40.6, 41.6, 42.5, 43.2, 44.2, 45.0, 45.8, 46.5, 47.3, 48.0, 48.6, 49.2, 49.8, 50.4]) def f(x, a, b,

Python power law fit with upper limits & asymmetric errors in data using ODR

南笙酒味 提交于 2019-12-04 12:01:08
问题 I'm trying to fit some data to a power law using python. The problem is that some of my points are upper limits, which I don't know how to include in the fitting routine. In the data, I have put the upper limits as errors in y equal to 1, when the rest is much smaller. You can put this errors to 0 and change the uplims list generator, but then the fit is terrible. The code is the following: import numpy as np import matplotlib.pyplot as plt from scipy.odr import * # Initiate some data x = [1

Suggestions for fitting noisy exponentials with scipy curve_fit?

荒凉一梦 提交于 2019-12-04 10:58:51
I'm trying to fit data that would be generally modeled by something along these lines: def fit_eq(x, a, b, c, d, e): return a*(1-np.exp(-x/b))*(c*np.exp(-x/d)) + e x = np.arange(0, 100, 0.001) y = fit_eq(x, 1, 1, -1, 10, 0) plt.plot(x, y, 'b') An example of an actual trace, though, is much noisier: If I fit the rising and decaying components separately, I can arrive at somewhat OK fits: def fit_decay(df, peak_ix): fit_sub = df.loc[peak_ix:] guess = np.array([-1, 1e-3, 0]) x_zeroed = fit_sub.time - fit_sub.time.values[0] def exp_decay(x, a, b, c): return a*np.exp(-x/b) + c popt, pcov = curve

Fitting a function in R

柔情痞子 提交于 2019-12-04 10:48:40
问题 I have a few datapoints (x and y) that seem to have a logarithmic relationship. > mydata x y 1 0 123 2 2 116 3 4 113 4 15 100 5 48 87 6 75 84 7 122 77 > qplot(x, y, data=mydata, geom="line") Now I would like to find an underlying function that fits the graph and allows me to infer other datapoints (i.e. 3 or 82 ). I read about lm and nls but I'm not getting anywhere really. At first, I created a function of which I thought it resembled the plot the most: f <- function(x, a, b) { a * exp(b *-x

Extracting x value given y threshold from polyfit plot (Matlab)

我是研究僧i 提交于 2019-12-04 06:41:50
问题 As shown by the solid and dashed line, I'd like to create a function where I set a threshold for y (Intensity) from that threshold it gives me corresponding x value (dashed line). Very simple but my while statement is off. Any help would be much appreciated! %% Curve fit plotting %% x1 = timeStamps(1:60); % taking timestamps from 1 - 120 given smoothed y1 values y1 = smooth(tic_lin(1:60),'sgolay',1); % Find coefficients for polynomial (order = 4 and 6, respectively) fitResults1 = polyfit(x1'

scipy.optimize.curve_fit, TypeError: unsupported operand type

Deadly 提交于 2019-12-04 05:18:49
I've done a search and the problem seems similar to Python scipy: unsupported operand type(s) for ** or pow(): 'list' and 'list' however the solution posted there did not work and I think it may actually be different. I am trying to fit a curve to data using scipy.curve_fit, when I leave all 3 parameters free everything works correctly and I get the expected result. def func(x,a,b,c): return a*np.exp(b*(x**c)) popt, pcov = curve_fit(func,x,y) However when I try to fix one of the values (c=2) as below, def func2(x,a,b): return a*np.exp(b*(x**2)) popt, pcov = curve_fit(func2,x,y) I get TypeError

How to use Java Math Commons CurveFitter?

眉间皱痕 提交于 2019-12-04 05:11:05
How do I use Math Commons CurveFitter to fit a function to a set of data? I was told to use CurveFitter with LevenbergMarquardtOptimizer and ParametricUnivariateFunction , but I don't know what to write in the ParametricUnivariateFunction gradient and value methods. Besides, after writing them, how to get the fitted function parameters? My function: public static double fnc(double t, double a, double b, double c){ return a * Math.pow(t, b) * Math.exp(-c * t); } So, this is an old question, but I ran into the same issue recently, and ended up having to delve into mailing lists and the Apache