<s> '''<STR_LIT>''' <EOL> import unittest , itertools <EOL> import pickle <EOL> import numpy as np <EOL> import tempfile <EOL> from GPy . examples . dimensionality_reduction import mrd_simulation <EOL> from GPy . core . parameterization . variational import NormalPosterior <EOL> from GPy . models . gp_regression import GPRegression <EOL> import GPy <EOL> from nose import SkipTest <EOL> def toy_model ( ) : <EOL> X = np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:50> ) [ : , None ] <EOL> Y = np . sin ( X ) <EOL> m = GPRegression ( X = X , Y = Y ) <EOL> return m <EOL> class ListDictTestCase ( unittest . TestCase ) : <EOL> def assertListDictEquals ( self , d1 , d2 , msg = None ) : <EOL> for k , v in d1 . items ( ) : <EOL> self . assertListEqual ( list ( v ) , list ( d2 [ k ] ) , msg ) <EOL> def assertArrayListEquals ( self , l1 , l2 ) : <EOL> for a1 , a2 in zip ( l1 , l2 ) : <EOL> np . testing . assert_array_equal ( a1 , a2 ) <EOL> class Test ( ListDictTestCase ) : <EOL> @ SkipTest <EOL> def test_load_pickle ( self ) : <EOL> import os <EOL> m = GPy . load ( os . path . join ( os . path . abspath ( os . path . split ( __file__ ) [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) ) <EOL> self . assertTrue ( m . checkgrad ( ) ) <EOL> self . assertEqual ( m . log_likelihood ( ) , - <NUM_LIT> ) <EOL> def test_model ( self ) : <EOL> par = toy_model ( ) <EOL> pcopy = par . copy ( ) <EOL> self . assertListEqual ( par . param_array . tolist ( ) , pcopy . param_array . tolist ( ) ) <EOL> np . testing . assert_allclose ( par . gradient_full , pcopy . gradient_full ) <EOL> self . assertSequenceEqual ( str ( par ) , str ( pcopy ) ) <EOL> self . assertIsNot ( par . param_array , pcopy . param_array ) <EOL> self . assertIsNot ( par . gradient_full , pcopy . gradient_full ) <EOL> self . assertTrue ( pcopy . checkgrad ( ) ) <EOL> self . assert_ ( np . any ( pcopy . gradient != <NUM_LIT:0.0> ) ) <EOL> with tempfile . TemporaryFile ( '<STR_LIT>' ) as f : <EOL> par . pickle ( f ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> pcopy = pickle . load ( f ) <EOL> self . assertListEqual ( par . param_array . tolist ( ) , pcopy . param_array . tolist ( ) ) <EOL> np . testing . assert_allclose ( par . gradient_full , pcopy . gradient_full ) <EOL> self . assertSequenceEqual ( str ( par ) , str ( pcopy ) ) <EOL> self . assert_ ( pcopy . checkgrad ( ) ) <EOL> def test_modelrecreation ( self ) : <EOL> par = toy_model ( ) <EOL> pcopy = GPRegression ( par . X . copy ( ) , par . Y . copy ( ) , kernel = par . kern . copy ( ) ) <EOL> np . testing . assert_allclose ( par . param_array , pcopy . param_array ) <EOL> np . testing . assert_allclose ( par . gradient_full , pcopy . gradient_full ) <EOL> self . assertSequenceEqual ( str ( par ) , str ( pcopy ) ) <EOL> self . assertIsNot ( par . param_array , pcopy . param_array ) <EOL> self . assertIsNot ( par . gradient_full , pcopy . gradient_full ) <EOL> self . assertTrue ( pcopy . checkgrad ( ) ) <EOL> self . assert_ ( np . any ( pcopy . gradient != <NUM_LIT:0.0> ) ) <EOL> np . testing . assert_allclose ( pcopy . param_array , par . param_array , atol = <NUM_LIT> ) <EOL> par . randomize ( ) <EOL> with tempfile . TemporaryFile ( '<STR_LIT>' ) as f : <EOL> par . pickle ( f ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> pcopy = pickle . load ( f ) <EOL> np . testing . assert_allclose ( par . param_array , pcopy . param_array ) <EOL> np . testing . assert_allclose ( par . gradient_full , pcopy . gradient_full , atol = <NUM_LIT> ) <EOL> self . assertSequenceEqual ( str ( par ) , str ( pcopy ) ) <EOL> self . assert_ ( pcopy . checkgrad ( ) ) <EOL> def test_posterior ( self ) : <EOL> X = np . random . randn ( <NUM_LIT:3> , <NUM_LIT:5> ) <EOL> Xv = np . random . rand ( * X . shape ) <EOL> par = NormalPosterior ( X , Xv ) <EOL> par . gradient = <NUM_LIT:10> <EOL> pcopy = par . copy ( ) <EOL> pcopy . gradient = <NUM_LIT:10> <EOL> self . assertListEqual ( par . param_array . tolist ( ) , pcopy . param_array . tolist ( ) ) <EOL> self . assertListEqual ( par . gradient_full . tolist ( ) , pcopy . gradient_full . tolist ( ) ) <EOL> self . assertSequenceEqual ( str ( par ) , str ( pcopy ) ) <EOL> self . assertIsNot ( par . param_array , pcopy . param_array ) <EOL> self . assertIsNot ( par . gradient_full , pcopy . gradient_full ) <EOL> with tempfile . TemporaryFile ( '<STR_LIT>' ) as f : <EOL> par . pickle ( f ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> pcopy = pickle . load ( f ) <EOL> self . assertListEqual ( par . param_array . tolist ( ) , pcopy . param_array . tolist ( ) ) <EOL> pcopy . gradient = <NUM_LIT:10> <EOL> np . testing . assert_allclose ( par . gradient_full , pcopy . gradient_full ) <EOL> np . testing . assert_allclose ( pcopy . mean . gradient_full , <NUM_LIT:10> ) <EOL> self . assertSequenceEqual ( str ( par ) , str ( pcopy ) ) <EOL> def test_model_concat ( self ) : <EOL> par = mrd_simulation ( optimize = <NUM_LIT:0> , plot = <NUM_LIT:0> , plot_sim = <NUM_LIT:0> ) <EOL> par . randomize ( ) <EOL> pcopy = par . copy ( ) <EOL> self . assertListEqual ( par . param_array . tolist ( ) , pcopy . param_array . tolist ( ) ) <EOL> self . assertListEqual ( par . gradient_full . tolist ( ) , pcopy . gradient_full . tolist ( ) ) <EOL> self . assertSequenceEqual ( str ( par ) , str ( pcopy ) ) <EOL> self . assertIsNot ( par . param_array , pcopy . param_array ) <EOL> self . assertIsNot ( par . gradient_full , pcopy . gradient_full ) <EOL> self . assertTrue ( par . checkgrad ( ) ) <EOL> self . assertTrue ( pcopy . checkgrad ( ) ) <EOL> self . assert_ ( np . any ( pcopy . gradient != <NUM_LIT:0.0> ) ) <EOL> with tempfile . TemporaryFile ( '<STR_LIT>' ) as f : <EOL> par . pickle ( f ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> pcopy = pickle . load ( f ) <EOL> self . assertListEqual ( par . param_array . tolist ( ) , pcopy . param_array . tolist ( ) ) <EOL> np . testing . assert_allclose ( par . gradient_full , pcopy . gradient_full ) <EOL> self . assertSequenceEqual ( str ( par ) , str ( pcopy ) ) <EOL> self . assert_ ( pcopy . checkgrad ( ) ) <EOL> def _callback ( self , what , which ) : <EOL> what . count += <NUM_LIT:1> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
