<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> """<STR_LIT>""" <EOL> import nitime . analysis . granger as gc <EOL> """<STR_LIT>""" <EOL> import nitime . utils as utils <EOL> """<STR_LIT>""" <EOL> a1 = np . array ( [ [ <NUM_LIT> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> a2 = np . array ( [ [ - <NUM_LIT:0.5> , <NUM_LIT:0> ] , <EOL> [ - <NUM_LIT> , - <NUM_LIT:0.5> ] ] ) <EOL> am = np . array ( [ - a1 , - a2 ] ) <EOL> x_var = <NUM_LIT:1> <EOL> y_var = <NUM_LIT> <EOL> xy_cov = <NUM_LIT> <EOL> cov = np . array ( [ [ x_var , xy_cov ] , <EOL> [ xy_cov , y_var ] ] ) <EOL> """<STR_LIT>""" <EOL> N = <NUM_LIT> <EOL> """<STR_LIT>""" <EOL> L = <NUM_LIT> <EOL> order = am . shape [ <NUM_LIT:0> ] <EOL> n_lags = order + <NUM_LIT:1> <EOL> n_process = am . shape [ - <NUM_LIT:1> ] <EOL> z = np . empty ( ( N , n_process , L ) ) <EOL> nz = np . empty ( ( N , n_process , L ) ) <EOL> np . random . seed ( <NUM_LIT> ) <EOL> for i in range ( N ) : <EOL> z [ i ] , nz [ i ] = utils . generate_mar ( am , cov , L ) <EOL> """<STR_LIT>""" <EOL> est_order = [ ] <EOL> for i in range ( N ) : <EOL> this_order , this_Rxx , this_coef , this_ecov = gc . fit_model ( z [ i ] [ <NUM_LIT:0> ] , z [ i ] [ <NUM_LIT:1> ] ) <EOL> est_order . append ( this_order ) <EOL> order = int ( np . round ( np . mean ( est_order ) ) ) <EOL> """<STR_LIT>""" <EOL> Rxx = np . empty ( ( N , n_process , n_process , n_lags ) ) <EOL> coef = np . empty ( ( N , n_process , n_process , order ) ) <EOL> ecov = np . empty ( ( N , n_process , n_process ) ) <EOL> for i in range ( N ) : <EOL> this_order , this_Rxx , this_coef , this_ecov = gc . fit_model ( z [ i ] [ <NUM_LIT:0> ] , z [ i ] [ <NUM_LIT:1> ] , order = order ) <EOL> Rxx [ i ] = this_Rxx <EOL> coef [ i ] = this_coef <EOL> ecov [ i ] = this_ecov <EOL> """<STR_LIT>""" <EOL> np . random . seed ( <NUM_LIT> ) <EOL> est_ts , _ = utils . generate_mar ( np . mean ( coef , axis = <NUM_LIT:0> ) , np . mean ( ecov , axis = <NUM_LIT:0> ) , L ) <EOL> fig01 = plt . figure ( ) <EOL> ax = fig01 . add_subplot ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> ax . plot ( est_ts [ <NUM_LIT:0> ] [ <NUM_LIT:0> : <NUM_LIT:100> ] ) <EOL> ax . plot ( z [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> : <NUM_LIT:100> ] , '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> plt . show ( ) <EOL> """<STR_LIT>""" </s>
