Пример #1
0
def runTrain(masterDict, *, screen="test", cudaID):
    if type(masterDict) is str:
        mFile = masterDict
        masterDict = master.readMasterFile(mFile)
    else:
        mFile = master.writeMasterFile(masterDict)

    codePath = os.path.realpath(__file__)
    if screen is None:
        cmd = "CUDA_VISIBLE_DEVICES={} python {} -F {} -M {}".format(
            cudaID, codePath, "train", mFile)
    else:
        cmd = "CUDA_VISIBLE_DEVICES={} screen -dmS {} python {} -F {} -M {}".format(
            cudaID, screen, codePath, "train", mFile)

    # if screen is None:
    #     #add some debugs Dapeng
    #     parser = argparse.ArgumentParser()
    #     parser.add_argument('-F', dest='func', type=str, default='train')
    #     parser.add_argument('-M', dest='mFile', type=str, default=mFile)
    #     args = parser.parse_args()
    #     if args.func == 'train':
    #         mDict = master.readMasterFile(args.mFile)
    #         master.train(mDict)
    #         # out = mDict['out']
    #         # email.sendEmail(subject='Training Done', text=out)

    print(cmd)
    os.system(cmd)
Пример #2
0
def runTrain(masterDict, *, screen='test', cudaID):
    if type(masterDict) is str:
        mFile = masterDict
        masterDict = master.readMasterFile(mFile)
    else:
        mFile = master.writeMasterFile(masterDict)

    codePath = os.path.realpath(__file__)
    if screen is None:
        cmd = 'CUDA_VISIBLE_DEVICES={} python {} -F {} -M {}'.format(
            cudaID, codePath, 'train', mFile)
    else:
        cmd = 'CUDA_VISIBLE_DEVICES={} screen -dmS {} python {} -F {} -M {}'.format(
            cudaID, screen, codePath, 'train', mFile)

    print(cmd)
    os.system(cmd)
Пример #3
0
    else:
        cmd = "CUDA_VISIBLE_DEVICES={} screen -dmS {} python {} -F {} -M {}".format(
            cudaID, screen, codePath, "train", mFile)

    # if screen is None:
    #     #add some debugs Dapeng
    #     parser = argparse.ArgumentParser()
    #     parser.add_argument('-F', dest='func', type=str, default='train')
    #     parser.add_argument('-M', dest='mFile', type=str, default=mFile)
    #     args = parser.parse_args()
    #     if args.func == 'train':
    #         mDict = master.readMasterFile(args.mFile)
    #         master.train(mDict)
    #         # out = mDict['out']
    #         # email.sendEmail(subject='Training Done', text=out)

    print(cmd)
    os.system(cmd)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-F", dest="func", type=str)
    parser.add_argument("-M", dest="mFile", type=str)
    args = parser.parse_args()
    if args.func == "train":
        mDict = master.readMasterFile(args.mFile)
        master.train(mDict)
        # out = mDict['out']
        # email.sendEmail(subject='Training Done', text=out)
Пример #4
0
                FDCLS = gageid[testInd][sampleInLst[iT]][nearID].tolist()
                FDCList.append(FDCLS)

        outLst = [
            os.path.join(save_path, str(tempseed), testregdic, x)
            for x in caseLst
        ]
        # all the directories to test in this list

        icount = 0
        imig = 0
        for out in outLst:
            # testing sequence: LSTM, LSTM with FDC, LSTM with fractional FDC migration
            if interfaceOpt == 1:
                # load testing data
                mDict = master.readMasterFile(out)
                optData = mDict["data"]
                df = camels.DataframeCamels(subset=testBasin, tRange=tRange)
                x = df.getDataTs(varLst=optData["varT"],
                                 doNorm=False,
                                 rmNan=False)
                obs = df.getDataObs(doNorm=False, rmNan=False, basinnorm=False)
                c = df.getDataConst(varLst=optData["varC"],
                                    doNorm=False,
                                    rmNan=False)

                # do normalization and remove nan
                # load the saved statDict
                statFile = os.path.join(out, "statDict.json")
                with open(statFile, "r") as fp:
                    statDict = json.load(fp)
Пример #5
0
#     masterDict = master.wrapMaster(out, optData, optModel, optLoss, optTrain)
#     master.runTrain(masterDict, cudaID=cid % 3, screen='test-DA' + str(nDay))
#     cid = cid + 1

# test original model
caseLst = ['All-90-95']
nDayLst = [1, 3, 7]
for nDay in nDayLst:
    caseLst.append('All-90-95-DA' + str(nDay))
outLst = [os.path.join(pathCamels['Out'], save_path, x) for x in caseLst]
# subset = 'All'
# subset = pubid
tRange = [19950101, 20000101]
predLst = list()
for out in outLst:
    tempdict = master.readMasterFile(out)
    trainid = np.array(tempdict['data']['subset'])
    subset = trainid.tolist()
    df, pred, obs = master.test(out,
                                tRange=tRange,
                                subset=subset,
                                basinnorm=True,
                                epoch=200)
    # pred=np.maximum(pred,0)
    predLst.append(pred)

# plot box
statDictLst = [stat.statError(x.squeeze(), obs.squeeze()) for x in predLst]
# keyLst = list(statDictLst[0].keys())
keyLst = ['Bias', 'RMSE', 'NSE']
dataBox = list()