Performance difference Python/Matlab curve fitting -
when fitting very simple function randomly created data came across fact python seems outperform matlab 2 orders of magnitude.
now, might depend on specific implementations , on function used particular fit, however, still find strange there such massive difference. i'd grateful if tell me how comes about.
matlab (also used create data , write file, read python):
% write data file able compare across languages x = 0:9; x = repmat(x', 1, 100); y = x.^2; y = y+randn(10, 100); dlmwrite('y_mat.csv',y); % fit , time execution tic d = zeros(1, 100); = zeros(1, 100); ft = fittype('4*d*x^a'); = 1:100 f = fit(x(:, i),y(:, i), ft); a(i) = f.a; d(i) = f.d; end toc
python:
import time import numpy np scipy import optimize start_time = time.time() data = np.loadtxt("y_mat.csv", delimiter=','); def func(t, d, a): return 4*d*t**a da = np.zeros([numparticles, 2]) in range(0, numparticles): x = np.arange(10) y = data[:,i] popt, pcov = optimize.curve_fit(func, x, y) da[i, ] = popt print("--- %s seconds ---" % (time.time() - start_time))
Comments
Post a Comment