Ejemplo n.º 1
0
def main():
    if '@' in ARGS.filename:
        tokens = ARGS.filename.split('@')
        assert len(tokens) == 2, 'wrong format of shared file'
        filenames = createShardFilenames(tokens[0], int(tokens[1]))
    else:
        filenames = [ARGS.filename]

    mData = [loadTrace(filename, ('reward')) for filename in filenames if
             os.path.isfile(filename)]
    windowStats = multipleRunRollingMean(mData, 'reward', ARGS.windowSize,
                                         ARGS.plotInterval)
    ptNumber = len(windowStats['mean'])

    runNumber = len(filenames)
    rewardMean = windowStats['mean']
    rewardStd= windowStats['std']
    sampleNumber = runNumber * ARGS.windowSize
    rewardSem = rewardStd / (P.sqrt(sampleNumber))
    confidenceLevel = 0.95
    yerr = ss.t.ppf((confidenceLevel + 1) / 2.0, sampleNumber-1) * rewardSem
    plotWithCI(range(ptNumber), rewardMean, yerr)
    if ARGS.exportFigPath is None:
        ARGS.exportFigPath = os.path.dirname(ARGS.filename) + '/fig.json'

    import json
    data = {
        'x': range(ptNumber),
        'y': rewardMean,
    }
    json.dump(data, open(ARGS.exportFigPath, 'w'))

#  P.errorbar(range(ptNumber), rewardMean, yerr=yerr, fmt='--o', ecolor='g',
#             capthick=2)
    if ARGS.showFig:
        P.show()
Ejemplo n.º 2
0
parser.add_argument('script_filename',
                    help='path of the script that will be run')
parser.add_argument('output_filename',
                    help='output sharded filename. It has format of prefix@N, '
                         'where N is the # of runs')

args = parser.parse_args()

def myExecute(filename):
    startTime = datetime.datetime.now()
    check_call('./blaze run %s > %s' % (args.script_filename, filename),
               shell=True)
    endTime = datetime.datetime.now()
    timeDelta = endTime - startTime
    fmt = "%Y-%m-%d %H:%M:%S"
    message = ("start time: %s \n"
              "end time: %s \n"
              "elapsed time: %i seconds\n") % (startTime.strftime(fmt),
                                              endTime.strftime(fmt),
                                              timeDelta.total_seconds())
    check_call('echo "%s" > %s.done' % (message, filename), shell=True)

tokens = args.output_filename.split('@')
assert len(tokens) == 2, 'wrong format of output file'
outputPrefix = tokens[0]
shardNumber = int(tokens[1])

p = multiprocessing.Pool()
outputFilenames = createShardFilenames(outputPrefix, shardNumber)
p.map(myExecute, outputFilenames)