Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<lambdifygenerated-1>:2: RuntimeWarning: overflow encountered in exp #373

Open
ghost opened this issue Dec 22, 2023 · 0 comments
Open

<lambdifygenerated-1>:2: RuntimeWarning: overflow encountered in exp #373

ghost opened this issue Dec 22, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Dec 22, 2023

Hi.

I am trying to do a curve fitting for two data sets (sig11-lam1) and (sig22-lam2) simultaneously since they have similar parameters.
Both sig11 and sig22 are functions of lam1 and lam2.

I tried to write an script for it like this :

from symfit import parameters, variables, Fit, Model, exp
import numpy as np
sig11e = np.array([0.007238495, 0.034467973, 0.062664953, 0.104778522, 0.155771434, 0.223699358, 0.296058426, 0.402029639, 0.950890584, 2.279527369, 4.079938047, 7.336652019, 10.94126853, 13.02172086, 13.53927407])
sig22e = np.array([0.004357766, 0.02221891, 0.029088113, 0.043979816, 0.132058283, 0.186319261, 0.411808169, 0.715913378, 1.984616059, 3.080248551, 5.472464315, 7.560792707, 9.380019492, 11.17472448, 11.85931825])
lam1e = np.array([0.043208, 0.339967999, 0.471335999, 0.560944, 0.692375999, 0.794935999, 0.911128, 1.032007999, 1.198792, 1.365175999, 1.478463999, 1.619112, 1.762359999, 1.847487999, 1.872296])
lam2e = np.array([0.026567999, 0.221599998, 0.327823999, 0.423647999, 0.673327999, 0.754639999, 0.987504, 1.097208, 1.310032, 1.399063999, 1.540599998, 1.643199999, 1.732247999, 1.827775999, 1.870688])
lam1, lam2, sig11, sig22 = variables('lam1, lam2, sig11, sig22')
a1, a2, a3, a4, a5 = parameters('a1, a2, a3, a4, a5')
model = Model({
    sig11: (-2/(lam1**2*lam2**2)) * (a1 + 2*a2*(lam1**2 + lam2**2 + (1/(lam1**2 * lam2**2))-3)+ 3*a3*(lam1**2 + lam2**2 + (1/(lam1**2 * lam2**2))-3)**2) + 2*a1*lam1**2 + 4*a2*lam1**2*(lam1**2 + lam2**2 + (1/(lam1**2 * lam2**2))-3) + 6*a3*lam1*(lam1**2 + lam2**2 + (1/(lam1**2 * lam2**2))-3)**2 + 2*lam1**2*a4*(lam1**2-1)*exp(a5*(lam1**2-1)),

    sig22: (-2/lam1**2) * (a1 + a2*(lam1**2 + lam2**2 + (1/(lam1**2 * lam2**2))-3) + 3*a3*(lam1**2 + lam2**2 + (1/(lam1**2 * lam2**2))-3)**2) + 2*a1*lam2**2 + 4*a2*lam2**2*(lam1**2 + lam2**2 + (1/(lam1**2 * lam2**2))-3) + 6*a3*lam2**2*(lam1**2 + lam2**2 + (1/(lam1**2 * lam2**2))-3)**2,
    
})
fit = Fit(model, lam1=lam1e, lam2=lam2e, sig11=sig11e, sig22=sig22e)
fit_result = fit.execute()

Where sig11e, sig22e, lam1e and lam2e are the data which I want to do a curve fitting for and they are considered as variables and a1, a2, a3, a4 and a5 are considered as parameters where a1, a2 and a3 are mutual in both sig11 and sig22 functions.

When I run it, I get the following error:

<lambdifygenerated-1>:2: RuntimeWarning: overflow encountered in exp
  return 2*a1*lam1**2 + 4*a2*lam1**2*(lam1**2 + lam2**2 - 3 + 1/(lam1**2*lam2**2)) + 6*a3*lam1*(lam1**2 + lam2**2 - 3 + 1/(lam1**2*lam2**2))**2 + 2*a4*lam1**2*(lam1**2 - 1)*exp(a5*(lam1**2 - 1)) - 2*(a1 + 2*a2*(lam1**2 + lam2**2 - 3 + 1/(lam1**2*lam2**2)) + 3*a3*(lam1**2 + lam2**2 - 3 + 1/(lam1**2*lam2**2))**2)/(lam1**2*lam2**2)
C:\Users\Alireza\anaconda3\Lib\site-packages\symfit\core\objectives.py:318: RuntimeWarning: overflow encountered in square
  (dep_var_value - dep_data) ** 2 / sigma ** 2

Is there something I am missing here or is it because my functions are somehow long?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants