2014-06-12 2 views
1

내가 PyMC 2.3 documentations에 주어진 예를 복제하기 위해 노력하고있어 :생성 확률 장식 2.3

@pm2.stochastic(dtype=int) 
    def switchpoint(value=1900, t_l=1851, t_h=1962): 
    """The switchpoint for the rate of disaster occurrence.""" 
    if value > t_h or value < t_l: 
     # Invalid values 
     return -np.inf 
    else: 
     # Uniform log-likelihood 
     return -np.log(t_h - t_l + 1) 

이 할당하려고 : 나는 오류 메시지가

test = switchpoint() 

을 (이 게시물 끝에있는 완전한 오류 메시지) :

TypeError: 'numpy.ndarray' object is not callable

나는 호환성 문제가 있다고 생각합니다. Enthought Canopy Python 2.7.6 (64-bit) 배포판을 사용하고 있습니다. Numpy 버전 1.8.0 및 Scipy 0.13.3.

문제가 무엇인지 쉽게 알 수 있습니까?

참고 : 분명히 같은 문제가있는 비교적 작은 old thread을 Google 그룹에서 발견했습니다. 그러나 스레드는 문제의 상태에 대한 업데이트가 없습니다.

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Users/arash/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymc/CommonDeterministics.py", line 975, in __call__ 
    plot=False) 
    File "/Users/arash/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymc/PyMCObjects.py", line 435, in __init__ 
    verbose=verbose) 
    File "/Users/arash/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymc/Node.py", line 216, in __init__ 
    Node.__init__(self, doc, name, parents, cache_depth, verbose=verbose) 
    File "/Users/arash/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymc/Node.py", line 127, in __init__ 
    self.parents = parents 
    File "/Users/arash/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymc/Node.py", line 150, in _set_parents 
    self.gen_lazy_function() 
    File "/Users/arash/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymc/PyMCObjects.py", line 446, in gen_lazy_function 
    self._value.force_compute() 
    File "LazyFunction.pyx", line 257, in pymc.LazyFunction.LazyFunction.force_compute (pymc/LazyFunction.c:2409) 
    File "/Users/arash/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymc/CommonDeterministics.py", line 967, in eval_fun 
    return self(*args, **kwargs) 
TypeError: 'numpy.ndarray' object is not callable 

답변

2

PyMC 실제로 일반 변수로 switchpoint 변 :

여기에 전체 오류 메시지입니다. 그래서 당신은 당신이 장식 된 함수로 정의하고 있기 때문에 그것은 이상한 보이는

test = switchpoint 

할 필요가 있지만, 당신이 그것을 사용하기로하고 실제로 어떻게 아니다.

switchpoint = DiscreteUniform('switchpoint', lower=0, upper=110, doc='Switchpoint[year]') 

그리고이 :

def switchpoint_logp(value, t_l, t_h): 
    if value > t_h or value < t_l: 
     return -np.inf 
    else: 
     return -np.log(t_h - t_l + 1) 

def switchpoint_rand(t_l, t_h): 
    from numpy.random import random 
    return np.round((t_l - t_h) * random()) + t_l 

switchpoint = Stochastic(logp = switchpoint_logp, 
       doc = 'The switchpoint for the rate of disaster occurrence.', 
       name = 'switchpoint', 
       parents = {'t_l': 1851, 't_h': 1962}, 
       random = switchpoint_rand, 
       trace = True, 
       value = 1900, 
       dtype=int, 
       rseed = 1., 
       observed = False, 
       cache_depth = 2, 
       plot=True, 
       verbose = 0) 
+0

감사를이처럼 당신이 확률 변수를 정의 할 수있는 다른 방법 보면 그것은 더 의미가 있습니다! 나는 그런 개념을 이해하지 못했다. 귀하의 답변은 문제를 해결하고 정말로 도움이되었습니다. – Bersavosh