<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> import statsmodels . sandbox . nonparametric . kernel_extras as smke <EOL> import statsmodels . sandbox . nonparametric . dgp_examples as dgp <EOL> class UnivariateFunc1a ( dgp . UnivariateFunc1 ) : <EOL> def het_scale ( self , x ) : <EOL> return <NUM_LIT:0.5> <EOL> seed = np . random . randint ( <NUM_LIT> ) <EOL> seed = <NUM_LIT> <EOL> print ( seed ) <EOL> np . random . seed ( seed ) <EOL> nobs , k_vars = <NUM_LIT> , <NUM_LIT:3> <EOL> x = np . random . uniform ( - <NUM_LIT:2> , <NUM_LIT:2> , size = ( nobs , k_vars ) ) <EOL> xb = x . sum ( <NUM_LIT:1> ) / <NUM_LIT:3> <EOL> k_vars_lin = <NUM_LIT:2> <EOL> x2 = np . random . uniform ( - <NUM_LIT:2> , <NUM_LIT:2> , size = ( nobs , k_vars_lin ) ) <EOL> funcs = [ <EOL> UnivariateFunc1a ( x = xb ) <EOL> ] <EOL> res = [ ] <EOL> fig = plt . figure ( ) <EOL> for i , func in enumerate ( funcs ) : <EOL> f = func <EOL> y = f . y + x2 . sum ( <NUM_LIT:1> ) <EOL> model = smke . SemiLinear ( y , x2 , x , '<STR_LIT>' , k_vars_lin ) <EOL> mean , mfx = model . fit ( ) <EOL> ax = fig . add_subplot ( <NUM_LIT:1> , <NUM_LIT:1> , i + <NUM_LIT:1> ) <EOL> f . plot ( ax = ax ) <EOL> xb_est = np . dot ( model . exog , model . b ) <EOL> sortidx = np . argsort ( xb_est ) <EOL> ax . plot ( f . x [ sortidx ] , mean [ sortidx ] , '<STR_LIT:o>' , color = '<STR_LIT:r>' , lw = <NUM_LIT:2> , label = '<STR_LIT>' ) <EOL> ax . legend ( loc = '<STR_LIT>' ) <EOL> res . append ( ( model , mean , mfx ) ) <EOL> print ( '<STR_LIT>' , model . b ) <EOL> print ( '<STR_LIT>' , ( y - ( xb_est + mean ) ) . std ( ) ) <EOL> print ( '<STR_LIT>' , ( y - ( f . y_true + x2 . sum ( <NUM_LIT:1> ) ) ) . std ( ) , <NUM_LIT:2> * f . het_scale ( <NUM_LIT:1> ) ) <EOL> fittedvalues = xb_est + mean <EOL> resid = np . squeeze ( model . endog ) - fittedvalues <EOL> print ( '<STR_LIT>' , np . corrcoef ( fittedvalues , resid ) [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , fittedvalues . var ( ) , fittedvalues . var ( ) / y . var ( ) ) <EOL> print ( '<STR_LIT>' , xb_est . var ( ) , xb_est . var ( ) / y . var ( ) ) <EOL> print ( '<STR_LIT>' , mean . var ( ) , mean . var ( ) / y . var ( ) ) <EOL> print ( '<STR_LIT>' , resid . var ( ) , resid . var ( ) / y . var ( ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( np . cov ( fittedvalues , resid ) / model . endog . var ( ddof = <NUM_LIT:1> ) ) <EOL> print ( '<STR_LIT>' , ( np . cov ( fittedvalues , resid ) / model . endog . var ( ddof = <NUM_LIT:1> ) ) . sum ( ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( np . cov ( np . column_stack ( ( xb_est , mean , resid ) ) , rowvar = False ) / model . endog . var ( ddof = <NUM_LIT:1> ) ) <EOL> fig . suptitle ( '<STR_LIT>' ) <EOL> fig . show ( ) <EOL> alpha = <NUM_LIT> <EOL> fig = plt . figure ( ) <EOL> ax = fig . add_subplot ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> ax . plot ( f . x [ sortidx ] , f . y [ sortidx ] , '<STR_LIT:o>' , color = '<STR_LIT:b>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . plot ( f . x [ sortidx ] , f . y_true [ sortidx ] , '<STR_LIT:o>' , color = '<STR_LIT:g>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . plot ( f . x [ sortidx ] , mean [ sortidx ] , '<STR_LIT:o>' , color = '<STR_LIT:r>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . legend ( loc = '<STR_LIT>' ) <EOL> sortidx = np . argsort ( xb_est + mean ) <EOL> fig = plt . figure ( ) <EOL> ax = fig . add_subplot ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> ax . plot ( f . x [ sortidx ] , y [ sortidx ] , '<STR_LIT:o>' , color = '<STR_LIT:b>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . plot ( f . x [ sortidx ] , f . y_true [ sortidx ] , '<STR_LIT:o>' , color = '<STR_LIT:g>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . plot ( f . x [ sortidx ] , ( xb_est + mean ) [ sortidx ] , '<STR_LIT:o>' , color = '<STR_LIT:r>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . legend ( loc = '<STR_LIT>' ) <EOL> ax . set_title ( '<STR_LIT>' ) <EOL> fig = plt . figure ( ) <EOL> sortidx0 = np . argsort ( xb ) <EOL> ax = fig . add_subplot ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> ax . plot ( f . y [ sortidx0 ] , '<STR_LIT:o>' , color = '<STR_LIT:b>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . plot ( f . y_true [ sortidx0 ] , '<STR_LIT:o>' , color = '<STR_LIT:g>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . plot ( mean [ sortidx0 ] , '<STR_LIT:o>' , color = '<STR_LIT:r>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . legend ( loc = '<STR_LIT>' ) <EOL> ax . set_title ( '<STR_LIT>' ) <EOL> ax = fig . add_subplot ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> ax . plot ( y - xb_est , '<STR_LIT:o>' , color = '<STR_LIT:b>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . plot ( f . y_true , '<STR_LIT:o>' , color = '<STR_LIT:g>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . plot ( mean , '<STR_LIT:o>' , color = '<STR_LIT:r>' , lw = <NUM_LIT:2> , alpha = alpha , label = '<STR_LIT>' ) <EOL> ax . legend ( loc = '<STR_LIT>' ) <EOL> ax . set_title ( '<STR_LIT>' ) <EOL> plt . figure ( ) <EOL> plt . plot ( y , xb_est + mean , '<STR_LIT:.>' ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> plt . show ( ) </s>
