如何使用scipy.optimize与pymc3随机变量?

时间:2017-06-16 17:13:29

标签: python numpy scipy pymc3

对于我的pymc3模型,我需要计算值E,其值为M = E - e * sinE
这里M和e是pymc3随机变量。我想使用scipy.optimize从给定的表达式中找到E,但我得到的错误是"应该是真值,而不是TensorVariable"。如何使用TensorVariables计算另一个随机变量?

@np.vectorize
def compute_E(M, e):
    """Solve Kepler's eqns for eccentric anomaly given mean anomaly"""
    f = lambda E, M=M, e=e: E - e * np.sin(E) - M
    return optimize.brentq(f, 0, 2 * np.pi)

with one_planet_model:
    V = pm.Uniform('V',lower=-2000,upper=2000)
    e = pm.Uniform('e',lower=0,upper=1)
    pomega = pm.Uniform('pomega',lower=0,upper=2*np.pi)
    chi = pm.Uniform('chi',lower=0,upper=1)
    T = pm.DensityDist('T',lambda value: - np.log(value) - np.log(np.log(15000 * 5)))
    K = pm.DensityDist('K',lambda value: -np.log(value+1)-np.log(2001))
    s = pm.DensityDist('s',lambda value: -np.log(value+1)-np.log(2001))
    sd = np.sqrt(err1**2 + s**2)
    M = 2 * np.pi * ((jd / T + chi) % 1)
    E = compute_E(M,e)
    f = 2 * np.arctan2(np.sqrt(1 + e) * np.sin(E / 2),
               np.sqrt(1 - e) * np.cos(E / 2))
    mu = V - K * (np.sin(f + pomega) + e * np.sin(pomega))
    rv_obs = pm.Normal('rv_obs',mu=mu,sd=sd,observed=rv1)

0 个答案:

没有答案