<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import numpy as np <EOL> import statsmodels . sandbox . distributions . mv_normal as mvd <EOL> from numpy . testing import assert_array_almost_equal <EOL> cov3 = np . array ( [ [ <NUM_LIT:1.> , <NUM_LIT:0.5> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> mu = np . array ( [ - <NUM_LIT:1> , <NUM_LIT:0.0> , <NUM_LIT> ] ) <EOL> mvn3 = mvd . MVNormal ( mu , cov3 ) <EOL> x = mvn3 . rvs ( size = <NUM_LIT> ) <EOL> xli = [ [ <NUM_LIT> , <NUM_LIT:1.> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:1.> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT> ] ] <EOL> xliarr = np . asarray ( xli ) . T [ None , : , : ] <EOL> r_cdf = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> r_cdf_errors = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> n_cdf = [ mvn3 . cdf ( a ) for a in xli ] <EOL> assert_array_almost_equal ( r_cdf , n_cdf , decimal = <NUM_LIT:4> ) <EOL> print ( n_cdf ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( ( x < np . array ( xli [ <NUM_LIT:0> ] ) ) . all ( - <NUM_LIT:1> ) . mean ( <NUM_LIT:0> ) ) <EOL> print ( ( x [ ... , None ] < xliarr ) . all ( <NUM_LIT:1> ) . mean ( <NUM_LIT:0> ) ) <EOL> print ( mvn3 . expect_mc ( lambda x : ( x < xli [ <NUM_LIT:0> ] ) . all ( - <NUM_LIT:1> ) , size = <NUM_LIT> ) ) <EOL> print ( mvn3 . expect_mc ( lambda x : ( x [ ... , None ] < xliarr ) . all ( <NUM_LIT:1> ) , size = <NUM_LIT> ) ) <EOL> mvn3n = mvn3 . normalized ( ) <EOL> assert_array_almost_equal ( mvn3n . cov , mvn3n . corr , decimal = <NUM_LIT:15> ) <EOL> assert_array_almost_equal ( mvn3n . mean , np . zeros ( <NUM_LIT:3> ) , decimal = <NUM_LIT:15> ) <EOL> xn = mvn3 . normalize ( x ) <EOL> xn_cov = np . cov ( xn , rowvar = <NUM_LIT:0> ) <EOL> assert_array_almost_equal ( mvn3n . cov , xn_cov , decimal = <NUM_LIT:2> ) <EOL> assert_array_almost_equal ( np . zeros ( <NUM_LIT:3> ) , xn . mean ( <NUM_LIT:0> ) , decimal = <NUM_LIT:2> ) <EOL> mvn3n2 = mvn3 . normalized2 ( ) <EOL> assert_array_almost_equal ( mvn3n . cov , mvn3n2 . cov , decimal = <NUM_LIT:2> ) <EOL> xs = mvn3 . standardize ( x ) <EOL> xs_cov = np . cov ( xn , rowvar = <NUM_LIT:0> ) <EOL> assert_array_almost_equal ( mvn3 . corr , xs_cov , decimal = <NUM_LIT:2> ) <EOL> assert_array_almost_equal ( np . zeros ( <NUM_LIT:3> ) , xs . mean ( <NUM_LIT:0> ) , decimal = <NUM_LIT:2> ) <EOL> mv2m = mvn3 . marginal ( np . array ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) ) <EOL> print ( mv2m . mean ) <EOL> print ( mv2m . cov ) <EOL> mv2c = mvn3 . conditional ( np . array ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) , [ <NUM_LIT:0> ] ) <EOL> print ( mv2c . mean ) <EOL> print ( mv2c . cov ) <EOL> mv2c = mvn3 . conditional ( np . array ( [ <NUM_LIT:0> ] ) , [ <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> print ( mv2c . mean ) <EOL> print ( mv2c . cov ) <EOL> import statsmodels . api as sm <EOL> mod = sm . OLS ( x [ : , <NUM_LIT:0> ] , sm . add_constant ( x [ : , <NUM_LIT:1> : ] , prepend = True ) ) <EOL> res = mod . fit ( ) <EOL> print ( res . model . predict ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] ) ) ) <EOL> mv2c = mvn3 . conditional ( np . array ( [ <NUM_LIT:0> ] ) , [ <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> print ( mv2c . mean ) <EOL> mv2c = mvn3 . conditional ( np . array ( [ <NUM_LIT:0> ] ) , [ <NUM_LIT:1> , <NUM_LIT:1> ] ) <EOL> print ( res . model . predict ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) ) <EOL> print ( mv2c . mean ) <EOL> mvt3 = mvd . MVT ( mu , cov3 , <NUM_LIT:4> ) <EOL> xt = mvt3 . rvs ( size = <NUM_LIT> ) <EOL> assert_array_almost_equal ( mvt3 . cov , np . cov ( xt , rowvar = <NUM_LIT:0> ) , decimal = <NUM_LIT:1> ) <EOL> mvt3s = mvt3 . standardized ( ) <EOL> mvt3n = mvt3 . normalized ( ) <EOL> assert_array_almost_equal ( mvt3 . corr , mvt3n . sigma , decimal = <NUM_LIT:15> ) <EOL> assert_array_almost_equal ( mvt3n . corr , mvt3n . sigma , decimal = <NUM_LIT:15> ) <EOL> assert_array_almost_equal ( np . eye ( <NUM_LIT:3> ) , mvt3s . sigma , decimal = <NUM_LIT:15> ) <EOL> xts = mvt3 . standardize ( xt ) <EOL> xts_cov = np . cov ( xts , rowvar = <NUM_LIT:0> ) <EOL> xtn = mvt3 . normalize ( xt ) <EOL> xtn_cov = np . cov ( xtn , rowvar = <NUM_LIT:0> ) <EOL> xtn_corr = np . corrcoef ( xtn , rowvar = <NUM_LIT:0> ) <EOL> assert_array_almost_equal ( mvt3n . mean , xtn . mean ( <NUM_LIT:0> ) , decimal = <NUM_LIT:2> ) <EOL> assert_array_almost_equal ( mvt3n . corr , xtn_corr , decimal = <NUM_LIT:1> ) <EOL> assert_array_almost_equal ( mvt3n . cov , xtn_cov , decimal = <NUM_LIT:1> ) <EOL> assert_array_almost_equal ( mvt3s . cov , xts_cov , decimal = <NUM_LIT:1> ) <EOL> a = [ <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT> ] <EOL> mvt3_cdf0 = mvt3 . cdf ( a ) <EOL> print ( mvt3_cdf0 ) <EOL> print ( ( xt < np . array ( a ) ) . all ( - <NUM_LIT:1> ) . mean ( <NUM_LIT:0> ) ) <EOL> print ( '<STR_LIT:R>' , <NUM_LIT> ) <EOL> print ( '<STR_LIT:R>' , <NUM_LIT> ) <EOL> print ( '<STR_LIT>' , mvt3_cdf0 - <NUM_LIT> ) <EOL> a = [ <NUM_LIT:0.0> , <NUM_LIT:0.5> , <NUM_LIT:1.0> ] <EOL> mvt3_cdf1 = mvt3 . cdf ( a ) <EOL> print ( mvt3_cdf1 ) <EOL> print ( ( xt < np . array ( a ) ) . all ( - <NUM_LIT:1> ) . mean ( <NUM_LIT:0> ) ) <EOL> print ( '<STR_LIT:R>' , <NUM_LIT> ) <EOL> print ( '<STR_LIT:R>' , <NUM_LIT> ) <EOL> print ( '<STR_LIT>' , mvt3_cdf1 - <NUM_LIT> ) <EOL> assert_array_almost_equal ( mvt3_cdf0 , <NUM_LIT> , decimal = <NUM_LIT:5> ) <EOL> assert_array_almost_equal ( mvt3_cdf1 , <NUM_LIT> , decimal = <NUM_LIT:5> ) <EOL> import statsmodels . distributions . mixture_rvs as mix <EOL> mu2 = np . array ( [ <NUM_LIT:4> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> mvn32 = mvd . MVNormal ( mu2 , cov3 / <NUM_LIT> , <NUM_LIT:4> ) <EOL> md = mix . mv_mixture_rvs ( [ <NUM_LIT> , <NUM_LIT> ] , <NUM_LIT:5> , [ mvt3 , mvt3n ] , <NUM_LIT:3> ) <EOL> rvs = mix . mv_mixture_rvs ( [ <NUM_LIT> , <NUM_LIT> ] , <NUM_LIT> , [ mvn3 , mvn32 ] , <NUM_LIT:3> ) <EOL> import matplotlib . pyplot as plt <EOL> fig = plt . figure ( ) <EOL> fig . add_subplot ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> plt . plot ( rvs [ : , <NUM_LIT:0> ] , rvs [ : , <NUM_LIT:1> ] , '<STR_LIT:.>' , alpha = <NUM_LIT> ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> fig . add_subplot ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> plt . plot ( rvs [ : , <NUM_LIT:0> ] , rvs [ : , <NUM_LIT:2> ] , '<STR_LIT:.>' , alpha = <NUM_LIT> ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> fig . add_subplot ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> plt . plot ( rvs [ : , <NUM_LIT:1> ] , rvs [ : , <NUM_LIT:2> ] , '<STR_LIT:.>' , alpha = <NUM_LIT> ) <EOL> plt . title ( '<STR_LIT>' ) </s>
