defaultDataGenValues[u'simLength'] = 4000 defaultDataGenValues[u'AR_n'] = AR_n defaultDataGenValues[u'coefVariance'] = 0.2 defaultDataGenValues[u'batchSize'] = 32 defaultDataGenValues[u'dataLength'] = 20 defaultDataGenValues[u'seed'] = 10 defaultDataGenValues[u'cuda'] = True dataGenParameters = [ defaultDataGenValues['simLength'], defaultDataGenValues['AR_n'], defaultDataGenValues['coefVariance'], defaultDataGenValues['batchSize'], defaultDataGenValues['dataLength'] ] trueStateData, measuredStateData = ARDatagenMismatch( dataGenParameters, defaultDataGenValues['seed'], cuda=defaultDataGenValues['cuda']) # If a file path was passed to it, load the data from the file. Expects it to be formatted how # ARDatagenMismatch formats it else: # Throw error if filepath could not be found if (not path.exists(args.filePath)): raise Exception('file path: "{}" could not be found'.format( args.filePath)) matData = hdf5s.loadmat(args.filePath) measuredStateData = matData['measuredData'] trueStateData = matData['predAndCurState'] print('loaded from file: ', args.filePath)
if (args.model_path != 'None'): testSession = True modelContext = torch.load(args.model_path) modelPath = args.model_path ### ~~~~~~~~~~~~~~~ LOAD DATA/GENERATE MODEL ~~~~~~~~~~~~~~~~ ### # Here we have the option of loading from a saved .mat file or just calling the data generation # function explicitly # AR data generation parameters AR_n = 2 # ~~~~~~~~~~~~~~~~~~ LOAD TRAINING SET if not testSession: if (trainFile == 'None'): # Generate AR process training data set - both measured and real states trainStateData, trainStateInfo = ARDatagenMismatch( [trainDataLen, AR_n, AR_var, seq_length], seed, args.cuda) # Convert the data from normal formatting to batches trueStateTRAIN, measuredStateTRAIN = convertToBatched( trainStateData[2], trainStateData[1], batch_size) fileContent[u'trainDataFile'] = trainStateInfo['filename'] fileContent[u'trainDataSize'] = trueStateTRAIN.shape # TODO: Improve the format at some point in the future, but for now we are just grabbing the trainingData to train # TODO: the LS LSTrainData = trainStateData else: # Grab the data from the .mat file trainDataDict = hdf5s.loadmat(trainFile) print('train data loaded from: {}'.format(trainFile)) # Convert the loaded data into batches for the TCN to run with trueStateTRAIN, measuredStateTRAIN = convertToBatched( trainDataDict['finalStateValues'], trainDataDict['observedStates'],
trainFile = args.trainDataFile testFile = args.testDataFile ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### ### ~~~~~~~~~~~~~~~ LOAD DATA/GENERATE MODEL ~~~~~~~~~~~~~~~~ ### # Here we have the option of loading from a saved .mat file or just calling the data generation # function explicitly # AR data generation parameters AR_n = 2 # ~~~~~~~~~~~~~~~~~~ LOAD TRAINING SET if (trainFile == 'None'): # Generate AR process training data set - both measured and real states trueState, measuredState = ARDatagenMismatch( [simu_len, AR_n, AR_var, batch_size, seq_length], seed, args.cuda) # Logging the train data fileContent[u'trainDataActual'] = trueState fileContent[u'trainDataMeas'] = measuredState # loading the data from the file else: # Grab the data from the .mat file trainDataDict = hdf5s.loadmat(trainFile) measuredState = trainDataDict['measuredData'] trueState = trainDataDict['predAndCurState'] # Convert numpy arrays to tensors trueState = torch.from_numpy(trueState) measuredState = torch.from_numpy(measuredState)
# coefficients used for testing in the 1st dimension, # batch elements in the 2nd dimension, real and complex # values in the 3rd dimension, sequence elements in the # 4th dimension, and by batches in the 5th dimension measuredStateTEST = np.empty( (numCoeffs, batchSize, 2, seqLen, testSeriesLength), dtype=float) LSandKFTestData = [] testDataInfo = [] for k in range(0, numCoeffs): # Generating the data with no variance between sequences (which is what the False in the array is for) # because we want to generate data with a single set of AR Coefficients subsetTestStateData, subsetTestDataInfo = ARDatagenMismatch( params=[testDataLen, 2, 0, seqLen, False], seed=seed + k, arCoeffs=stableCoeffs[k]) trueStateTEST[k, :, :, :], measuredStateTEST[ k, :, :, :, :] = convertToBatched(subsetTestStateData[2], subsetTestStateData[1], batchSize) # Storing the data that the Least Squares and Kalman Filter will be using LSandKFTestData.append(subsetTestStateData) subsetInfoHolder = {} # Grabbing the first riccatiConvergence because they should all be the same for both the estimate and prediction subsetInfoHolder[u'riccatiConvergencePred'] = subsetTestDataInfo[ 'riccatiConvergences'][0, 0] subsetInfoHolder[u'riccatiConvergenceEst'] = subsetTestDataInfo[ 'riccatiConvergences'][1, 0] # Grabbing the first set of AR Coefficients from the F matrix because they should all be the same
defaultDataGenValues[u'simLength'] = 400 defaultDataGenValues[u'AR_n'] = AR_n defaultDataGenValues[u'coefVariance'] = 0 defaultDataGenValues[u'dataLength'] = 20 defaultDataGenValues[u'seed'] = 10 defaultDataGenValues[u'cuda'] = False dataGenParameters = [ defaultDataGenValues['simLength'], defaultDataGenValues['AR_n'], defaultDataGenValues['coefVariance'], defaultDataGenValues['dataLength'] ] # trueStateData, measuredStateData = ARDatagenMismatch(dataGenParameters, defaultDataGenValues['seed'], cuda=defaultDataGenValues['cuda']) stateData, stateInfo = ARDatagenMismatch(dataGenParameters, defaultDataGenValues['seed'], cuda=defaultDataGenValues['cuda']) trueStateData = stateData[2] measuredStateData = stateData[1] all_F = stateInfo['allF'] # If a file path was passed to it, load the data from the file. Expects it to be formatted how # ARDatagenMismatch formats it - also loads all F matrices for best possible MSE value computation else: # Throw error if filepath could not be found if (not path.exists(args.filePath)): raise Exception('file path: "{}" could not be found'.format( args.filePath)) matData = hdf5s.loadmat(args.filePath) measuredStateData = matData['observedStates']
# Variance of AR Coeffieients parser.add_argument('--arVar', type=float, default=0.1, help='the variance of the AR Coefficients for each AR process (default=0.1)') # Order of AR process parser.add_argument('--AR_n', type=int, default=2, help='the order of the AR process that will be generated (default=2)' \ '{as of this comment, features related to this parameter have not been implmented yet, so' \ 'change the value of this from the default at your own peril}') # GPU used for data generation parser.add_argument('--cuda', action='store_true', help='use CUDA for data generation (default: False)') # Seed for the random number generation parser.add_argument('--seed', type=int, default=1111, help='seed for the rng of the data') args = parser.parse_args() # Setting up a time to determine how long data generation takes start = time.time() trueState, measuredState = ARDatagenMismatch([int(args.simLength),args.AR_n, args.arVar,int(args.batchSize), int(args.sequenceLength)], args.seed, args.cuda) end=time.time() print('it took this many seconds to generate the data', end-start) print(args)
# Order of AR process parser.add_argument('--AR_n', type=int, default=2, help='the order of the AR process that will be generated (default=2)' \ '{as of this comment, features related to this parameter have not been implmented yet, so' \ 'change the value of this from the default at your own peril}') # GPU used for data generation parser.add_argument('--cuda', action='store_true', help='use CUDA for data generation (default: False)') # Seed for the random number generation parser.add_argument('--seed', type=int, default=1111, help='seed for the rng of the data') args = parser.parse_args() # Setting up a time to determine how long data generation takes start = time.time() stateData, info = ARDatagenMismatch( [int(args.simLength), args.AR_n, args.arVar, int(args.sequenceLength)], args.seed, args.cuda) end = time.time() print('it took this many seconds to generate the data', end - start) print(args)