Skip to content

Commit

Permalink
Adjusted estimation process, reorganized promotion section and the tr…
Browse files Browse the repository at this point in the history
…avis test setup
  • Loading branch information
SeBecker committed Jun 23, 2019
1 parent 1559bfd commit 8d730e4
Show file tree
Hide file tree
Showing 123 changed files with 3,713 additions and 3,067 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
__pxcache__/
*.pyc
.idea/
docs/_build
docs/build
promotion/

20 changes: 11 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
rev: 19.3b0
hooks:
- id: black
language_version: python3.6
exclude: ^docs/
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- id: flake8
- repo: https://github.com/timothycrosley/isort
rev: v4.3.20
hooks:
- repo: https://github.com/timothycrosley/isort
rev: 4.3.20
hooks:
- id: isort
- name: isort
- entry: isort
- require_serial: true
- language: python
- types: [python]
name: isort
exclude: ^docs/
entry: isort
require_serial: true
language: python
types: [python]

21 changes: 17 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
language: python

python:
- "3.6"

install:
- pip install -r requirements.txt
- pip install pytest-cov
- pip install codecov
- sudo apt-get update
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- PATH="$HOME/miniconda/bin:$PATH"
- conda env create -f environment.yml
- source activate grmpy

before_script:
- export PYTHONPATH=$PYTHONPATH:$(pwd)

script:
- py.test --cov=grmpy
- py.test
- bash utils/run_sphinx_build.sh
- travis_wait python utils/travis_runner.py
- python -c "import grmpy; grmpy.test()"

after_success:
- codecov

notifications:
email: false
50 changes: 27 additions & 23 deletions development/tests/regression/draft.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
"""The test provides a regression test battery. In the first step it loops over 100 different seeds,
generates a random init file for each seed, simulates the resulting dataframe, sums it up and saves
the sum and the generated dictionary in /grmpy/test/resources/ as a json file. In the second step it
reads the json file, and loops over all entries. For each element it prints an init file, simulates
the dataframe, sums it up again and compares the sum from the first step with the one from the
second step.
"""The test provides a regression test battery. In the first step it loops over 100
different seeds, generates a random init file for each seed, simulates the resulting
dataframe, sums it up and saves the sum and the generated dictionary in
/grmpy/test/resources/ as a json file. In the second step it reads the json file, and
loops over all entries. For each element it prints an init file, simulates the dataframe,
sums it up again and compares the sum from the first step with the one from the second
step.
"""

import json
import os

import numpy as np

from grmpy.estimate.estimate_auxiliary import calculate_criteria
from grmpy.estimate.estimate_auxiliary import start_values
from grmpy.test.random_init import generate_random_dict
from grmpy.test.random_init import print_dict
from grmpy.estimate.estimate_auxiliary import (
calculate_criteria,
process_data,
start_values,
)
from grmpy.read.read import read
from grmpy.simulate.simulate import simulate
from grmpy.test.auxiliary import cleanup
from grmpy.read.read import read
from grmpy.test.random_init import generate_random_dict, print_dict

NUM_TESTS = 100

np.random.seed(1234235)
seeds = np.random.randint(0, 1000, size=NUM_TESTS)
directory = os.path.dirname(__file__)
file_dir = os.path.join(directory, 'old_regression_vault.grmpy.json')
file_dir = os.path.join(directory, "old_regression_vault.grmpy.json")

if True:
tests = []
for seed in seeds:
np.random.seed(seed)
constr = dict()
constr['DETERMINISTIC'], constr['CATEGORICAL'] = False, False
constr["DETERMINISTIC"], constr["CATEGORICAL"] = False, False
dict_ = generate_random_dict(constr)
df = simulate('test.grmpy.ini')
df = simulate("test.grmpy.yml")
stat = np.sum(df.sum())
init_dict = read('test.grmpy.ini')
start = start_values(init_dict, df, 'init')
criteria = calculate_criteria(init_dict, df, start)
init_dict = read("test.grmpy.yml")
start = start_values(init_dict, df, "init")
_, X1, X0, Z1, Z0, Y1, Y0 = process_data(df, init_dict)
criteria = calculate_criteria(init_dict, X1, X0, Z1, Z0, Y1, Y0, start)
tests += [(stat, dict_, criteria)]
json.dump(tests, open(file_dir, 'w'))
json.dump(tests, open(file_dir, "w"))

if True:
tests = json.load(open(file_dir, 'r'))
tests = json.load(open(file_dir, "r"))

for test in tests:
stat, dict_, criteria = test
print_dict(dict_)
init_dict = read('test.grmpy.yml')
df = simulate('test.grmpy.yml')
start = start_values(init_dict, df, 'init')
init_dict = read("test.grmpy.yml")
df = simulate("test.grmpy.yml")
start = start_values(init_dict, df, "init")
criteria_ = calculate_criteria(init_dict, df, start)
np.testing.assert_array_almost_equal(criteria, criteria_)
np.testing.assert_almost_equal(np.sum(df.sum()), stat)

cleanup('regression')
cleanup("regression")
124 changes: 90 additions & 34 deletions development/tests/regression/run.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
#!/usr/bin/env python
"""The test provides the basic capabilities to work with the regression tests of the package."""
"""The test provides the basic capabilities to work with the regression tests of the
package.
"""
import argparse
import json
import os

import numpy as np
import grmpy

from grmpy.test.random_init import generate_random_dict
from grmpy.test.random_init import print_dict
import grmpy
from grmpy.estimate.estimate_auxiliary import (
calculate_criteria,
process_data,
start_values,
)
from grmpy.read.read import read
from grmpy.simulate.simulate import simulate
from grmpy.test.auxiliary import cleanup
from grmpy.test.auxiliary import cleanup, dict_transformation
from grmpy.test.random_init import generate_random_dict, print_dict


def process_arguments(parser):
"""This function parses the input arguments."""
args = parser.parse_args()

# Distribute input arguments
request = args.request
if "num_tests" in args:
num_tests = int(args.num_tests)
else:
num_tests = None

# Test validity of input arguments
assert request in ['check', 'create']

return request
if request not in ["check", "create"]:
raise AssertionError()
if num_tests not in [i for i in np.arange(1001)]:
raise AssertionError(9)
return request, num_tests


def create_vault(num_tests=100, seed=123):
Expand All @@ -33,39 +45,83 @@ def create_vault(num_tests=100, seed=123):
tests = []
for _ in range(num_tests):
dict_ = generate_random_dict()
df = simulate('test.grmpy.ini')
init_dict = read("test.grmpy.yml")
df = simulate("test.grmpy.yml")
_, X1, X0, Z1, Z0, Y1, Y0 = process_data(df, init_dict)
x0 = start_values(init_dict, df, "init")
criteria = calculate_criteria(init_dict, X1, X0, Z1, Z0, Y1, Y0, x0)
stat = np.sum(df.sum())
tests += [(stat, dict_)]
tests += [(stat, dict_, criteria)]
cleanup()

json.dump(tests, open('old_regression_vault.grmpy.json', 'w'))
json.dump(tests, open("regression_vault.grmpy.json", "w"))


def check_vault():
"""This function checks the complete regression vault that is distributed as part of the
package.
def check_vault(num_tests=100):
"""This function checks the complete regression vault that is distributed as part of
the package.
"""
fname = os.path.dirname(grmpy.__file__) + '/test/resources/old_regression_vault.grmpy.json'
fname = (
os.path.dirname(grmpy.__file__)
+ "/test/resources/old_regression_vault.grmpy.json"
)
tests = json.load(open(fname))

