0

我试图通过 symfit 同时拟合两个具有共享参数的模型,并不断出现以下错误:

AttributeError: 'ImmutableDenseNDimArray' object has no attribute 'as_real_imag'

我已经简化了模型中的两个函数:

B = Variable('B')
y1 = Variable('y1')
y2 = Variable('y2')
n_1 = Parameter('n1', value=n1, min=1.5e27, max=1.55e27) 
n_2 = Parameter('n2', value=n2, min=-1.52e27, max=-1.51e27)
mu_1 = Parameter('mu1', value=mu1, min=1.4, max=1.42)
mu_2 = Parameter('mu2', value=mu2, min=0.63, max=0.65)

a = 1.1513
f = 0.992
q = 1.6e-19

R1 = -1 / (q*n_1)
R2 = -1 / (q*n_2)


rho1 = 1 / (abs(n_1) * q * mu_1)    
rho2 = 1 / (abs(n_2) * q * mu_2)


dictionary = ({

    y1: lambda B,n1,n2,mu1,mu2: 
    
    (rho1 / (rho1**2 + (R1*B)**2) + rho2 / (rho2**2 + (R2*B)**2),
  
    y2: lambda B,n1,n2,mu1,mu2:
    
    - ((-R1*B)/(rho1**2+(R1*B)**2) + (-R2*B)/(rho2**2+(R2*B)**2)
})
    
mixed_model = CallableNumericalModel(dictionary, 
                connectivity_mapping = {y1:{B,n_1,n_2,mu_1,mu_2}, 
                                       y2:{B,n_1,n_2,mu_1,mu_2}})
model_sim = mixed_model(B=xdata, n1=n1, n2=n2, mu1=mu1, mu2=mu2)
rho_xx_sim = model_sim.y1
rho_xy_sim = model_sim.y2

fit = Fit(mixed_model, B=xdata, y1=rho_xx_sim, y2=rho_xy_sim)
fit_result = fit.execute()
print(fit_result)

任何如何对这个错误进行排序的建议都会很棒。在真实模型中,有一个 cosh 组件,我明确写出了它的定义。

先感谢您!

追溯如下:

    unfile('C:/Users/alariaj/Documents/RyanBolger_Mphys/multicarrier/Multicarrier Fitting - 10K (3).py', wdir='C:/Users/alariaj/Documents/RyanBolger_Mphys/multicarrier')
Traceback (most recent call last):

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 262, in getit
    return self._assumptions[fact]

 

KeyError: 'zero'

 


During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 262, in getit
    return self._assumptions[fact]

 

KeyError: 'zero'

 


During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

 

  File "C:\Users\alariaj\Documents\RyanBolger_Mphys\multicarrier\Multicarrier Fitting - 10K (3).py", line 180, in <module>
    model_sim = mixed_model(B=xdata, n1=n1, n2=n2, n3=n3, n4=n4, mu1=mu1, mu2=mu2, mu3=mu3, mu4=mu4)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\symfit\core\models.py", line 667, in __call__
    return ModelOutput(self.keys(), self.eval_components(*args, **kwargs))

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\symfit\core\models.py", line 615, in eval_components
    kwargs[symbol.name] = components[symbol](**dependencies_kwargs)

 

  File "C:\Users\alariaj\Documents\RyanBolger_Mphys\multicarrier\Multicarrier Fitting - 10K (3).py", line 151, in <lambda>
    + (-R3*B)/(rho3**2+(R3*B)**2) + (-R4*B)/(rho4**2+(R4*B)**2))**2))

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\decorators.py", line 91, in __sympifyit_wrapper
    return func(a, b)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\decorators.py", line 129, in binary_op_wrapper
    return func(self, other)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\expr.py", line 196, in __mul__
    return Mul(self, other)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\operations.py", line 47, in __new__
    c_part, nc_part, order_symbols = cls.flatten(args)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\mul.py", line 199, in flatten
    if not a.is_zero and a.is_Rational:

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 266, in getit
    return _ask(fact, self)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 309, in _ask
    a = evaluate(obj)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\mul.py", line 1241, in _eval_is_zero
    z = a.is_zero

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 266, in getit
    return _ask(fact, self)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 321, in _ask
    _ask(pk, obj)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 321, in _ask
    _ask(pk, obj)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 321, in _ask
    _ask(pk, obj)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 321, in _ask
    _ask(pk, obj)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\assumptions.py", line 309, in _ask
    a = evaluate(obj)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\power.py", line 666, in _eval_is_imaginary
    i = arg(self.base)*self.exp/S.Pi

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\function.py", line 473, in __new__
    result = super(Function, cls).__new__(cls, *args, **options)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\function.py", line 288, in __new__
    evaluated = cls.eval(*args)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\functions\elementary\complexes.py", line 671, in eval
    x, y = arg_.as_real_imag()

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\core\add.py", line 858, in as_real_imag
    re, im = term.as_real_imag(deep=deep)

 

  File "C:\Users\alariaj\Anaconda3\lib\site-packages\sympy\functions\elementary\exponential.py", line 375, in as_real_imag
    re, im = self.args[0].as_real_imag()

 

AttributeError: 'ImmutableDenseNDimArray' object has no attribute 'as_real_imag'
4

0 回答 0