Skip to content

Commit

Permalink
Changed info file output, added setup, conftest, auxiliary test modul…
Browse files Browse the repository at this point in the history
…e, changed unit tests ...
  • Loading branch information
SeBecker committed Aug 26, 2017
1 parent f0e6cee commit 03267eb
Show file tree
Hide file tree
Showing 20 changed files with 1,038 additions and 563 deletions.
2 changes: 1 addition & 1 deletion .idea/grmpy.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

416 changes: 360 additions & 56 deletions .idea/workspace.xml

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions docs/credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ Development Lead
Contributors
^^^^^^^^^^^^

`Sebastian Becker <https://github.com/sebecker>`_
`Tobias Raabe <https://github.com/tobiasraabe>`_, `Sebastian Becker <https://github.com/sebecker>`_

Acknowledgments
^^^^^^^^^^^^^^^

We appreciate the financial support of the `AXA Research Fund <https://www.axa-research.org/>`_ and the `University of Bonn <https://www.uni-bonn.de>`_. We are indebted to the open source community as we build on top of numerous open source tools such as the `SciPy Stack <https://www.scipy.org>`_ and `statsmodels <http://statsmodels.sourceforge.net/>`.
We appreciate the financial support of the `AXA Research Fund <https://www.axa-research.org/>`_ and the `University of Bonn <https://www.uni-bonn.de>`_. We are indebted to the open source community as we build on top of numerous open source tools such as the `SciPy Stack <https://www.scipy.org>`_ and
`statsmodels <http://statsmodels.sourceforge.net/>`_.
68 changes: 67 additions & 1 deletion docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,70 @@ Parametric Assumptions
Model Specification
-------------------

The model is specified in an initialization file.
The model is specified in an initialization file. The specific file includes the following sections:


**SIMULATION**

The *SIMULATION* part contains basic configurations that determine the simulation and output process.

======= ====== ==================
Key Value Interpretation
======= ====== ==================
agents int number of individuals
seed int seed for the specific simulation
source str name for output files
======= ====== ==================

**TREATED & UNTREATED**

The *TREATED* and *UNTREATED* paragraph are similar regarding their structure. Both contain the parameters that determine the expected wage dependent on the treatment status. There can be added as many covariates as wished, but the number has to be the same for both cases.

*Note:* The first coefficient is interpreted as an intercept.

======= ====== ==================
Key Value Interpretation
======= ====== ==================
coeff float intercept coefficient
coeff float coefficient of the first covariate
coeff float coefficient of the second covariate
...
======= ====== ==================

**COST**

*COST* includes parameters related to the cost function.

*Note:* The first coefficient is interpreted as an intercept.

======= ====== ==================
Key Value Interpretation
======= ====== ==================
coeff float intercept coefficient
coeff float coefficient of the first covariate
coeff float coefficient of the second covariate
...
======= ====== ==================

**DIST**

The *DIST* Section determines distributional characteristics regarding the unobservables.

*Note:* The coefficients

======= ====== ==================
Key Value Interpretation
======= ====== ==================
coeff float :math:`\sigma_{1}`
coeff float :math:`\sigma_{12}`
coeff float :math:`\sigma_{13}`
coeff float :math:`\sigma_{2}`
coeff float :math:`\sigma_{23}`
coeff float :math:`\sigma_{3}`
======= ====== ==================






24 changes: 24 additions & 0 deletions grmpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""The module allows to run tests from inside the interpreter
"""
import os

try:
import pytest
except ImportError:
pass

__version__ = '1.0.0'


def test():
""" Run PYTEST for the package.
"""

package_directory = os.path.dirname(os.path.realpath(__file__))
current_directory = os.getcwd()

os.chdir(package_directory)

pytest.main()

os.chdir(current_directory)
6 changes: 4 additions & 2 deletions grmpy/read/read.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

"""The module contains the main function of the init file import process
"""

import shlex

Expand All @@ -7,7 +8,8 @@


def read(file_):
"""reads the initialization file and provides an dictionary with parameters for the simulation"""
"""The function reads the initialization file and returns a dictionary with parameters for the simulation
"""
dict_ = {}
for line in open(file_).readlines():

Expand Down
10 changes: 6 additions & 4 deletions grmpy/read/read_auxiliary.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""This module provides auxiliary functions for the import process of the init file.
"""

