#NEWLINE# def model( M , N , D , K ) : #NEWLINE# #INDENT# '\n    Construct the linear state-space model with time-varying dynamics\n\n    For reference, see the following publication:\n    (TODO)\n    ' #NEWLINE# beta = Gamma ( 1e-05 , 1e-05 , plates = ( K , ) , name = 'beta' ) #NEWLINE# B = GaussianARD ( np . identity ( K ) , beta , shape = ( beta , ) , plates = ( K , ) , name = 'B' , plotter = bpplt . GaussianHintonPlotter ( rows = 0 , cols = 1 , scale = 0 ) , initialize = False ) #NEWLINE# B . initialize_from_value ( np . identity ( K ) ) #NEWLINE# S = GaussianMarkovChain ( np . ones ( K ) , ( 1e-06 * np . identity ( K ) ) , B , np . ones ( K ) , n = N , name = 'S' , plotter = bpplt . GaussianMarkovChainPlotter ( scale = 2 ) , initialize = False ) #NEWLINE# s = ( 10 * np . random . randn ( N , K ) ) #NEWLINE# s [ : , 0 ] = 10 #NEWLINE# S . initialize_from_value ( s ) #NEWLINE# alpha = Gamma ( 1e-05 , 1e-05 , plates = ( D , K ) , name = 'alpha' ) #NEWLINE# alpha . initialize_from_value ( ( 1 * np . ones ( ( D , K ) ) ) ) #NEWLINE# A = GaussianARD ( 0 , alpha , shape = ( D , K ) , plates = ( D , ) , name = 'A' , plotter = bpplt . GaussianHintonPlotter ( rows = 0 , cols = 1 , scale = 0 ) , initialize = False ) #NEWLINE# a = np . zeros ( ( D , D , K ) ) #NEWLINE# a [ ( np . arange ( D ) , np . arange ( D ) , np . zeros ( D , dtype = int ) ) ] = 1 #NEWLINE# a [ : , : , 0 ] = ( np . identity ( D ) / s [ ( 0 , 0 ) ] ) #NEWLINE# a [ : , : , 1 : ] = ( ( 0.1 / s [ ( 0 , 0 ) ] ) * np . random . randn ( D , D , ( K - 1 ) ) ) #NEWLINE# A . initialize_from_value ( a ) #NEWLINE# X = VaryingGaussianMarkovChain ( np . zeros ( D ) , ( 0.001 * np . identity ( D ) ) , A , S . _convert ( GaussianMoments ) [ 1 : ] , np . ones ( D ) , n = N , name = 'X' , plotter = bpplt . GaussianMarkovChainPlotter ( scale = 2 ) , initialize = False ) #NEWLINE# X . initialize_from_value ( np . random . randn ( N , D ) ) #NEWLINE# gamma = Gamma ( 1e-05 , 1e-05 , plates = ( D , ) , name = 'gamma' ) #NEWLINE# gamma . initialize_from_value ( ( 0.01 * np . ones ( D ) ) ) #NEWLINE# C = GaussianARD ( 0 , gamma , shape = ( D , ) , plates = ( M , 1 ) , name = 'C' , plotter = bpplt . GaussianHintonPlotter ( rows = 0 , cols = 2 , scale = 0 ) ) #NEWLINE# C . initialize_from_value ( np . random . randn ( M , 1 , D ) ) #NEWLINE# F = SumMultiply ( 'd,d' , C , X , name = 'F' ) #NEWLINE# tau = Gamma ( 1e-05 , 1e-05 , name = 'tau' ) #NEWLINE# tau . initialize_from_value ( 100.0 ) #NEWLINE# Y = GaussianARD ( F , tau , name = 'Y' ) #NEWLINE# Q = VB ( Y , F , C , gamma , X , A , alpha , tau , S , B , beta ) #NEWLINE# return Q