2017-04-30 4 views
2

DensityDist을 사용하여 균일 한 이전에 맞춤 분포의 샘플을 사용하고 싶습니다. 의 정신으로 뭔가 : star는 않은 정규화 된 로그 우도 함수에 2D 직교 점을 매핑 기능이PyMC3에서 다변량 유니폼 샘플링

import theano.tensor as T 
from pymc3 import DensityDist, Uniform, Model 

with Model() as model: 
    lim = 3 
    x0 = Uniform('x0', -lim, lim) 
    x1 = Uniform('x1', -lim, lim) 

    x = T.concatenate([x0,x1]) 
    # Create custom densities 
    star = DensityDist('star', lambda x: star(x[:,0],x[:,1])) 

. Metropolis-Hastings를 사용하여 샘플링하려는 기능입니다.

많은 변형을 시도했지만 아무 것도 효과가 없었습니다. 현재 코드가 다음과 같이 실패합니다.

ValueError: The index list is longer (size 2) than the number of dimensions of the tensor(namely 0). You are asking for a dimension of the tensor that does not exist! You might need to use dimshuffle to add extra dimension to your tensor. 

도움이 되었습니까?

답변

2

x에 대한 색인이 잘못되었습니다. 1 차원이기 때문에 2 차원을 따라 인덱싱하는 것은 실제로 작동하지 않습니다.

import theano.tensor as tt 
from pymc3 import DensityDist, Uniform, Model 

def star(x): 
    return -0.5 * tt.exp(-tt.sum(x ** 2)) 
    # or if you need the components individually 
    #return -0.5 * tt.exp(-x[0] ** 2 - x[1] ** 2) 

with Model() as model: 
    lim = 3 
    x0 = Uniform('x0', -lim, lim) 
    x1 = Uniform('x1', -lim, lim) 

    x = T.stack([x0,x1]) 
    # Create custom densities 
    star = DensityDist('star', star)