tBuLi / symfit

Symbolic Fitting; fitting as it should be.
http://symfit.readthedocs.org
MIT License
234 stars 17 forks source link

Unknown issue with super(type, obj) in fit.py #351

Closed lhdp0110 closed 1 year ago

lhdp0110 commented 1 year ago

I am getting the following error:

Traceback (most recent call last):

  File ~\anaconda3\Scripts\Project\script_04.py:77 in <module>
    fit = Fit(model, t=tdata, A=concentration, sigma_A=0.5)

  File ~\anaconda3\lib\site-packages\symfit\core\support.py:427 in wrapped_func
    return func(*bound_args.args, **bound_args.kwargs)

  File ~\anaconda3\lib\site-packages\symfit\core\fit.py:394 in __init__
    super(Fit, self).__init__(self.model, absolute_sigma=absolute_sigma,

TypeError: super(type, obj): obj must be an instance or subtype of type

Here is my code:

from symfit import variables, parameters, Fit, D, ODEModel, exp
import numpy as np
import matplotlib.pyplot as plt

tdata = np.array([0, 2, 4, 8, 12, 24, 48])
concentration = np.array([3.36, 5.39, 7.02, 7.70, 6.80, 4.62, 7.90])

# Define our ODE model
t, P, bP, bI, RB, RP, RN, bRN, H, A, G = variables('t, P, bP, bI, RB, RP, RN, bRN, H, A, G')
D_P, c_N, c_bN = parameters('D_P, c_N, c_bN')

V = 1
VN = 0.1
m = 2
k = 2

cP = 0.1                                 
cI = 0.02                                
cB = 0.044    
cH = 0.05
cA = 0.041
cM = 0.00001              

phiP = 15                     
phiI = 50                      
phiR = 0.02        
phiM = 10                            

deltaP = 0.01 
deltaPstar = 0.01
deltaR = 0.01
deltaN = 0.01
deltaH = 0.05
deltaA = 0.05

rhoIstar = 0.01
KR = 2
KM = 10    
IT = 1                                            
QM = 1

QP = deltaP
QR = deltaR/V
QH = deltaH/V
QA = deltaA/V       

model_dict = {
    D(P, t): QP - m * cP * exp( - phiP * H) * P**k * G - deltaP * P,
    D(bP, t): cP * exp( - phiP * H) * P**k * G - deltaPstar * bP,
    D(bI, t): cI * exp( - phiI * H) * (IT - bI) * bP - rhoIstar * bI,
    D(RB, t): QR / V + (phiR * bRN) / (KR + bRN) - cB * bI * RB - deltaR * RB,
    D(RP, t): cB * bI * RB - D_P * RP - deltaR * RP,
    D(RN, t): D_P * RP / VN - c_N * RN + c_bN * bRN - deltaN * RN,
    D(bRN, t): c_N * RN - c_bN * bRN,
    D(H, t): QH / V + cH * bRN - deltaH * H,
    D(A, t): QA / V + cA * bRN - deltaA * A,
    D(G, t): QM * G + (phiM * A / (KM + A)) * G - cM * G**2
}

model = ODEModel(
    model_dict,
    initial={t: tdata[0], P: 1.0, bP: 0.1, bI: 0.1, RB: 1.0, RP: 0.1, RN: 0.1, 
             bRN: 0.1, H: 1.0, A: concentration[0], G: 1.0}
)

fit = Fit(model, t=tdata, A=concentration, sigma_A=0.5)
fit_result = fit.execute()

print(fit_result)

Could you please advise? Thank you

lhdp0110 commented 1 year ago

Follow up: I am getting the same error when running the example found here https://symfit.readthedocs.io/en/latest/examples/ex_ODEModel.html Could this be an issue within the support.py or fit.py files?

pckroon commented 1 year ago

Curious. I need to modify your Fit call a little (fit = Fit(model, t=tdata, A=concentration, sigma_A=0.5, G=None, H=None, P=None, RB=None, RN=None, RP=None, bI=None, bP=None, bRN=None)), but it does work for me.

What version of Python are you using? I'm on 3.9.2 here.

lhdp0110 commented 1 year ago

Thank you for your reply! I was able to fix the issue: I think this was due to me accidentally messing with the symfit scripts. Another issue has come up since, see issue #352 if interested.