用枢轴点拟合曲线Python [英] Fitting a curve with a pivot point Python

查看:145
本文介绍了用枢轴点拟合曲线Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的图,我想用2条线拟合.使用python,我设法适应了上面的部分:

I have the plot below and I want to fit it with 2 lines. Using python I manage to fit the upper part:

def func(x,a,b):
    x=np.array(x)
    return a*(x**b)
popt,pcov=curve_fit(func,up_x,up_y)

我想在下部用另一条线拟合,但是我希望该线穿过红色的一颗星星的点,因此我可以具有连续的功能.所以我的问题是,如何通过给定函数必须通过的点来使用curve_fit,而让直线的斜率由python计算呢? (或其他任何能够执行此操作的python软件包)

And I want to fit the lower part with another line, but I want the line to pass through the point where the red one stars, so I can have a continuous function. So my question is how can I use curve_fit by giving a point the function has to pass through, but leaving the slope of the line to be calculated by python? (Or any other python package able to do it)

推荐答案

在日志空间中对模型进行可能的逐步参数化是这样的:

A possible stepwise parametrisation of your model in log-space is something like:

(x>q)*((x-q)*a)+(x<q)*((x-q)*c)+b

其中q是纽结的位置,ac是两个零件的斜率,b是全局y偏移.由于模型具有不连续性,因此基于梯度的最小化器可能不是找到最佳拟合的最佳选择.尽管如此,我同时尝试了scipy.optimize.leastsqscipy.odr并获得了良好的结果.

Where q is the position of the kink, a, and c are the slopes of both parts and b is a global y-offset. Since the model has a discontinuity a gradient based minimizer might not be the best choice to find a best fit. Nevertheless I tried both scipy.optimize.leastsq and scipy.odr and got good results.

这篇关于用枢轴点拟合曲线Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