python - Alternative to scipy.optimize.curve_fit -


i'm trying plot visualisations matplotlib, , in 1 of functions, check if waves logarithmic. current working version:

import numpy np def is_logarithmic(waves):      def expfunc(x, a, b, c):         return a*np.exp(b*x) + c      wcopy = list(waves)     wcopy.sort()      # if ratio of x-max : x-min < 10, don't use logarithmic scale     # (at least in matplotlib)     if (wcopy[-1] / wcopy[0]) < 10:         return false      # take guess @ whether logarithmic seeing how x-scale     # fits exponential curve     diffs = []     ii in range(len(wcopy) - 1):         diffs.append(wcopy[ii + 1] - wcopy[ii])      # fit diffs exponential curve     x = np.arange(len(wcopy)-1)     try:         popt, pcov = curve_fit(expfunc, x, diffs)     except exception e:         print e         popt = [0.0, 0.0, 0.0]         pcov = np.inf      # if > 0.5 , covsum < 1000.0     # use logarithmic scale.     if type(pcov) == float:         # it's np.inf         covsum = pcov     else:         covsum = pcov.diagonal().sum()     res = (covsum < 1000.0) & (popt[0] > 0.5)     return res 

i'm trying find alternative scipy's curve_fit(), because don't want install such big library use 1 function. there else can use, or combination of other functions using ideally numpy , matplotlib, similar result?

numpy can linear (numpy.linalg.lstsq) , polynomial fits (numpy.polyfit). in general need scipy fitting functions define (scipy uses fortran minpack while numpy built c).

however, example, use similar approach this question fit exp. basically, take logatithm of both sides of equation , use numpy.polyfit.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -