#NEWLINE# @ bpplt . interactive #NEWLINE# def demo( N = 1000 , D = 5 , K = 4 , seed = 42 , maxiter = 200 , rotate = True , debug = False , precompute = False , plot = True ) : #NEWLINE# #INDENT# if ( Q is not None ) : #NEWLINE# #INDENT# np . random . seed ( seed ) #NEWLINE# #UNINDENT# ( y , f ) = simulate_data ( N ) #NEWLINE# mask_gaps = misc . trues ( N ) #NEWLINE# for m in range ( 100 , N , 140 ) : #NEWLINE# #INDENT# start = m #NEWLINE# end = min ( ( m + 15 ) , ( N - 1 ) ) #NEWLINE# mask_gaps [ start : end ] = False #NEWLINE# #UNINDENT# mask_random = np . logical_or ( random . mask ( N , p = 0.8 ) , np . logical_not ( mask_gaps ) ) #NEWLINE# mask = np . logical_and ( mask_gaps , mask_random ) #NEWLINE# y [ ( ~ mask ) ] = np . nan #NEWLINE# y = y [ ( None , ... ) ] #NEWLINE# f = f [ ( None , ... ) ] #NEWLINE# mask = mask [ ( None , ... ) ] #NEWLINE# mask_gaps = mask_gaps [ ( None , ... ) ] #NEWLINE# mask_random = mask_random [ ( None , ... ) ] #NEWLINE# Q = infer ( y , D , K , mask = mask , maxiter = maxiter , rotate = rotate , debug = debug , precompute = precompute , update_hyper = 10 , start_rotating_weights = 20 , monitor = True ) #NEWLINE# if plot : #NEWLINE# #INDENT# plt . figure ( ) #NEWLINE# bpplt . timeseries_normal ( Q [ 'F' ] , scale = 2 ) #NEWLINE# bpplt . timeseries ( f , linestyle = '-' , color = 'b' ) #NEWLINE# bpplt . timeseries ( y , linestyle = 'None' , color = 'r' , marker = '.' ) #NEWLINE# plt . ylim ( [ ( - 2 ) , 2 ] ) #NEWLINE# Q . plot ( 'X' ) #NEWLINE# Q . plot ( 'S' ) #NEWLINE# #UNINDENT# rmse_random = misc . rmse ( Q [ 'Y' ] . get_moments ( ) [ 0 ] [ ( ~ mask_random ) ] , f [ ( ~ mask_random ) ] ) #NEWLINE# rmse_gaps = misc . rmse ( Q [ 'Y' ] . get_moments ( ) [ 0 ] [ ( ~ mask_gaps ) ] , f [ ( ~ mask_gaps ) ] ) #NEWLINE# print ( ( 'RMSE for randomly missing values: %f' % rmse_random ) ) #NEWLINE# print ( ( 'RMSE for gap values: %f' % rmse_gaps ) )