<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import numpy as np <EOL> from statsmodels . stats . correlation_tools import ( <EOL> corr_nearest , corr_clipped , cov_nearest ) <EOL> examples = [ '<STR_LIT:all>' ] <EOL> if '<STR_LIT:all>' in examples : <EOL> x0 = np . array ( [ [ <NUM_LIT:1> , - <NUM_LIT> , - <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT:1> , - <NUM_LIT> ] , [ - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT:1> ] ] ) <EOL> x = np . array ( [ [ <NUM_LIT:1> , - <NUM_LIT> , - <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT:1> , - <NUM_LIT> ] , [ - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT:1> ] ] ) <EOL> n_fact = <NUM_LIT:2> <EOL> print ( '<STR_LIT>' , np . linalg . eigvalsh ( x ) ) <EOL> y = corr_nearest ( x , n_fact = <NUM_LIT:100> ) <EOL> print ( '<STR_LIT>' , np . linalg . eigvalsh ( y ) ) <EOL> print ( y ) <EOL> y = corr_nearest ( x , n_fact = <NUM_LIT:100> , threshold = <NUM_LIT> ) <EOL> print ( '<STR_LIT>' , np . linalg . eigvalsh ( y ) ) <EOL> print ( y ) <EOL> y = corr_clipped ( x , threshold = <NUM_LIT> ) <EOL> print ( '<STR_LIT>' , np . linalg . eigvalsh ( y ) ) <EOL> print ( y ) <EOL> np . set_printoptions ( precision = <NUM_LIT:4> ) <EOL> print ( '<STR_LIT>' ) <EOL> k_vars = <NUM_LIT:5> <EOL> diag_idx = np . arange ( k_vars ) <EOL> for ii in range ( <NUM_LIT:10> ) : <EOL> print ( ) <EOL> x = np . random . uniform ( - <NUM_LIT:1> , <NUM_LIT:1> , size = ( k_vars , k_vars ) ) <EOL> x = ( x + x . T ) * <NUM_LIT:0.5> <EOL> x [ diag_idx , diag_idx ] = <NUM_LIT:1> <EOL> print ( ) <EOL> print ( np . sort ( np . linalg . eigvals ( x ) ) , '<STR_LIT>' ) <EOL> yn = corr_nearest ( x , threshold = <NUM_LIT> , n_fact = <NUM_LIT:200> ) <EOL> print ( np . sort ( np . linalg . eigvals ( yn ) ) , ( ( yn - x ) ** <NUM_LIT:2> ) . sum ( ) , '<STR_LIT>' ) <EOL> yc = corr_clipped ( x , threshold = <NUM_LIT> ) <EOL> print ( np . sort ( np . linalg . eigvals ( yc ) ) , ( ( yc - x ) ** <NUM_LIT:2> ) . sum ( ) , '<STR_LIT>' ) <EOL> import time <EOL> t0 = time . time ( ) <EOL> for _ in range ( <NUM_LIT:100> ) : <EOL> corr_nearest ( x , threshold = <NUM_LIT> , n_fact = <NUM_LIT:100> ) <EOL> t1 = time . time ( ) <EOL> for _ in range ( <NUM_LIT:1000> ) : <EOL> corr_clipped ( x , threshold = <NUM_LIT> ) <EOL> t2 = time . time ( ) <EOL> print ( '<STR_LIT>' , t1 - t0 , t2 - t1 ) <EOL> if '<STR_LIT:all>' in examples : <EOL> x2 = np . array ( [ <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> ] ) . reshape ( <NUM_LIT:6> , <NUM_LIT:6> ) <EOL> y1 = corr_nearest ( x2 , threshold = <NUM_LIT> , n_fact = <NUM_LIT:200> ) <EOL> y2 = corr_clipped ( x2 , threshold = <NUM_LIT> ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( np . sort ( np . linalg . eigvals ( x2 ) ) , '<STR_LIT>' ) <EOL> print ( np . sort ( np . linalg . eigvals ( y1 ) ) , ( ( y1 - x2 ) ** <NUM_LIT:2> ) . sum ( ) , '<STR_LIT>' ) <EOL> print ( np . sort ( np . linalg . eigvals ( y1 ) ) , ( ( y2 - x2 ) ** <NUM_LIT:2> ) . sum ( ) , '<STR_LIT>' ) </s>
