#NEWLINE# def test_oas( ) : #NEWLINE# #INDENT# X_centered = ( X - X . mean ( axis = 0 ) ) #NEWLINE# oa = OAS ( assume_centered = True ) #NEWLINE# oa . fit ( X_centered ) #NEWLINE# shrinkage_ = oa . shrinkage_ #NEWLINE# score_ = oa . score ( X_centered ) #NEWLINE# ( oa_cov_from_mle , oa_shinkrage_from_mle ) = oas ( X_centered , assume_centered = True ) #NEWLINE# assert_array_almost_equal ( oa_cov_from_mle , oa . covariance_ , 4 ) #NEWLINE# assert_almost_equal ( oa_shinkrage_from_mle , oa . shrinkage_ ) #NEWLINE# scov = ShrunkCovariance ( shrinkage = oa . shrinkage_ , assume_centered = True ) #NEWLINE# scov . fit ( X_centered ) #NEWLINE# assert_array_almost_equal ( scov . covariance_ , oa . covariance_ , 4 ) #NEWLINE# X_1d = X [ : , 0 : 1 ] #NEWLINE# oa = OAS ( assume_centered = True ) #NEWLINE# oa . fit ( X_1d ) #NEWLINE# ( oa_cov_from_mle , oa_shinkrage_from_mle ) = oas ( X_1d , assume_centered = True ) #NEWLINE# assert_array_almost_equal ( oa_cov_from_mle , oa . covariance_ , 4 ) #NEWLINE# assert_almost_equal ( oa_shinkrage_from_mle , oa . shrinkage_ ) #NEWLINE# assert_array_almost_equal ( ( ( X_1d ** 2 ) . sum ( ) / n_samples ) , oa . covariance_ , 4 ) #NEWLINE# oa = OAS ( store_precision = False , assume_centered = True ) #NEWLINE# oa . fit ( X_centered ) #NEWLINE# assert_almost_equal ( oa . score ( X_centered ) , score_ , 4 ) #NEWLINE# assert ( oa . precision_ is None ) #NEWLINE# oa = OAS ( ) #NEWLINE# oa . fit ( X ) #NEWLINE# assert_almost_equal ( oa . shrinkage_ , shrinkage_ , 4 ) #NEWLINE# assert_almost_equal ( oa . score ( X ) , score_ , 4 ) #NEWLINE# ( oa_cov_from_mle , oa_shinkrage_from_mle ) = oas ( X ) #NEWLINE# assert_array_almost_equal ( oa_cov_from_mle , oa . covariance_ , 4 ) #NEWLINE# assert_almost_equal ( oa_shinkrage_from_mle , oa . shrinkage_ ) #NEWLINE# scov = ShrunkCovariance ( shrinkage = oa . shrinkage_ ) #NEWLINE# scov . fit ( X ) #NEWLINE# assert_array_almost_equal ( scov . covariance_ , oa . covariance_ , 4 ) #NEWLINE# X_1d = X [ : , 0 ] . reshape ( ( ( - 1 ) , 1 ) ) #NEWLINE# oa = OAS ( ) #NEWLINE# oa . fit ( X_centered ) #NEWLINE# ( oa_cov_from_mle , oa_shinkrage_from_mle ) = oas ( X_1d ) #NEWLINE# assert_array_almost_equal ( oa_cov_from_mle , oa . covariance_ , 4 ) #NEWLINE# assert_almost_equal ( oa_shinkrage_from_mle , oa . shrinkage_ ) #NEWLINE# assert_array_almost_equal ( empirical_covariance ( X_1d ) , oa . covariance_ , 4 ) #NEWLINE# X_1sample = np . arange ( 5 ) . reshape ( 1 , 5 ) #NEWLINE# oa = OAS ( ) #NEWLINE# assert_warns ( UserWarning , oa . fit , X_1sample ) #NEWLINE# assert_array_almost_equal ( oa . covariance_ , np . zeros ( shape = ( 5 , 5 ) , dtype = np . float64 ) ) #NEWLINE# oa = OAS ( store_precision = False ) #NEWLINE# oa . fit ( X ) #NEWLINE# assert_almost_equal ( oa . score ( X ) , score_ , 4 ) #NEWLINE# assert ( oa . precision_ is None )