power-law function fitting in linear space or linear-function in log space

Viewed 100

I have a question about power-law fitting.

Please attached figure. In this figure, I have four diagonal lines. Lines are the results of fitting using circles in the background. The black and cyan line used gray circles, and orange dashed line and magenta line used yellow circles for fitting.

The difference between black and cyan, and orange and magenta is which space and which function do I use for fitting the data.

Now I cannot judge which one is correct fitting. Using power-law function in linear space or using linear function in log space.

Please give a hint about this:(

Below is a part of my code.

def powerlaw_linear_func(x,a,b):
    return a*x+b

def powerlaw_func(x,a,b):
    return b*x**a



xx = np.arange(0,100,1)
    #### fit all data and plot using power-law function in linear space - black ####
    params2, params_cov2 = optimize.curve_fit(powerlaw_func,vrms_c[0],alpha_all[0])#,p0=[1.2,1])
    #print (params2)
    #print (np.sqrt(np.diag(params_cov2)))
    axs[i+7].plot(np.log10(xx),np.log10(params2[1]*xx**params2[0]),c='k',ls='-')
    
    #### fit all data and plot using linear function in log space - cyan ####
    params3, params_cov3 = optimize.curve_fit(powerlaw_linear_func,np.log10(vrms_c[0].astype('float')),np.log10(alpha_all[0].astype('float')))#,p0=[1.2,1])
    axs[i+7].plot(np.log10(xx),params3[0]*np.log10(xx) + params3[1],c='c',ls='-')

    
    #### fit orange data and plot using power-law function in linear space - orange ####
    params2, params_cov2 = optimize.curve_fit(powerlaw_func,vrms_c[i],alpha_all[i])#,p0=[1.2,1])
    axs[i+7].plot(np.log10(xx),np.log10(params2[1]*xx**params2[0]),c=lines[i],ls='--')
    print (params2)
    print (np.sqrt(np.diag(params_cov2)))
    print (i)
    
    #### fit orange data and plot using linear function in log space - magenta ####
    params3, params_cov3 = optimize.curve_fit(powerlaw_linear_func,np.log10(vrms_c[i].astype('float')),np.log10(alpha_all[i].astype('float')))#,p0=[1.2,1])
    axs[i+7].plot(np.log10(xx),params3[0]*np.log10(xx) + params3[1],c='m',ls='-')
0 Answers
Related