Пример #1
0
        logging.debug("Results already computed: " + str(resultsFileName))

N, resultsDir, outputDir, recordStep, startDate, endDate, prefix, targetGraph, breakSize, numEpsilons, M, matchAlpha, matchAlg, numInds = loadParams(0)

if saveResults:
    for ind in range(numInds):
        logging.debug("Record step: " + str(recordStep))
        logging.debug("Start date: " + str(startDate))
        logging.debug("End date: " + str(endDate))
        logging.debug("End date - start date: " + str(endDate - startDate))
        
        N, resultsDir, outputDir, recordStep, startDate, endDate, prefix, targetGraph, breakSize, numEpsilons, M, matchAlpha, matchAlg, numInds = loadParams(ind)        
        
        t = 0
        for i in range(numEpsilons): 
            thetaArray, objArray = loadThetaArray(N, resultsDir, i)
            if thetaArray.shape[0] == N: 
                t = i   
            
        logging.debug("Using population " + str(t))        
        
        try: 
            os.mkdir(outputDir)
        except: 
            logging.debug("Directory exists: " + outputDir)     
        
        thetaArray = loadThetaArray(N, resultsDir, t)[0]
        logging.debug(thetaArray)
        
        paramList = []
        
Пример #2
0
        return results 
        
    thetaDir = resultsDir + "thetaSA" + str(i) + "/"
    
    if not os.path.exists(thetaDir): 
        os.mkdir(thetaDir)
    
    paramList = numpy.arange(10) 
    pool = multiprocessing.Pool(processes=numProcesses)               
    resultsIterator = pool.map(optimise, paramList)     
    #resultsIterator = map(runModel, paramList)     

    for result in resultsIterator: 
        theta = result[0]
        objective = result[1]
        logging.debug("Accepting theta=" + str(result[0]))
        logging.debug("Objective=" + str(result[1]))
        logging.debug("Number of iterations: " + str(result[4]))        
        
        currentTheta = loadThetaArray(N, thetaDir, 0)[0].tolist()
        fileName = thetaDir + "theta_" + str(len(currentTheta)) + ".npz" 
        try:
           with open(fileName, "w") as fileObj:
               numpy.savez(fileObj, theta, numpy.array(objective))
        except IOError:
           logging.debug("File IOError (probably a collision) occured with " + fileName)
    
    pool.terminate()

logging.debug("All done!")