#NEWLINE# def _setup_bernoulli_mixture( ) : #NEWLINE# #INDENT# '\n    Setup code for the hinton tests.\n\n    This code is from http://www.bayespy.org/examples/bmm.html\n    ' #NEWLINE# np . random . seed ( 1 ) #NEWLINE# p0 = [ 0.1 , 0.9 , 0.1 , 0.9 , 0.1 , 0.9 , 0.1 , 0.9 , 0.1 , 0.9 ] #NEWLINE# p1 = [ 0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.9 , 0.9 , 0.9 , 0.9 , 0.9 ] #NEWLINE# p2 = [ 0.9 , 0.9 , 0.9 , 0.9 , 0.9 , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 ] #NEWLINE# p = np . array ( [ p0 , p1 , p2 ] ) #NEWLINE# z = random . categorical ( [ ( 1 / 3 ) , ( 1 / 3 ) , ( 1 / 3 ) ] , size = 100 ) #NEWLINE# x = random . bernoulli ( p [ z ] ) #NEWLINE# N = 100 #NEWLINE# D = 10 #NEWLINE# K = 10 #NEWLINE# R = Dirichlet ( ( K * [ 1e-05 ] ) , name = 'R' ) #NEWLINE# Z = Categorical ( R , plates = ( N , 1 ) , name = 'Z' ) #NEWLINE# P = Beta ( [ 0.5 , 0.5 ] , plates = ( D , K ) , name = 'P' ) #NEWLINE# X = Mixture ( Z , Bernoulli , P ) #NEWLINE# Q = VB ( Z , R , X , P ) #NEWLINE# P . initialize_from_random ( ) #NEWLINE# X . observe ( x ) #NEWLINE# Q . update ( repeat = 1000 ) #NEWLINE# return ( R , P , Z )