if num_tests > len(tests):
print(
"The specified number of evaluations is larger than the number"
" of entries in the regression_test vault.\n"
"Therefore the test runs the complete test battery."
)
else:
tests = [tests[i] for i in np.random.choice(len(tests), num_tests)]

for test in tests:
stat, dict_, criteria = test
print_dict(dict_)
df = simulate('test.grmpy.ini')
print_dict(dict_transformation(dict_))
init_dict = read("test.grmpy.yml")
df = simulate("test.grmpy.yml")
_, X1, X0, Z1, Z0, Y1, Y0 = process_data(df, init_dict)
x0 = start_values(init_dict, df, "init")
criteria_ = calculate_criteria(init_dict, X1, X0, Z1, Z0, Y1, Y0, x0)
np.testing.assert_almost_equal(criteria_, criteria)
np.testing.assert_almost_equal(np.sum(df.sum()), stat)
cleanup('regression')


if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Work with regression tests for package.')

parser.add_argument('--request', action='store', dest='request', required=True,
choices=['check', 'create'], help='request')

request = process_arguments(parser)

if request == 'check':
check_vault()
elif request == 'create':
create_vault()
cleanup("regression")


if __name__ == "__main__":

parser = argparse.ArgumentParser(
description="Work with regression tests for package."
)

parser.add_argument(
"--request",
action="store",
dest="request",
required=True,
choices=["check", "create"],
help="request",
)

parser.add_argument(
"--num_tests",
action="store",
dest="num_tests",
required=False,
choices=[str(i) for i in np.arange(1001)],
help="num_tests",
)

request, num_tests = process_arguments(parser)

if request == "check":
if num_tests is None:
check_vault()
else:
check_vault(num_tests)
elif request == "create":
if num_tests is None:
create_vault()
else:
create_vault(num_tests)
2 changes: 2 additions & 0 deletions development/tests/replication/replication.grmpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ESTIMATION:
indicator: state
comparison: 0
output_file: est.grmpy.info
print_output: est.grmpy.info

TREATED:
params:
- 1.0
Expand Down
Loading

0 comments on commit 8d730e4

Please sign in to comment.