(objeto):
    ObjName = "images\\" + objeto + ".PNG"
    SiExiste = pyautogui.locateOnScreen(ObjName)
    button7x, button7y = pyautogui.center(SiExiste)
    pyautogui.click(button7x, button7y)

# Funcion <validarValor>
# Verifica si existe una imagen en pantalla
def validarValor(resultado):
    ObjName = "images\\" + resultado + ".PNG"
    SiExiste = pyautogui.locateOnScreen(ObjName)
    if (SiExiste == None):
        resultado = False
    else:
        resultado = True
    return resultado

def insertarMail(usuario,proveedor):
    pulsarBoton("USUARIO")
    pyautogui.typewrite(usuario)
    pyautogui.keyDown('altright')
    pyautogui.keyDown('q')
    pyautogui.keyUp('altright')
    pyautogui.keyUp('q')
    pyautogui.typewrite(proveedor)
    pyautogui.typewrite(".com")

# Posiciona el cursor en el ángulo superior izquierdo
pyautogui.moveTo(5, 5)

# Abre la página
global URL
URL="http://www.cablevisionfibertel.com.ar"
driver = webdriver.Chrome('C:\\Webdrivers\\chromedriver.exe')
#driver.set_page_load_timeout(10)
driver.get(URL)
print(driver.title)
time.sleep(5)
driver.maximize_window()
wait = WebDriverWait(driver, 5)
open_file("params\\PARAMS.xlsx",1)

pyautogui.moveTo(5, 505)
time.sleep(1)
pyautogui.click(5, 505,3)

# Valida que esté abierta la página principal
assert (esperarCarga("MAINPAGE", 10000))

assert (esperarCarga("INGRESAR", 10000))

'''''
ObjName = "images\\INGRESAR.PNG"
SiExiste = pyautogui.locateOnScreen(ObjName)
button7x, button7y = pyautogui.center(SiExiste)
pyautogui.click(button7x, button7y)
'''''

pulsarBoton("INGRESAR")

pyautogui.moveTo(5, 505)
time.sleep(1)
pyautogui.click(5, 505,3)

# Valida que esté abierta la página Login
assert (esperarCarga("LOGINPAGE", 10000))

pyautogui.moveTo(5, 505)
time.sleep(1)
pyautogui.click(5, 505,3)

# Ingresa Usuario

'''''
pulsarBoton("USUARIO")

email = usuario + "@" + proveedor
element = wait.until(EC.presence_of_element_located((By.NAME, email)))
driver.find_element_by_name("userName").send_keys(usuario)

pulsarBoton("CLAVE")

# Ingresa Contraseeña
element = wait.until(EC.presence_of_element_located((By.NAME, clave)))
driver.find_element_by_name("password").send_keys(clave)

# Hace click en el botón Login
clickID(driver,"ingresar-button")

insertarMail("martinjavierd","gmail")
'''''

# Realizza la operación LOGIN
pulsarBoton("USUARIO")

pyautogui.typewrite("martinjavierd")
pyautogui.keyDown('altright')
pyautogui.keyDown('q')
pyautogui.keyUp('altright')
pyautogui.keyUp('q')
pyautogui.typewrite("gmail.com")

pulsarBoton("CLAVE")

time.sleep(1)

pyautogui.typewrite("CrudSec2")

pyautogui.moveTo(5, 505)
time.sleep(1)
pyautogui.click(5, 505,3)

pulsarBoton("BTNLOGIN")

# Valida el Resultado esperado

pyautogui.moveTo(5, 505)
time.sleep(1)
pyautogui.click(5, 505,3)

assert (esperarCarga("VALIDALOG", 10000))

#screenShotGUI(caso, nombre)

# Termina el proceso
driver.close()# Statistical Inference for Lasso

##### Posted on Apr 15, 2019

This note is based on the Chapter 6 of Hastie, T., Tibshirani, R., & Wainwright, M. (2015). Statistical Learning with Sparsity. 362..

The interest to determine the statistical strength of the included variables, but the adaptive nature of the estimation procedure makes this problem difficult–both conceptually and analytically.

## The Bayesian Lasso

Consider the model

\begin{align*} \y \mid \beta,\lambda, \sigma & \sim N(\X\beta, \sigma^2\I_{N\times N})\\ \beta \mid \lambda,\sigma &\sim \prod_{j=1}^p\frac{\lambda}{2\sigma}e^{-\frac \lambda\sigma\vert\beta_j\vert}\,, \end{align*}

where the second one is the i.i.d. Laplacian prior. It can be showed that the negative log posterior density for $\beta\mid \y,\lambda,\sigma$ is given by

$\frac{1}{2\sigma^2}\Vert \y-\X\beta\Vert_2^2 + \frac\lambda\sigma\Vert\beta\Vert_1$

where the additive constant independent of $\beta$ is dropped.

## The Bootstrap

Consider the sampling distribution of $\hat\beta(\hat\lambda_{CV})$, where $\hat\lambda_{CV}$ minimizes the CV error. In other words, we are interested in the distribution of the random estimate $\hat\beta(\hat\lambda_{CV})$ as a function of the $N$ i.i.d. samples $\{(x_i,y_i)\}_{i=1}^N$.

The nonparametric bootstrap is one method for approximating this sampling distribution: it approximates the CDF $\hat F_N$ defined by the $N$ samples, then draw $N$ samples from $\hat F_N$, which amounts to drawing $N$ samples with replacement from the given dataset. In fact, the empirical distribution function $\hat F_N$ is the nonparametric maximum likelihood estimate of $F$.

In contrast, the parametric bootstrap samples from a parametric estimate of $F$. Here, we would fit $\X$ and obtain estimates $\hat\beta$ and $\hat\sigma^2$ either from the full least-squares fit, or from the fitted lasso with parameter $\lambda$, then we would sample $\y$ values from the Gaussian model, with $\beta$ and $\sigma^2$ replaced by $\hat\beta$ and $\hat\sigma^2$.

## Post-Selection Inference for the Lasso

### The Covariance Test

Denote the knots returned by the LAR algorithm by $\lambda_1>\lambda_2>\cdots>\lambda_K$. These are the values of the regularization parameter $\lambda$ where there is a change in the set of active predictors. Why?

Suppose that we wish to test significance of the predictor entered by LAR at $\lambda_k$. Let $\cA_{k-1}$ be the active set before this predictor was added and let the estimate at the end of this step be $\hat\beta(\lambda_{k+1})$. Refit the lasso, keeping $\lambda = \lambda_{k+1}$ but using just the variables in $\cA_{k-1}$, which yields the estimate $\hat\beta_{\cA_{k-1}}(\lambda_{k+1})$. The covariance test statistic is defined by

$T_k = \frac{1}{\sigma^2}\left( \langle \y,\X\hat\beta(\lambda_{k+1}) \rangle - \langle \y,\X\hat\beta_{\cA_{k-1}}(\lambda_{k+1}) \rangle \right)\,.$

Under certain conditions,

$T_k\rightarrow_d \text{Exp}(1)\,.$

### A General Scheme for Post-Selection Inference

