Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22202

Why is scipy.optimize.curve_fit dependent on python version?

$
0
0

I found curve_fit produces different results on two different linux machines.So, I did my due diligence with google search but found nothing relevant.After a few experiments, I finally got the same results from both machineand the source of the discrepancy was the different python builds (but the same version!)

  • machine 1: Python 3.9.9 (main, Dec 16 2021, 12:49:28) [GCC 9.3.0]
  • machine 2: Python 3.9.9 (main, Jun 11 2022, 01:51:41) [GCC 9.4.0]

Can anyone explain why this is happening? The difference is small, but it was not negligible when I use the code for bigger data.

Here is the snippet I used for the test:

import sys, numpy, scipyprint(f"python version: {sys.version}\n"      f"numpy version: {numpy.__version__}\n"      f"scipy version: {scipy.__version__}")from scipy.optimize import curve_fitimport numpy as npx = 0.97coords_str = ['[0.0010000000, 1.0000000000]','[0.0330000000, 0.9994012000]','[0.0670000000, 0.9988665000]','[0.1000000000, 0.9983952000]','[0.1330000000, 0.9979058000]','[0.1670000000, 0.9974526000]']coords = np.array([eval(i) for i in coords_str])tau_guess = - coords[-1,0]/np.log(coords[-1,1])init_guess = [tau_guess, 1]sed_fit = lambda t, tau, beta: np.exp(-(t/tau)**beta)curve_fit(sed_fit, coords[:, 0], coords[:, 1], p0=init_guess, method='lm', maxfev=10000)

Output from a linux machine 1 (didn't capture the result from machine 2):

python version: 3.9.9 (main, Jun  2 2022, 15:27:06) [GCC 9.4.0]numpy version: 1.22.4scipy version: 1.8.1(array([131.5209196 ,   0.89507784]), array([[ 1.36570447e+02, -1.33611006e-01],        [-1.33611006e-01,  1.31045820e-04]]))

Another output from an intel mac.

python version: 3.9.9 (main, Dec 16 2021, 12:40:53) [Clang 12.0.0 (clang-1200.0.32.29)]numpy version: 1.21.4scipy version: 1.8.1(array([131.52101656,   0.89507775]), array([[ 1.3657089e+02, -1.3361155e-01],        [-1.3361155e-01,  1.3104646e-04]]))

Viewing all articles
Browse latest Browse all 22202

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>