使用Scipy最小二乘法使数据与移位功率曲线最佳匹配

时间:2022-07-03 21:24:24

I'm new to Python/Scipy/Numpy.

我是Python / Scipy / Numpy的新手。

I've successfully used an example from here to smooth data using least squares method. But in a couple of cases it's accuracy is off at the extreme ends.

我已成功使用此处的示例来使用最小二乘法平滑数据。但在一些情况下,它的准确性在极端情况下是不对的。

It seems a Shifted Power Curve is a better fit but I'm having problems with syntax on the a(x-b)^c function and am not sure this'll work with the log10 method.

似乎移位功率曲线更适合但我在a(x-b)^ c函数上遇到语法问题,我不确定这是否适用于log10方法。

Current code is:

目前的代码是:

from scipy import *
from scipy import optimize
#                                         # READ DATA FROM CSV FILE
DIA, FlowRate =  genfromtxt('#ThisDataFile#', delimiter=',', unpack='true')
#                                         # CONVERT DATA TO LOG ITS MORE ACCURATE
logx = log10(DIA)
logy = log10(FlowRate)                    #crlf#
#                                         # define our (line) fitting function
fitfunc = lambda p, x: p[0] + p[1] * x
errfunc = lambda p, x, y: (y - fitfunc(p, x))
pinit = [5.0, -5.0]
out = optimize.leastsq(errfunc, pinit,
                       args=(logx, logy), full_output=1)
pfinal1 = out[0]
amp1 = 10.0**pfinal1[0]

print(amp1, pfinal1[1])

Can anyone point me in the right direction.

任何人都可以指出我正确的方向。

Thanks Peter

Update:

Sample data ( on measured ) pressure:

样本数据(已测量)压力:

DIA  = [ 1, 2, 3, 4, 5, 6, 7, 8 ]
flow = [ 58.33254,
         30.11954,
         16.02723,
          9.47614,
          5.75362,
          3.63373,
          2.37532,
          1.58426
         ]

1 个解决方案

#1


1  

Sample data pressure = "1,2,3,4,5,6,7,8" flow="58.33254,30.11954,16.02723,9.47614,5.75362,3.63373,2.37532,1.58426"

样本数据压力=“1,2,3,4,5,6,7,8”flow =“58.33254,30.11954,16.02723,9.47614,5.75362,3.63373,2.37532,1.58426”

#1


1  

Sample data pressure = "1,2,3,4,5,6,7,8" flow="58.33254,30.11954,16.02723,9.47614,5.75362,3.63373,2.37532,1.58426"

样本数据压力=“1,2,3,4,5,6,7,8”flow =“58.33254,30.11954,16.02723,9.47614,5.75362,3.63373,2.37532,1.58426”