3

the past two days I have been working on a specific data fit (orange line of picture 1 ).

Thing is, I want it to be accurate on the bigger θ[0.1,1]. As a matter of fact, I wanted to start at the same point (so for θ=1 we got ψ=1 too) with this form:

ψ_f=a1*(1-x)**a2 +a3*(1-x)**a4+1

but it was super bad as it gets on inf for bigger θ.

For the image 1 I used scipy.optimize.curve_fit for a simple form

ψ_f = a1 *x**a2

Αny other form was flat bad.

Any idea what to do? :(

EDIT:

Data is form this file using following loading code:

ww=np.load('Hot3.npy')
s=ww[3]
z=np.array([ww[0],ww[1],ww[2])

and the xdata,ydata is equal to

xdata = s/max(s)
ydata = z[2]/min(z[2])

Orange is datafit

Billy Matlock
  • 340
  • 2
  • 14

1 Answers1

1

Here is some example code that appears to give a better fit. Note that I have not taken any logs, nor plotted on a log scale. plot

import numpy, scipy, matplotlib
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import warnings


ww=numpy.load('/home/zunzun/temp/hot3.npy')
xData = ww[3]/max(ww[3])
yData = ww[2]/min(ww[2])


def func(x, a, b, c): # Combined Power And Exponential equation from zunzun.com
    power = numpy.power(x, b)
    exponent = numpy.exp(c * x)
    return a * power * exponent 


# numpy defaults are all 1.0, try these instead
initialParameters = numpy.array([1.0,-1.0,-1.0])

# ignore intermediate overflow warning during curve_fit() routine
warnings.filterwarnings("ignore")

# curve fit the test data
fittedParameters, pcov = curve_fit(func, xData, yData, initialParameters)

modelPredictions = func(xData, *fittedParameters) 

absError = modelPredictions - yData

SE = numpy.square(absError) # squared errors
MSE = numpy.mean(SE) # mean squared errors
RMSE = numpy.sqrt(MSE) # Root Mean Squared Error, RMSE
Rsquared = 1.0 - (numpy.var(absError) / numpy.var(yData))

print('Parameters:', fittedParameters)
print('RMSE:', RMSE)
print('R-squared:', Rsquared)

print()


##########################################################
# graphics output section
def ModelAndScatterPlot(graphWidth, graphHeight):
    f = plt.figure(figsize=(graphWidth/100.0, graphHeight/100.0), dpi=100)
    axes = f.add_subplot(111)

    # first the raw data as a scatter plot
    axes.plot(xData, yData,  'o')

    # create data for the fitted equation plot
    xModel = numpy.linspace(min(xData), max(xData))
    yModel = func(xModel, *fittedParameters)

    # now the model as a line plot
    axes.plot(xModel, yModel)

    axes.set_xlabel('X Data') # X axis data label
    axes.set_ylabel('Y Data') # Y axis data label

    plt.show()
    plt.close('all') # clean up after using pyplot

graphWidth = 800
graphHeight = 600
ModelAndScatterPlot(graphWidth, graphHeight)
James Phillips
  • 4,526
  • 3
  • 13
  • 11