import numpy as np


def process(list_, dict_, keyword):
"""processes keyword parameters"""
"""The function processes keyword parameters and creates dictionary elements."""
name, val = list_[0], list_[1]

if name not in dict_[keyword].keys() and name in ['coeff']:
Expand All @@ -25,7 +28,8 @@ def process(list_, dict_, keyword):


def auxiliary(dict_):
"""
"""The function creates an new dictionary entry 'AUX' that includes starting values of
each parameter and the number of covariates.
"""
dict_['AUX'] = {}
if dict_['DIST']['coeff'] == [0.0] * len(dict_['DIST']['coeff']):
Expand All @@ -41,8 +45,6 @@ def auxiliary(dict_):
dict_[key_]['all'] = dict_[key_]['coeff']
dict_[key_]['all'] = np.array(dict_[key_]['all'])

# Create keys that contain all standard deviation and covariance parameters

# Number of covariates
num_covars_out = len(dict_['TREATED']['all'])
num_covars_cost = len(dict_['COST']['all'])
Expand Down
11 changes: 11 additions & 0 deletions grmpy/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from setuptools import setup

setup(name='grmpy',
version='0.1',
description='grmpy is a package for simulation and analysis of economic aspects of the generalized roy model',
url='https://github.com/grmToolbox/grmpy',
author='Phillip Eisenhauer',
author_email='eisenhauer@policy-lab.org',
license='MIT',
packages=['numpy', 'scipy', 'pytest', 'pandas', 'statsmodels'],
zip_safe=False)
File renamed without changes.
23 changes: 13 additions & 10 deletions grmpy/simulation/simulation.py → grmpy/simulate/simulate.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""The module provides the simulation process.
"""
import numpy as np
import os.path

from grmpy.simulation.simulation_auxiliary import simulate_unobservables
from grmpy.simulation.simulation_auxiliary import simulate_outcomes
from grmpy.simulation.simulation_auxiliary import write_output
from grmpy.simulation.simulation_auxiliary import print_info
from grmpy.simulate.simulate_auxiliary import simulate_unobservables
from grmpy.simulate.simulate_auxiliary import simulate_outcomes
from grmpy.simulate.simulate_auxiliary import write_output
from grmpy.simulate.simulate_auxiliary import print_info
from grmpy.read.read import read


Expand All @@ -12,8 +15,10 @@ def simulate(init_file):
"""

# Transform init file to dictionary

assert isinstance(init_file, str)
assert os.path.isfile(init_file)
init_dict = read(init_file)

# Distribute information
is_deterministic = init_dict['DETERMINISTIC']
num_agents = init_dict['SIMULATION']['agents']
Expand Down Expand Up @@ -44,17 +49,15 @@ def simulate(init_file):
Z[:, 0], X[:, 0] = 1.0, 1.0

# Simulate unobservables
# Read information about the distribution and the specific means from the init dic

U, V = simulate_unobservables(covar_, vars_, num_agents)

# Simulate endogeneous variables

Y, D, Y_1, Y_0 = simulate_outcomes([X, Z], U, coeffs)

# Write output file
df = write_output([Y, D, Y_1, Y_0], [X, Z], [U, V], source, is_deterministic)
df = write_output([Y, D, Y_1, Y_0], [X, Z], [U, V],
source, is_deterministic)

print_info(df, [Y0_coeffs, Y1_coeffs, C_coeffs, Dist_coeffs], source)

return df, Y, Y_1, Y_0, D, X, Z, U, V
return df

0 comments on commit 03267eb

Please sign in to comment.