From bad9aa89199796735424d644da42552ef295ba92 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:40:58 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../hessian_approximation/compute_hessian.py | 93 ++++++++++--------- .../tests/property/property_auxiliary.py | 1 + development/tests/property/run.py | 1 + development/tests/reliability/reliability.py | 1 + development/tests/replication/run.py | 1 + docs/__init__.py | 1 + docs/source/figures/create.py | 1 + docs/source/figures/scripts/__init__.py | 1 + .../figures/scripts/fig-distribution-joint.py | 1 + .../figures/scripts/fig-eh-marginal-effect.py | 1 + .../scripts/fig-local-average-treatment.py | 1 + .../figures/scripts/fig-reliability-par.py | 1 + .../figures/scripts/fig-treatment-effects.py | 1 + .../scripts/fig-weights-marginal-effect.py | 1 + docs/source/figures/scripts/fig_config.py | 1 + grmpy/__init__.py | 1 + grmpy/estimate/estimate.py | 1 + grmpy/estimate/estimate_output.py | 1 + grmpy/estimate/estimate_par.py | 31 +++---- grmpy/estimate/estimate_semipar.py | 1 + grmpy/grmpy_config.py | 1 + grmpy/plot/plot_auxiliary.py | 1 + grmpy/read/read.py | 1 + grmpy/read/read_auxiliary.py | 1 + grmpy/simulate/simulate.py | 1 + grmpy/simulate/simulate_auxiliary.py | 1 + grmpy/test/auxiliary.py | 13 +-- grmpy/test/conftest.py | 1 + grmpy/test/random_init.py | 1 + grmpy/test/resources/tutorial.py | 1 + grmpy/test/test_integration_semipar.py | 1 + grmpy/test/test_quality.py | 1 + grmpy/test/test_unit.py | 1 + grmpy/test/test_unit_semipar.py | 1 + .../tutorial_semipar_auxiliary.py | 1 + 35 files changed, 101 insertions(+), 68 deletions(-) diff --git a/development/hessian_approximation/compute_hessian.py b/development/hessian_approximation/compute_hessian.py index 3d5acf98..23927895 100644 --- a/development/hessian_approximation/compute_hessian.py +++ b/development/hessian_approximation/compute_hessian.py @@ -1,6 +1,7 @@ """This module provides the analytical solution for computing the hessian matrix of our loglikelihood function """ + import numpy as np from scipy.stats import norm @@ -29,9 +30,9 @@ def compute_hessian(x0, X1, X0, Z1, Z0, Y1, Y0): # aux_params nu1 = (Y1 - np.dot(beta1, X1.T)) / sd1 - lambda1 = (np.dot(gamma, Z1.T) - rho1v * nu1) / (np.sqrt(1 - rho1v ** 2)) + lambda1 = (np.dot(gamma, Z1.T) - rho1v * nu1) / (np.sqrt(1 - rho1v**2)) nu0 = (Y0 - np.dot(beta0, X0.T)) / sd0 - lambda0 = (np.dot(gamma, Z0.T) - rho0v * nu0) / (np.sqrt(1 - rho0v ** 2)) + lambda0 = (np.dot(gamma, Z0.T) - rho0v * nu0) / (np.sqrt(1 - rho0v**2)) eta1 = ( -lambda1 * norm.pdf(lambda1) * norm.cdf(lambda1) - norm.pdf(lambda1) ** 2 @@ -113,13 +114,13 @@ def calc_hess_beta1( """ # define some auxiliary variables - rho_aux1 = lambda1 * rho1v / (1 - rho1v ** 2) - nu1 / (1 - rho1v ** 2) ** 0.5 - rho_aux2 = rho1v ** 2 / ((1 - rho1v ** 2) ** (3 / 2)) + 1 / (1 - rho1v ** 2) ** 0.5 - sd_aux1 = rho1v ** 2 / (1 - rho1v ** 2) - sd_aux2 = rho1v / np.sqrt(1 - rho1v ** 2) + rho_aux1 = lambda1 * rho1v / (1 - rho1v**2) - nu1 / (1 - rho1v**2) ** 0.5 + rho_aux2 = rho1v**2 / ((1 - rho1v**2) ** (3 / 2)) + 1 / (1 - rho1v**2) ** 0.5 + sd_aux1 = rho1v**2 / (1 - rho1v**2) + sd_aux2 = rho1v / np.sqrt(1 - rho1v**2) # derivation wrt beta1 der_b1_beta1 = -( - X1X1 * (rho1v ** 2 / (1 - rho1v ** 2)) * 1 / sd1 ** 2 - X1.T @ X1 / sd1 ** 2 + X1X1 * (rho1v**2 / (1 - rho1v**2)) * 1 / sd1**2 - X1.T @ X1 / sd1**2 ) # add zeros for derv beta 0 der_b1_beta1 = np.concatenate( @@ -127,7 +128,7 @@ def calc_hess_beta1( ) # derivation wrt gamma - der_b1_gamma = -(X1Z1 * rho1v / (sd1 * (1 - rho1v ** 2))) + der_b1_gamma = -(X1Z1 * rho1v / (sd1 * (1 - rho1v**2))) der_b1_gamma = np.concatenate((der_b1_beta1, der_b1_gamma), axis=1) # derv wrt sigma 1 der_b1_sd = ( @@ -150,7 +151,7 @@ def calc_hess_beta1( # derv wrt rho1 der_b1_rho = ( -( - eta1 * rho_aux1 * rho1v / ((1 - rho1v ** 2) ** 0.5) + eta1 * rho_aux1 * rho1v / ((1 - rho1v**2) ** 0.5) + norm.pdf(lambda1) / norm.cdf(lambda1) * rho_aux2 ) * 1 @@ -176,21 +177,21 @@ def calc_hess_beta0( """ # define some aux_vars - rho_aux1 = lambda0 * rho0v / (1 - rho0v ** 2) - nu0 / (1 - rho0v ** 2) ** 0.5 - rho_aux2 = rho0v ** 2 / ((1 - rho0v ** 2) ** (3 / 2)) + 1 / (1 - rho0v ** 2) ** 0.5 - sd_aux1 = rho0v ** 2 / (1 - rho0v ** 2) - sd_aux2 = rho0v / (np.sqrt(1 - rho0v ** 2)) + rho_aux1 = lambda0 * rho0v / (1 - rho0v**2) - nu0 / (1 - rho0v**2) ** 0.5 + rho_aux2 = rho0v**2 / ((1 - rho0v**2) ** (3 / 2)) + 1 / (1 - rho0v**2) ** 0.5 + sd_aux1 = rho0v**2 / (1 - rho0v**2) + sd_aux2 = rho0v / (np.sqrt(1 - rho0v**2)) # add zeros for beta0 der_b0_beta1 = np.zeros((n_col_X1, n_col_X0)) # beta0 der_b0_beta0 = ( - -(X0X0 * (rho0v ** 2 / (1 - rho0v ** 2)) * 1 / sd0 ** 2) + X0.T @ X0 / sd0 ** 2 + -(X0X0 * (rho0v**2 / (1 - rho0v**2)) * 1 / sd0**2) + X0.T @ X0 / sd0**2 ) der_b0_beta0 = np.concatenate((der_b0_beta1, der_b0_beta0), axis=1) # gamma - der_b0_gamma = -X0Z0 * rho0v / (1 - rho0v ** 2) * 1 / sd0 + der_b0_gamma = -X0Z0 * rho0v / (1 - rho0v**2) * 1 / sd0 der_b0_gamma = np.concatenate((der_b0_beta0, der_b0_gamma), axis=1) # add zeros for sigma1 and rho1 @@ -204,7 +205,7 @@ def calc_hess_beta0( - 2 * nu0 ) * 1 - / sd0 ** 2 + / sd0**2 ) der_b0_sd = np.expand_dims((der_b0_sd.T @ X0), 1) der_b0_sd = np.concatenate((der_b0_gamma, der_b0_sd), axis=1) @@ -212,7 +213,7 @@ def calc_hess_beta0( # rho der_b0_rho = ( ( - eta0 * -rho_aux1 * (rho0v / ((1 - rho0v ** 2) ** 0.5)) + eta0 * -rho_aux1 * (rho0v / ((1 - rho0v**2) ** 0.5)) + norm.pdf(lambda0) / (1 - norm.cdf(lambda0)) * rho_aux2 ) * 1 @@ -252,7 +253,7 @@ def calc_hess_gamma( der_gamma_beta = np.zeros((Z1.shape[1], num_col_X1X0)) - der_g_gamma = -(1 / (1 - rho1v ** 2) * Z1Z1 + 1 / (1 - rho0v ** 2) * Z0Z0) + der_g_gamma = -(1 / (1 - rho1v**2) * Z1Z1 + 1 / (1 - rho0v**2) * Z0Z0) der_g_gamma = np.concatenate((der_gamma_beta, der_g_gamma), axis=1) # sigma1 @@ -261,19 +262,19 @@ def calc_hess_gamma( @ np.einsum("ij, i ->ij", X1, nu1) / sd1 * rho1v - / (1 - rho1v ** 2) + / (1 - rho1v**2) )[:, 0] der_g_sd1 = np.expand_dims(der_g_sd1, 0).T der_g_sd1 = np.concatenate((der_g_gamma, der_g_sd1), axis=1) # rho1 aux_rho11 = np.einsum("ij, i ->ij", Z1, eta1).T @ ( - lambda1 * rho1v / (1 - rho1v ** 2) - nu1 / np.sqrt(1 - rho1v ** 2) + lambda1 * rho1v / (1 - rho1v**2) - nu1 / np.sqrt(1 - rho1v**2) ) aux_rho21 = Z1.T @ (norm.pdf(lambda1) / norm.cdf(lambda1)) - der_g_rho1 = -aux_rho11 * 1 / (np.sqrt(1 - rho1v ** 2)) - aux_rho21 * rho1v / ( - (1 - rho1v ** 2) ** (3 / 2) + der_g_rho1 = -aux_rho11 * 1 / (np.sqrt(1 - rho1v**2)) - aux_rho21 * rho1v / ( + (1 - rho1v**2) ** (3 / 2) ) der_g_rho1 = np.expand_dims(der_g_rho1, 0).T der_g_rho1 = np.concatenate((der_g_sd1, der_g_rho1), axis=1) @@ -284,19 +285,19 @@ def calc_hess_gamma( @ np.einsum("ij, i ->ij", X0, nu0) / sd0 * rho0v - / (1 - rho0v ** 2) + / (1 - rho0v**2) )[:, 0] der_g_sd0 = np.expand_dims(der_g_sd0, 0).T der_g_sd0 = np.concatenate((der_g_rho1, -der_g_sd0), axis=1) # rho1 aux_rho10 = np.einsum("ij, i ->ij", Z0, eta0).T @ ( - lambda0 * rho0v / (1 - rho0v ** 2) - nu0 / np.sqrt(1 - rho0v ** 2) + lambda0 * rho0v / (1 - rho0v**2) - nu0 / np.sqrt(1 - rho0v**2) ) aux_rho20 = -Z0.T @ (norm.pdf(lambda0) / (1 - norm.cdf(lambda0))) - der_g_rho0 = aux_rho10 * 1 / (np.sqrt(1 - rho0v ** 2)) + aux_rho20 * rho0v / ( - (1 - rho0v ** 2) ** (3 / 2) + der_g_rho0 = aux_rho10 * 1 / (np.sqrt(1 - rho0v**2)) + aux_rho20 * rho0v / ( + (1 - rho0v**2) ** (3 / 2) ) der_g_rho0 = np.expand_dims(-der_g_rho0, 0).T der_g_rho0 = np.concatenate((der_g_sd0, der_g_rho0), axis=1) @@ -328,15 +329,15 @@ def calc_hess_dist( Delta_sd1 = ( +1 / sd1 - (norm.pdf(lambda1) / norm.cdf(lambda1)) - * (rho1v * nu1 / (np.sqrt(1 - rho1v ** 2) * sd1)) - - nu1 ** 2 / sd1 + * (rho1v * nu1 / (np.sqrt(1 - rho1v**2) * sd1)) + - nu1**2 / sd1 ) Delta_sd1_der = ( nu1 / sd1 * ( - -eta1 * (rho1v ** 2 * nu1) / (1 - rho1v ** 2) - + (norm.pdf(lambda1) / norm.cdf(lambda1)) * rho1v / np.sqrt(1 - rho1v ** 2) + -eta1 * (rho1v**2 * nu1) / (1 - rho1v**2) + + (norm.pdf(lambda1) / norm.cdf(lambda1)) * rho1v / np.sqrt(1 - rho1v**2) + 2 * nu1 ) ) @@ -344,36 +345,36 @@ def calc_hess_dist( Delta_sd0 = ( +1 / sd0 + (norm.pdf(lambda0) / (1 - norm.cdf(lambda0))) - * (rho0v * nu0 / (np.sqrt(1 - rho0v ** 2) * sd0)) - - nu0 ** 2 / sd0 + * (rho0v * nu0 / (np.sqrt(1 - rho0v**2) * sd0)) + - nu0**2 / sd0 ) Delta_sd0_der = ( nu0 / sd0 * ( - -eta0 * (rho0v ** 2 * nu0) / (1 - rho0v ** 2) + -eta0 * (rho0v**2 * nu0) / (1 - rho0v**2) - (norm.pdf(lambda0) / (1 - norm.cdf(lambda0))) * rho0v - / np.sqrt(1 - rho0v ** 2) + / np.sqrt(1 - rho0v**2) + 2 * nu0 ) ) - aux_rho11 = lambda1 * rho1v / (1 - rho1v ** 2) - nu1 / np.sqrt(1 - rho1v ** 2) - aux_rho12 = 1 / (1 - rho1v ** 2) ** (3 / 2) + aux_rho11 = lambda1 * rho1v / (1 - rho1v**2) - nu1 / np.sqrt(1 - rho1v**2) + aux_rho12 = 1 / (1 - rho1v**2) ** (3 / 2) - aux_rho_rho11 = (np.dot(gamma, Z1.T) * rho1v - nu1) / (1 - rho1v ** 2) ** (3 / 2) + aux_rho_rho11 = (np.dot(gamma, Z1.T) * rho1v - nu1) / (1 - rho1v**2) ** (3 / 2) aux_rho_rho12 = ( - 2 * np.dot(gamma, Z1.T) * rho1v ** 2 + np.dot(gamma, Z1.T) - 3 * nu1 * rho1v - ) / (1 - rho1v ** 2) ** (5 / 2) + 2 * np.dot(gamma, Z1.T) * rho1v**2 + np.dot(gamma, Z1.T) - 3 * nu1 * rho1v + ) / (1 - rho1v**2) ** (5 / 2) - aux_rho01 = lambda0 * rho0v / (1 - rho0v ** 2) - nu0 / np.sqrt(1 - rho0v ** 2) - aux_rho02 = 1 / (1 - rho0v ** 2) ** (3 / 2) + aux_rho01 = lambda0 * rho0v / (1 - rho0v**2) - nu0 / np.sqrt(1 - rho0v**2) + aux_rho02 = 1 / (1 - rho0v**2) ** (3 / 2) - aux_rho_rho01 = (np.dot(gamma, Z0.T) * rho0v - nu0) / (1 - rho0v ** 2) ** (3 / 2) + aux_rho_rho01 = (np.dot(gamma, Z0.T) * rho0v - nu0) / (1 - rho0v**2) ** (3 / 2) aux_rho_rho02 = ( - 2 * np.dot(gamma, Z0.T) * rho0v ** 2 + np.dot(gamma, Z0.T) - 3 * nu0 * rho0v - ) / (1 - rho0v ** 2) ** (5 / 2) + 2 * np.dot(gamma, Z0.T) * rho0v**2 + np.dot(gamma, Z0.T) - 3 * nu0 * rho0v + ) / (1 - rho0v**2) ** (5 / 2) # for sigma1 @@ -385,7 +386,7 @@ def calc_hess_dist( 1 / sd1 * ( - -eta1 * aux_rho11 * (rho1v * nu1) / (np.sqrt(1 - rho1v ** 2)) + -eta1 * aux_rho11 * (rho1v * nu1) / (np.sqrt(1 - rho1v**2)) - (norm.pdf(lambda1) / norm.cdf(lambda1)) * aux_rho12 * nu1 ) ) @@ -411,7 +412,7 @@ def calc_hess_dist( 1 / sd0 * ( - -eta0 * aux_rho01 * (rho0v * nu0) / (np.sqrt(1 - rho0v ** 2)) + -eta0 * aux_rho01 * (rho0v * nu0) / (np.sqrt(1 - rho0v**2)) + (norm.pdf(lambda0) / (1 - norm.cdf(lambda0))) * aux_rho02 * nu0 ) ) diff --git a/development/tests/property/property_auxiliary.py b/development/tests/property/property_auxiliary.py index a77855ea..35915b73 100644 --- a/development/tests/property/property_auxiliary.py +++ b/development/tests/property/property_auxiliary.py @@ -1,4 +1,5 @@ """This module contains some auxiliary functions for the property testing.""" + import glob import os diff --git a/development/tests/property/run.py b/development/tests/property/run.py index a983f884..f307bd0f 100755 --- a/development/tests/property/run.py +++ b/development/tests/property/run.py @@ -1,4 +1,5 @@ """The test provides the basic capabilities to run numerous property tests.""" + import os import functools diff --git a/development/tests/reliability/reliability.py b/development/tests/reliability/reliability.py index 32937d9d..45235cab 100644 --- a/development/tests/reliability/reliability.py +++ b/development/tests/reliability/reliability.py @@ -3,6 +3,7 @@ used. Additionally the module creates two different figures for the reliability section of the documentation. """ + import matplotlib.pyplot as plt import numpy as np import pandas as pd diff --git a/development/tests/replication/run.py b/development/tests/replication/run.py index 4c135eee..492f42a5 100644 --- a/development/tests/replication/run.py +++ b/development/tests/replication/run.py @@ -1,6 +1,7 @@ """This script replicates the estimation results from Cainero 2011 via the grmpy estimation method. Additionally it returns a figure of the Marginal treatment effect based on the estimation results. """ + import json import matplotlib.pyplot as plt import numpy as np diff --git a/docs/__init__.py b/docs/__init__.py index 5b1d60de..a098ebcd 100644 --- a/docs/__init__.py +++ b/docs/__init__.py @@ -1,4 +1,5 @@ """The module allows to run tests from inside the interpreter.""" + import os import pytest diff --git a/docs/source/figures/create.py b/docs/source/figures/create.py index 309c71e3..212042c6 100644 --- a/docs/source/figures/create.py +++ b/docs/source/figures/create.py @@ -1,6 +1,7 @@ """This module creates all available figures and then provides them in a compiled document for review. """ + import os import subprocess diff --git a/docs/source/figures/scripts/__init__.py b/docs/source/figures/scripts/__init__.py index fd0da36d..55759267 100644 --- a/docs/source/figures/scripts/__init__.py +++ b/docs/source/figures/scripts/__init__.py @@ -1,4 +1,5 @@ """The module allows to run tests from inside the interpreter.""" + import os import pytest diff --git a/docs/source/figures/scripts/fig-distribution-joint.py b/docs/source/figures/scripts/fig-distribution-joint.py index 164bbbce..cc297b04 100644 --- a/docs/source/figures/scripts/fig-distribution-joint.py +++ b/docs/source/figures/scripts/fig-distribution-joint.py @@ -1,4 +1,5 @@ """This module creates the contour plots for the bivariate normal distribution.""" + import numpy as np import matplotlib.pyplot as plt from scipy.stats import multivariate_normal diff --git a/docs/source/figures/scripts/fig-eh-marginal-effect.py b/docs/source/figures/scripts/fig-eh-marginal-effect.py index e169975d..8b6a209d 100644 --- a/docs/source/figures/scripts/fig-eh-marginal-effect.py +++ b/docs/source/figures/scripts/fig-eh-marginal-effect.py @@ -1,6 +1,7 @@ """The script creates a figure to illustrate the appearance of the marginal treatment effect in the abscence and presence of individual heterogeneity. """ + import numpy as np import matplotlib.pyplot as plt diff --git a/docs/source/figures/scripts/fig-local-average-treatment.py b/docs/source/figures/scripts/fig-local-average-treatment.py index e279f3fa..c96e9d35 100644 --- a/docs/source/figures/scripts/fig-local-average-treatment.py +++ b/docs/source/figures/scripts/fig-local-average-treatment.py @@ -1,5 +1,6 @@ """This module contains the code for a local average treatment graph. """ + import matplotlib.pyplot as plt from fig_config import OUTPUT_DIR, RESOURCE_DIR diff --git a/docs/source/figures/scripts/fig-reliability-par.py b/docs/source/figures/scripts/fig-reliability-par.py index ab074c41..9bbed489 100644 --- a/docs/source/figures/scripts/fig-reliability-par.py +++ b/docs/source/figures/scripts/fig-reliability-par.py @@ -1,6 +1,7 @@ """This script replicates the results of Caneiro 2011 via using a mock data set and plots the original as well as the estimated mar- ginal treatment effect""" + import json import pandas as pd diff --git a/docs/source/figures/scripts/fig-treatment-effects.py b/docs/source/figures/scripts/fig-treatment-effects.py index 3f9d024f..ec382baa 100644 --- a/docs/source/figures/scripts/fig-treatment-effects.py +++ b/docs/source/figures/scripts/fig-treatment-effects.py @@ -1,4 +1,5 @@ """""" + import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm diff --git a/docs/source/figures/scripts/fig-weights-marginal-effect.py b/docs/source/figures/scripts/fig-weights-marginal-effect.py index 6cf8cd92..9574dea1 100644 --- a/docs/source/figures/scripts/fig-weights-marginal-effect.py +++ b/docs/source/figures/scripts/fig-weights-marginal-effect.py @@ -1,6 +1,7 @@ """ This script creates a figure to illustrate how the usual treatment effects can be constructed by using differen weights on the marginal treatment effect. """ + import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm diff --git a/docs/source/figures/scripts/fig_config.py b/docs/source/figures/scripts/fig_config.py index cdf7a9a3..12c2a9d8 100644 --- a/docs/source/figures/scripts/fig_config.py +++ b/docs/source/figures/scripts/fig_config.py @@ -1,4 +1,5 @@ """This file contains paths that are used for the execution of all figure scripts.""" + import os RESOURCE_DIR = os.path.dirname(os.path.abspath(__file__)) + "/resources" diff --git a/grmpy/__init__.py b/grmpy/__init__.py index 8f50a6db..e71f231b 100644 --- a/grmpy/__init__.py +++ b/grmpy/__init__.py @@ -8,6 +8,7 @@ gp. """ + import pytest from grmpy.estimate.estimate import fit # noqa: F401 diff --git a/grmpy/estimate/estimate.py b/grmpy/estimate/estimate.py index 85d7d641..50e24eff 100644 --- a/grmpy/estimate/estimate.py +++ b/grmpy/estimate/estimate.py @@ -1,6 +1,7 @@ """The module provides an estimation process given the simulated data set and the initialization file. """ + from grmpy.check.auxiliary import read_data from grmpy.check.check import ( check_est_init_dict, diff --git a/grmpy/estimate/estimate_output.py b/grmpy/estimate/estimate_output.py index d78c6ba9..0b869cf7 100644 --- a/grmpy/estimate/estimate_output.py +++ b/grmpy/estimate/estimate_output.py @@ -1,4 +1,5 @@ """This module contains methods for producing the estimation output files.""" + import time from textwrap import wrap diff --git a/grmpy/estimate/estimate_par.py b/grmpy/estimate/estimate_par.py index 60db8a94..3bdc9475 100644 --- a/grmpy/estimate/estimate_par.py +++ b/grmpy/estimate/estimate_par.py @@ -474,10 +474,10 @@ def log_likelihood( sd1, sd0, rho1v, rho0v = x0[-4], x0[-2], x0[-3], x0[-1] nu1 = (Y1 - np.dot(beta1, X1.T)) / sd1 - lambda1 = (np.dot(gamma, Z1.T) - rho1v * nu1) / (np.sqrt(1 - rho1v ** 2)) + lambda1 = (np.dot(gamma, Z1.T) - rho1v * nu1) / (np.sqrt(1 - rho1v**2)) nu0 = (Y0 - np.dot(beta0, X0.T)) / sd0 - lambda0 = (np.dot(gamma, Z0.T) - rho0v * nu0) / (np.sqrt(1 - rho0v ** 2)) + lambda0 = (np.dot(gamma, Z0.T) - rho0v * nu0) / (np.sqrt(1 - rho0v**2)) treated = (1 / sd1) * norm.pdf(nu1) * norm.cdf(lambda1) untreated = (1 / sd0) * norm.pdf(nu0) * (1 - norm.cdf(lambda0)) @@ -916,7 +916,7 @@ def gradient(X1, X0, Z1, Z0, nu1, nu0, lambda1, lambda0, gamma, sd1, sd0, rho1v, "ij, i ->ij", X1, -(norm.pdf(lambda1) / norm.cdf(lambda1)) - * (rho1v / (np.sqrt(1 - rho1v ** 2) * sd1)) + * (rho1v / (np.sqrt(1 - rho1v**2) * sd1)) - nu1 / sd1, ), 0, @@ -929,7 +929,7 @@ def gradient(X1, X0, Z1, Z0, nu1, nu0, lambda1, lambda0, gamma, sd1, sd0, rho1v, X0, norm.pdf(lambda0) / (1 - norm.cdf(lambda0)) - * (rho0v / (np.sqrt(1 - rho0v ** 2) * sd0)) + * (rho0v / (np.sqrt(1 - rho0v**2) * sd0)) - nu0 / sd0, ), 0, @@ -939,8 +939,8 @@ def gradient(X1, X0, Z1, Z0, nu1, nu0, lambda1, lambda0, gamma, sd1, sd0, rho1v, * ( +1 / sd1 - (norm.pdf(lambda1) / norm.cdf(lambda1)) - * (rho1v * nu1 / (np.sqrt(1 - rho1v ** 2) * sd1)) - - nu1 ** 2 / sd1 + * (rho1v * nu1 / (np.sqrt(1 - rho1v**2) * sd1)) + - nu1**2 / sd1 ), keepdims=True, ) @@ -949,8 +949,8 @@ def gradient(X1, X0, Z1, Z0, nu1, nu0, lambda1, lambda0, gamma, sd1, sd0, rho1v, * ( +1 / sd0 + (norm.pdf(lambda0) / (1 - norm.cdf(lambda0))) - * (rho0v * nu0 / (np.sqrt(1 - rho0v ** 2) * sd0)) - - nu0 ** 2 / sd0 + * (rho0v * nu0 / (np.sqrt(1 - rho0v**2) * sd0)) + - nu0**2 / sd0 ), keepdims=True, ) @@ -958,7 +958,7 @@ def gradient(X1, X0, Z1, Z0, nu1, nu0, lambda1, lambda0, gamma, sd1, sd0, rho1v, ( -(norm.pdf(lambda1) / norm.cdf(lambda1)) * ((np.dot(gamma, Z1.T) * rho1v) - nu1) - / (1 - rho1v ** 2) ** (1 / 2) + / (1 - rho1v**2) ** (1 / 2) ), keepdims=True, ) @@ -967,7 +967,7 @@ def gradient(X1, X0, Z1, Z0, nu1, nu0, lambda1, lambda0, gamma, sd1, sd0, rho1v, ( (norm.pdf(lambda0) / (1 - norm.cdf(lambda0))) * ((np.dot(gamma, Z0.T) * rho0v) - nu0) - / (1 - rho0v ** 2) ** (1 / 2) + / (1 - rho0v**2) ** (1 / 2) ), keepdims=True, ) @@ -976,14 +976,13 @@ def gradient(X1, X0, Z1, Z0, nu1, nu0, lambda1, lambda0, gamma, sd1, sd0, rho1v, np.einsum( "ij, i ->ij", Z1, - (norm.pdf(lambda1) / norm.cdf(lambda1)) * 1 / np.sqrt(1 - rho1v ** 2), + (norm.pdf(lambda1) / norm.cdf(lambda1)) * 1 / np.sqrt(1 - rho1v**2), ) ) - sum( np.einsum( "ij, i ->ij", Z0, - (norm.pdf(lambda0) / (1 - norm.cdf(lambda0))) - * (1 / np.sqrt(1 - rho0v ** 2)), + (norm.pdf(lambda0) / (1 - norm.cdf(lambda0))) * (1 / np.sqrt(1 - rho0v**2)), ) ) @@ -1042,10 +1041,10 @@ def gradient_hessian(x0, X1, X0, Z1, Z0, Y1, Y0): # compute gradient for beta 1 nu1 = (Y1 - np.dot(beta1, X1.T)) / sd1 - lambda1 = (np.dot(gamma, Z1.T) - rho1v * nu1) / (np.sqrt(1 - rho1v ** 2)) + lambda1 = (np.dot(gamma, Z1.T) - rho1v * nu1) / (np.sqrt(1 - rho1v**2)) nu0 = (Y0 - np.dot(beta0, X0.T)) / sd0 - lambda0 = (np.dot(gamma, Z0.T) - rho0v * nu0) / (np.sqrt(1 - rho0v ** 2)) + lambda0 = (np.dot(gamma, Z0.T) - rho0v * nu0) / (np.sqrt(1 - rho0v**2)) grad = gradient( X1, X0, Z1, Z0, nu1, nu0, lambda1, lambda0, gamma, sd1, sd0, rho1v, rho0v @@ -1054,7 +1053,7 @@ def gradient_hessian(x0, X1, X0, Z1, Z0, Y1, Y0): multiplier = np.concatenate( ( np.ones(len(grad[:-4])), - np.array([1 / sd1, 1 / (1 - rho1v ** 2), 1 / sd0, 1 / (1 - rho0v ** 2)]), + np.array([1 / sd1, 1 / (1 - rho1v**2), 1 / sd0, 1 / (1 - rho0v**2)]), ) ) diff --git a/grmpy/estimate/estimate_semipar.py b/grmpy/estimate/estimate_semipar.py index f102f493..6350f3e4 100644 --- a/grmpy/estimate/estimate_semipar.py +++ b/grmpy/estimate/estimate_semipar.py @@ -1,6 +1,7 @@ """ This module contains the semiparametric estimation process. """ + import kernreg as kr import matplotlib.pyplot as plt import numpy as np diff --git a/grmpy/grmpy_config.py b/grmpy/grmpy_config.py index 37b8e8b0..9943591d 100644 --- a/grmpy/grmpy_config.py +++ b/grmpy/grmpy_config.py @@ -1,4 +1,5 @@ """This module provides some configuration for the package.""" + import os import sys import warnings diff --git a/grmpy/plot/plot_auxiliary.py b/grmpy/plot/plot_auxiliary.py index 247608e3..b4e2c4bf 100644 --- a/grmpy/plot/plot_auxiliary.py +++ b/grmpy/plot/plot_auxiliary.py @@ -1,6 +1,7 @@ """ This module provides auxiliary functions for the plot_mte function. """ + import matplotlib.pyplot as plt import numpy as np import pandas as pd diff --git a/grmpy/read/read.py b/grmpy/read/read.py index e8182a92..c1ced6ec 100644 --- a/grmpy/read/read.py +++ b/grmpy/read/read.py @@ -1,4 +1,5 @@ """The module contains the main function of the init file import process.""" + import numpy as np import yaml diff --git a/grmpy/read/read_auxiliary.py b/grmpy/read/read_auxiliary.py index f7389511..68a84b44 100644 --- a/grmpy/read/read_auxiliary.py +++ b/grmpy/read/read_auxiliary.py @@ -1,4 +1,5 @@ """This module provides auxiliary functions for the import process of the init file.""" + import numpy as np diff --git a/grmpy/simulate/simulate.py b/grmpy/simulate/simulate.py index 704601a9..73c6e21a 100644 --- a/grmpy/simulate/simulate.py +++ b/grmpy/simulate/simulate.py @@ -1,4 +1,5 @@ """The module provides the simulation process.""" + import numpy as np from grmpy.check.check import check_sim_init_dict diff --git a/grmpy/simulate/simulate_auxiliary.py b/grmpy/simulate/simulate_auxiliary.py index 196b190c..08f0a488 100644 --- a/grmpy/simulate/simulate_auxiliary.py +++ b/grmpy/simulate/simulate_auxiliary.py @@ -2,6 +2,7 @@ simulation processes of the unobservable and endogenous variables of the model as well as functions regarding the info file output. """ + import numpy as np import pandas as pd from scipy.stats import norm diff --git a/grmpy/test/auxiliary.py b/grmpy/test/auxiliary.py index ae2c6c5b..9d08a8b6 100644 --- a/grmpy/test/auxiliary.py +++ b/grmpy/test/auxiliary.py @@ -1,4 +1,5 @@ """The module provides basic auxiliary functions for the test modules.""" + import glob import os import shlex @@ -70,16 +71,16 @@ def read_desc(fname): if list_[0] == "Observed": dict_["TREATED"][list_[0] + " " + list_[1]] = list_[2:] else: - dict_["TREATED"][ - list_[0] + " " + list_[1] + " " + list_[2] - ] = list_[3:] + dict_["TREATED"][list_[0] + " " + list_[1] + " " + list_[2]] = ( + list_[3:] + ) elif 38 <= i < 41: if list_[0] == "Observed": dict_["UNTREATED"][list_[0] + " " + list_[1]] = list_[2:] else: - dict_["UNTREATED"][ - list_[0] + " " + list_[1] + " " + list_[2] - ] = list_[3:] + dict_["UNTREATED"][list_[0] + " " + list_[1] + " " + list_[2]] = ( + list_[3:] + ) # Process the string in int and float values for key_ in dict_.keys(): diff --git a/grmpy/test/conftest.py b/grmpy/test/conftest.py index 9201f2cb..29a995ca 100644 --- a/grmpy/test/conftest.py +++ b/grmpy/test/conftest.py @@ -1,4 +1,5 @@ """This module provides the fixtures for the PYTEST runs.""" + import os import numpy as np diff --git a/grmpy/test/random_init.py b/grmpy/test/random_init.py index 5f34e313..8532e767 100644 --- a/grmpy/test/random_init.py +++ b/grmpy/test/random_init.py @@ -1,4 +1,5 @@ """The module provides a random dictionary generating process for test purposes.""" + import collections import uuid from itertools import combinations diff --git a/grmpy/test/resources/tutorial.py b/grmpy/test/resources/tutorial.py index fc2d0514..7145540e 100644 --- a/grmpy/test/resources/tutorial.py +++ b/grmpy/test/resources/tutorial.py @@ -1,6 +1,7 @@ """This module contains a tutorial illustrating the basic capabilities of the grmpy package. """ + import os from grmpy.estimate.estimate import fit diff --git a/grmpy/test/test_integration_semipar.py b/grmpy/test/test_integration_semipar.py index a957ba1e..1a8c8efd 100644 --- a/grmpy/test/test_integration_semipar.py +++ b/grmpy/test/test_integration_semipar.py @@ -1,4 +1,5 @@ """This file contains integration tests for the semiparametric estimation routine.""" + import numpy as np import pandas as pd import pickle diff --git a/grmpy/test/test_quality.py b/grmpy/test/test_quality.py index 361f320b..603db105 100644 --- a/grmpy/test/test_quality.py +++ b/grmpy/test/test_quality.py @@ -1,4 +1,5 @@ """This module contains test that check the code quality of the package.""" + import os import subprocess from subprocess import CalledProcessError diff --git a/grmpy/test/test_unit.py b/grmpy/test/test_unit.py index 39964ef0..0f9fb9e3 100644 --- a/grmpy/test/test_unit.py +++ b/grmpy/test/test_unit.py @@ -1,4 +1,5 @@ """The module provides unit tests for different aspects of the simulation process.""" + import numpy as np import pandas as pd import pytest diff --git a/grmpy/test/test_unit_semipar.py b/grmpy/test/test_unit_semipar.py index b3054330..2ac18e21 100644 --- a/grmpy/test/test_unit_semipar.py +++ b/grmpy/test/test_unit_semipar.py @@ -1,4 +1,5 @@ """This file contains unit tests for the semiparametric estimation routine.""" + import numpy as np import pandas as pd import pytest diff --git a/promotion/grmpy_tutorial_notebook/tutorial_semipar_auxiliary.py b/promotion/grmpy_tutorial_notebook/tutorial_semipar_auxiliary.py index 0445ded5..d10d4e8e 100644 --- a/promotion/grmpy_tutorial_notebook/tutorial_semipar_auxiliary.py +++ b/promotion/grmpy_tutorial_notebook/tutorial_semipar_auxiliary.py @@ -1,6 +1,7 @@ """ This module provides auxiliary functions for the semiparametric tutorial. """ + import matplotlib.patches as mpatches import matplotlib.pyplot as plt import numpy as np