def test_whiteness(self): np.random.seed(91) var = VARBase(0) var.residuals = np.random.randn(10, 5, 100) pr = sp.plot_whiteness(var, 20, repeats=100) self.assertGreater(pr, 0.05)
m = 4 # number of sources to estimate h = 66 # number of lags for whiteness test i = 0 for p in [22, 33]: i += 1 print("Model order:", p) print(" Performing CSPVARICA") var = scot.backend["var"](p) result = cspvarica(data, var, classes, m) if result.a.is_stable(): s = "" else: s = "*NOT* " print(" VAR model is {}stable.".format(s)) # discard the first p residuals # r = result.var_residuals[p:, :, :] print(" Testing VAR residuals for whiteness up to lag", h) pr = splot.plot_whiteness(result.a, h, repeats=100, axis=plt.subplot(2, 1, i)) if pr < 0.05: plt.gca().set_title("model order {}: residuals significantly " "non-white with p={:f}".format(p, pr)) else: plt.gca().set_title("model order {}: residuals white " "with p={:f}".format(p, pr)) splot.show_plots()
i += 1 print('Model order:', p) print(' Performing CSPVARICA') var = scot.backend['var'](p) result = cspvarica(data, var, classes, m) if result.a.is_stable(): s = '' else: s = '*NOT* ' print(' VAR model is {}stable.'.format(s)) # discard the first p residuals # r = result.var_residuals[p:, :, :] print(' Testing VAR residuals for whiteness up to lag', h) pr = splot.plot_whiteness(result.a, h, repeats=100, axis=plt.subplot(2, 1, i)) if pr < 0.05: plt.gca().set_title('model order {}: residuals significantly ' 'non-white with p={:f}'.format(p, pr)) else: plt.gca().set_title('model order {}: residuals white ' 'with p={:f}'.format(p, pr)) splot.show_plots()