farhad
farhad

Reputation: 11

Evaluate parameter in symfit model

I am using symfit for fitting of two NMR data set simultaneously.I defined a cut-off gaussian distribution on one of the parameter. I summerized my explanation in the following simplified example:

import symfit as sf
from symfit import parameters, variables, Fit, Model, Ge
from symfit.core.minimizers import BFGS, BasinHopping, NelderMead, DifferentialEvolution
from symfit import GradientModel, CallableModel
xd= [1.1, 3, 5, 7, 9, 11, 14, 19, 25, 32, 44]
yd= [5.5, 8, 11, 14, 18, 22, 28, 35,45, 69, 110]
pi=3.14
x, y = variables('x, y')
a = sf.Parameter('a',value=3)
b = sf.Parameter('b',value=0.7)
sigma= sf.Parameter('sigma',value=0.7)
res=0
norm=0
for i in range(1,5):
    atemp= (a + ((i-1)*3*sigma/2))
    if atemp < 0:
        atemp = 0
    gauss= sf.exp(-(atemp-a)**2/(2*(sigma**2)))/sf.sqrt(2*pi*(sigma**2))
    res= res+ gauss* (atemp * x + b) 
    norm= norm + gauss
    if i == 4:
        firstres= res
        firstnorm= norm
        res=0
        norm=0

funfit = CallableModel({y: (firstres/firstnorm)})

fit = Fit(funfit, x= xd, y=yd, minimizer=[NelderMead, BFGS])
fit_result = fit.execute()
print(" Best-Fit Parameters: ", fit_result)

I need to check "atemp" be positive because negetive values does not have any physical meaning. I know that "atemp" is a parameter and is an expression but I need to get the value of this parameter. I tried atemp.evalf() and it does not work. I get such an error: "TypeError: cannot determine truth value of Relational"

Upvotes: 0

Views: 276

Answers (0)

Related Questions