示例#1
0
#!/usr/bin/env python
''' Template that shows an example on how to use the grmEstimatorToolbox.
'''

# standard library
import os
import sys

# edit pythonpath
dir_ = os.path.realpath(__file__).replace('/example/template.py', '')
sys.path.insert(0, dir_)

# project library
import grmToolbox
''' Simulation.
'''
grmToolbox.simulate()
''' Estimation.
'''
grmToolbox.estimate()
# standard library
import os
import sys
# project library
import grmToolbox
import grmReader
from mpi4py import MPI
import numpy

''' Simulation.
'''
grmToolbox.simulate()

''' Estimation.
'''
rslt=grmToolbox.estimate()
Y1_beta    = (rslt['Y1_beta'])
Y0_beta    = (rslt['Y0_beta'])   
U1_var     = rslt['U1_var'] 
U0_var     = rslt['U0_var']

# Get the X's from the data
# Checks.
assert (os.path.exists('grmInit.ini'))     
# Process initialization file.
initDict = grmReader.read()
data = numpy.genfromtxt(initDict['fileName'], dtype = 'float')
trash   = numpy.array(initDict['Y1_beta'])
numCovarsOut  = trash.shape[0]  
X = data[:,2:(numCovarsOut + 2)]
D = data[:,1]
from mpi4py import MPI

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
#size= number of processors
size = comm.Get_size() 


''' Simulation.
'''
grmToolbox.simulate()

''' Estimation.
'''
grmToolbox.estimate()


def Treatment_simulation():
    ''' Retrieve Estimated parameters from grmRslt.json
    '''
    # Checks.
    assert (os.path.exists('grmRslt.json')) 
    
    ParamEst = json.load(open('grmRslt.json')) 
    
    
    numAgents  = ParamEst['numAgents']
    fileName   = ParamEst['fileName']
    
    Y1_beta    = np.array(ParamEst['Y1_beta'])
示例#4
0
''' Template that shows an example on how to use the grmEstimatorToolbox.
'''

# standard library
import os
import sys

# edit pythonpath
dir_ = os.path.realpath(__file__).replace('/example/template.py','')
sys.path.insert(0, dir_)

# project library
import grmToolbox

#
# Simulation.
#
grmToolbox.simulate()

#
# Estimation.
#
rslt = grmToolbox.estimate(outputfile = 'grmRslt.json')

#
# Calculating Treatment Effects
#
treat = grmToolbox.calcSimTreatEffects(20, outputfile = 'grmTreatEffects.json')

print rslt
print treat