Skip to content

Commit

Permalink
pep8 style adjustments , implemented deterministic case into simulati…
Browse files Browse the repository at this point in the history
…on function and read process and changed all assert statements in the test directory such that they work now as they should do
  • Loading branch information
SeBecker committed Aug 21, 2017
1 parent 9b7a188 commit 60b6339
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 301 deletions.
8 changes: 4 additions & 4 deletions development/working/run.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
""" This module allows to manually explore the capabilities of the grmpy package.
"""
import sys
import os
sys.path.insert(0, "../../")

from grmpy.simulation.simulation import simulate
from grmpy.read.read import read
from grmpy.test.random_init import generate_random_dict
from grmpy.read.print_init import print_dict
from grmpy.test.random_init import print_dict

sys.path.insert(0, "../../")

dict_ = generate_random_dict()
print_dict(dict_)
dict_ = read('test.grmpy.ini')
Expand Down
3 changes: 0 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@
author, 'grmpy', 'One line description of project.',
'Miscellaneous'),
]



# -- Options for Epub output ----------------------------------------------

# Bibliographic Dublin Core info.
Expand Down
10 changes: 5 additions & 5 deletions grmpy/read/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import shlex

from grmpy.read.read_auxiliary import _auxiliary
from grmpy.read.read_auxiliary import _process
from grmpy.read.read_auxiliary import auxiliary
from grmpy.read.read_auxiliary import process


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

Expand All @@ -28,9 +28,9 @@ def read(file_):
dict_[keyword] = {}
continue

_process(list_, dict_, keyword)
process(list_, dict_, keyword)

dict_ = _auxiliary(dict_)
dict_ = auxiliary(dict_)

return dict_

37 changes: 9 additions & 28 deletions grmpy/read/read_auxiliary.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import numpy as np

def _process(list_, dict_, keyword):
'''processes keyword parameters'''
name, val = list_[0], list_[1]

if name not in dict_[keyword].keys():
if name in ['coeff']:
dict_[keyword][name] = []

def process(list_, dict_, keyword):
"""processes keyword parameters"""
name, val = list_[0], list_[1]

if name not in dict_[keyword].keys() and name in ['coeff']:
dict_[keyword][name] = []
# Type conversion
if name in ['agents', 'seed']:
val = int(val)
Expand All @@ -26,31 +24,23 @@ def _process(list_, dict_, keyword):
return dict_


def _auxiliary(dict_):
def auxiliary(dict_):
"""
"""
dict_['AUX'] = {}
if 'coeff' not in dict_['TREATED'].keys():
if dict_['DIST']['coeff'] == [0.0] * len(dict_['DIST']['coeff']):
is_deterministic = True
else:
is_deterministic = False


for key_ in ['UNTREATED', 'TREATED', 'COST', 'DIST']:
if key_ in ['UNTREATED', 'TREATED', 'COST']:
if not is_deterministic:
dict_[key_]['all'] = dict_[key_]['coeff']
dict_[key_]['all'] = np.array(dict_[key_]['all'])
else:
dict_[key_]['all'] = np.array([])
else:
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
Expand All @@ -63,8 +53,7 @@ def _auxiliary(dict_):
# Number of parameters
dict_['AUX']['num_paras'] = 2 * num_covars_out + num_covars_cost + 2 + 2


#Starting values
# Starting values
dict_['AUX']['init_values'] = []

for key_ in ['TREATED', 'UNTREATED', 'COST', 'DIST']:
Expand All @@ -75,14 +64,6 @@ def _auxiliary(dict_):
pass
else:
del dict_[key_][j]
dict_['DETERMINISTIC']= is_deterministic
dict_['DETERMINISTIC'] = is_deterministic

return dict_








27 changes: 14 additions & 13 deletions grmpy/simulation/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
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.read.read import read


def simulate(init_dict):
def simulate(init_file):
""" This function simulated a user-specified version of the generalized Roy model
"""

# Transform init file to dictionary

init_dict = read(init_file)
# Distribute information
is_deterministic = init_dict['DETERMINISTIC']
num_agents = init_dict['SIMULATION']['agents']
Expand All @@ -29,18 +34,14 @@ def simulate(init_dict):
num_covars_cost = C_coeffs.shape[0]

# Simulate observables
if not is_deterministic:
means = np.tile(0.0, num_covars_out)
covs = np.identity(num_covars_out)
X = np.random.multivariate_normal(means, covs, num_agents)

means = np.tile(0.0, num_covars_cost)
covs = np.identity(num_covars_cost)
Z = np.random.multivariate_normal(means, covs, num_agents)
Z[:, 0], X[:, 0] = 1.0, 1.0
else:
X = np.array([])
Z = np.array([])
means = np.tile(.0, num_covars_out)
covs = np.identity(num_covars_out)
X = np.random.multivariate_normal(means, covs, num_agents)

means = np.tile(.0, num_covars_cost)
covs = np.identity(num_covars_cost)
Z = np.random.multivariate_normal(means, covs, num_agents)
Z[:, 0], X[:, 0] = 1.0, 1.0

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

0 comments on commit 60b6339

Please sign in to comment.