<s> import unittest <EOL> import numpy as np <EOL> from numpy . testing import assert_array_equal <EOL> import scot . xvschema <EOL> class TestBuiltin ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> pass <EOL> def tearDown ( self ) : <EOL> pass <EOL> def test_singletrial ( self ) : <EOL> n_trials = <NUM_LIT:10> <EOL> xv = scot . xvschema . singletrial ( n_trials ) <EOL> for n , ( train , test ) in enumerate ( xv ) : <EOL> self . assertEqual ( len ( train ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( test ) , n_trials - <NUM_LIT:1> ) <EOL> for t in train : <EOL> self . assertTrue ( t not in test ) <EOL> self . assertEqual ( train [ <NUM_LIT:0> ] , n ) <EOL> def test_multitrial ( self ) : <EOL> n_trials = <NUM_LIT:10> <EOL> xv = scot . xvschema . multitrial ( n_trials ) <EOL> for n , ( train , test ) in enumerate ( xv ) : <EOL> self . assertEqual ( len ( test ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( train ) , n_trials - <NUM_LIT:1> ) <EOL> for t in train : <EOL> self . assertTrue ( t not in test ) <EOL> self . assertEqual ( test [ <NUM_LIT:0> ] , n ) <EOL> def test_splitset ( self ) : <EOL> n_trials = <NUM_LIT:10> <EOL> xv = scot . xvschema . splitset ( n_trials ) <EOL> for n , ( train , test ) in enumerate ( xv ) : <EOL> self . assertEqual ( len ( test ) , n_trials // <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( train ) , n_trials // <NUM_LIT:2> ) <EOL> for t in train : <EOL> self . assertTrue ( t not in test ) <EOL> def test_nfold ( self ) : <EOL> n_trials = <NUM_LIT:50> <EOL> n_blocks = <NUM_LIT:5> <EOL> xv = scot . xvschema . make_nfold ( n_blocks ) ( n_trials ) <EOL> for n , ( train , test ) in enumerate ( xv ) : <EOL> self . assertEqual ( len ( test ) , n_trials // n_blocks ) <EOL> self . assertEqual ( len ( train ) , n_trials - n_trials // n_blocks ) <EOL> for t in train : <EOL> self . assertTrue ( t not in test ) <EOL> self . assertEqual ( n + <NUM_LIT:1> , n_blocks ) <EOL> class TestSklearn ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> try : <EOL> import sklearn <EOL> except ImportError : <EOL> self . skipTest ( "<STR_LIT>" ) <EOL> def tearDown ( self ) : <EOL> pass <EOL> def test_leave1out ( self ) : <EOL> from sklearn . cross_validation import LeaveOneOut <EOL> n_trials = <NUM_LIT:10> <EOL> xv1 = scot . xvschema . multitrial ( n_trials ) <EOL> xv2 = LeaveOneOut ( n_trials ) <EOL> self . _comparexv ( xv1 , xv2 ) <EOL> def test_kfold ( self ) : <EOL> from sklearn . cross_validation import KFold <EOL> n_trials = <NUM_LIT:15> <EOL> n_blocks = <NUM_LIT:5> <EOL> xv1 = scot . xvschema . make_nfold ( n_blocks ) ( n_trials ) <EOL> xv2 = KFold ( n_trials , n_folds = n_blocks , shuffle = False ) <EOL> self . _comparexv ( xv1 , xv2 ) <EOL> def test_application ( self ) : <EOL> from scot . var import VAR <EOL> from sklearn . cross_validation import LeaveOneOut , KFold <EOL> np . random . seed ( <NUM_LIT> ) <EOL> x = np . random . randn ( <NUM_LIT:10> , <NUM_LIT:3> , <NUM_LIT:15> ) <EOL> var = VAR ( <NUM_LIT:3> , xvschema = lambda n , _ : LeaveOneOut ( n ) ) . optimize_delta_bisection ( x ) <EOL> self . assertGreater ( var . delta , <NUM_LIT:0> ) <EOL> var = VAR ( <NUM_LIT:3> , xvschema = lambda n , _ : KFold ( n , <NUM_LIT:5> ) ) . optimize_delta_bisection ( x ) <EOL> self . assertGreater ( var . delta , <NUM_LIT:0> ) <EOL> def _comparexv ( self , xv1 , xv2 ) : <EOL> for ( a , b ) , ( c , d ) in zip ( xv1 , xv2 ) : <EOL> assert_array_equal ( a , c ) <EOL> assert_array_equal ( b , d ) </s>
