Ejemplo n.º 1
0
def create_train_model(train_dset, ids, max_states, max_obs, precision):

    sshmms = []
    print('Creating load PMFs and finding load states...')
    print('\tMax partitions per load =', max_states)
    pmfs = []
    for id in ids:
        pmfs.append(
            EmpiricalPMF(id, max_obs * precision,
                         list(train_dset[id].astype(int))))
        pmfs[-1].quantize(max_states, ε)
    #%
    print()
    print('Creating compressed SSHMM...')
    incro = 1 / precision
    sshmm = SuperStateHMM(pmfs, [i for i in frange(0, max_obs + incro, incro)])

    print('\tConverting DataFrame in to obs/hidden lists...')
    #%
    #tempme = deepcopy(train_dset)
    train_dset = train_dset.astype(int)
    #len(train_dset)

    obs_id = list(train_dset)[0]
    obs = list(train_dset[obs_id])
    hidden = [i for i in train_dset[ids].to_records(index=False)]

    sshmm.build(obs, hidden)
    sshmms.append(sshmm)
    return sshmms
Ejemplo n.º 2
0
datasets_dir = './datasets/%s.csv'
logs_dir = './logs/%s.log'
models_dir = './models/%s.json'

print()
print('Loading saved model %s from JSON storage (%s)...' %
      (modeldb, models_dir % modeldb))
fp = open(models_dir % modeldb, 'r')
jdata = json.load(fp)
fp.close()
folds = len(jdata)
print('\tModel set for %d-fold cross-validation.' % folds)
print('\tLoading JSON data into SSHMM objects...')
sshmms = []
for data in jdata:
    sshmm = SuperStateHMM()
    sshmm._fromdict(data)
    sshmms.append(sshmm)
del jdata
labels = sshmms[0].labels
print('\tModel lables are: ', labels)

print()
print('Testing %s algorithm load disagg...' % algo_name)
acc = Accuracy(len(labels), folds)
test_times = []
indv_tm_sum = 0.0
indv_count = 0
y_noise = 0.0
y_total = 0.0
calc_done = [0, 0]
Ejemplo n.º 3
0
for (fold, priors, testing) in folds: 
    del testing
    tm_start = time()
    
    print()
    print('Creating load PMFs and finding load states...')
    print('\tMax partitions per load =', max_states)
    pmfs = []
    for id in ids:
        pmfs.append(EmpiricalPMF(id, max_obs * precision, list(priors[id])))
        pmfs[-1].quantize(max_states, ε)

    print()
    print('Creating compressed SSHMM...')
    incro = 1 / precision
    sshmm = SuperStateHMM(pmfs, [i for i in frange(0, max_obs + incro, incro)])
    
    print('\tConverting DataFrame in to obs/hidden lists...')
    obs_id = list(priors)[0]
    obs = list(priors[obs_id])
    hidden = [i for i in priors[ids].to_records(index=False)]
    
    sshmm.build(obs, hidden)
    sshmms.append(sshmm)
    
    train_times.append((time() - tm_start) / 60)

print()
print('Train Time was', round(sum(train_times), 2), ' min (avg ', round(sum(train_times) / len(train_times), 2), ' min/fold).')

print()
Ejemplo n.º 4
0
for (fold, priors, testing) in folds:
    del testing
    tm_start = time()

    print()
    print('Creating load PMFs and finding load states...')
    print('\tMax partitions per load =', max_states)
    pmfs = []
    for id in ids:
        pmfs.append(EmpiricalPMF(id, max_obs * precision, list(priors[id])))
        pmfs[-1].quantize(max_states, ε)

    print()
    print('Creating compressed SSHMM...')
    incro = 1 / precision
    sshmm = SuperStateHMM(pmfs, [i for i in frange(0, max_obs + incro, incro)])

    print('\tConverting DataFrame in to obs/hidden lists...')
    obs_id = list(priors)[0]
    obs = list(priors[obs_id])
    hidden = [i for i in priors[ids].to_records(index=False)]

    sshmm.build(obs, hidden)
    sshmms.append(sshmm)

    train_times.append((time() - tm_start) / 60)

print()
print('Train Time was', round(sum(train_times), 2), ' min (avg ',
      round(sum(train_times) / len(train_times), 2), ' min/fold).')
Ejemplo n.º 5
0
datasets_dir = './datasets/%s.csv'
logs_dir = './logs/%s.log'
models_dir = './models/%s.json'

print()
print('Loading saved model %s from JSON storage (%s)...' % (modeldb, models_dir % modeldb))
fp = open(models_dir % modeldb, 'r')
jdata = json.load(fp)
fp.close()
folds = len(jdata)
print('\tModel set for %d-fold cross-validation.' % folds)
print('\tLoading JSON data into SSHMM objects...')
sshmms = []
for data in jdata:
    sshmm = SuperStateHMM()
    sshmm._fromdict(data)
    sshmms.append(sshmm)
del jdata
labels = sshmms[0].labels
print('\tModel lables are: ', labels)

print()
print('Testing %s algorithm load disagg...' % algo_name)
acc = Accuracy(len(labels), folds)
test_times = []

print()
folds = Folding(dataset_loader(datasets_dir % dataset, labels, precision, denoised), folds)
for (fold, priors, testing) in folds: 
    del priors