def main(): #args = parseArgs(sys.argv) for house in [ 'C', 'B' , 'A']: for f in ['lastchange']: loc = data_loc_str.format(house=house,feature=f) data = load.data(loc) classify(data, house, f)
def main(): #args = parseArgs(sys.argv) for house in ['C', 'B', 'A']: for f in ['lastchange']: loc = data_loc_str.format(house=house, feature=f) data = load.data(loc) classify(data, house, f)
def translation(init_tuple): filename = init_tuple[0] ion_steps_scope = init_tuple[2] ions_scope = init_tuple[3] number_of_ions = ions_scope[1] - ions_scope[0] # Attaching 3D axis to the figure fig = plt.figure() ax = p3.Axes3D(fig) paths = load.data(init_tuple) for ion in range(number_of_ions): ax.plot(paths[:, ion, 0], paths[:, ion, 1], paths[:, ion, 2]) # Setting the axes properties ax.set_xlim3d([0.0, 6.0]) ax.set_xlabel('X') ax.set_ylim3d([0.0, 6.0]) ax.set_ylabel('Y') ax.set_zlim3d([0.0, 6.0]) ax.set_zlabel('Z') ax.set_title('Diffusion plot in: {}'.format(filename)) plt.show()
def main(): #sample: {"y_pred":[], "y_true":[], "acc":[]} #args = parseArgs(sys.argv) for house in ['A', 'B', 'C']: for f in ['lastchange']: #,'last', 'change', 'data']: loc = data_loc_str.format(house=house, feature=f) data = load.data(loc) classify(data, house, f)
def main(): #sample: {"y_pred":[], "y_true":[], "acc":[]} #args = parseArgs(sys.argv) for house in [ 'A', 'B' , 'C']: for f in ['lastchange']:#,'last', 'change', 'data']: loc = data_loc_str.format(house=house,feature=f) data = load.data(loc) classify(data, house, f)
def main(): args = parseArgs(sys.argv) if args.source == 'k': data = load.data(args.data) elif args.source == 't': data = load.tulum(args.data, dtype_str=True) else: print('Invalid data source specified: {}'.format(args.source)) sys.exit(1) classify(data, args.clfFile, args.resultsFile)
def main(): args = parseArgs(sys.argv) raw = load.data(args.input) rep = None if args.representation == 'last': rep = last(raw) elif args.representation == 'change': rep = change(raw) else: print('Invalid representation requested: {}'.format( args.representation)) sys.exit(1) write(rep, args.output)
def train(name): model, checkpoint, tensorboard, pre_input, decode = choose_model(name) train_generator, validation_generator = load.data( train_path=param['train'], vali_path=param['validate'], size=param['image_size'], batch_size=param['batch_size'], preprocess_input=pre_input) hist = model.fit_generator(generator=train_generator, steps_per_epoch=10, epochs=param['num_epoch'], validation_data=validation_generator, validation_steps=10, verbose=1, callbacks=[tensorboard, checkpoint]) return hist
def animated_translation(file_to_load, dimensions, ion_steps, scope, cell_size): def update_lines(num, data_lines, lines): for line, data_temp in zip(lines, data_lines): # NOTE: there is no .set_data() for 3 dim data... line.set_data(data_temp[0:2, :num]) line.set_3d_properties(data_temp[2, :num]) return lines # Attaching 3D axis to the figure fig = plt.figure() ax = p3.Axes3D(fig) data = load.data(file_to_load, dimensions, ion_steps, scope, cell_size) ion_path = [ ax.plot(dat[0, 0:1], dat[1, 0:1], dat[2, 0:1])[0] for dat in data ] # Setting the axes properties ax.set_xlim3d([0.0, 1.0]) ax.set_xlabel('X') ax.set_ylim3d([0.0, 1.0]) ax.set_ylabel('Y') ax.set_zlim3d([0.0, 1.0]) ax.set_zlabel('Z') ax.set_title('Diffusion plot in: {}'.format(file_to_load)) # Creating the Animation object line_ani = animation.FuncAnimation(fig, update_lines, ion_steps, fargs=(data, ion_path), interval=50, blit=False) plt.show()
def simple(init_tuple): data = load.data(init_tuple) ion_steps_scope = init_tuple[2] number_of_ion_steps = ion_steps_scope[1] - ion_steps_scope[0] ions_scope = init_tuple[3] number_of_ions = ions_scope[1] - ions_scope[0] step = np.arange(number_of_ion_steps) msd_n = [ numeric.msd_simple(data[:, atom]) for atom in range(number_of_ions) ] msd = [] for j in range(ion_steps_scope[0], ion_steps_scope[1]): sum = 0.0 for i in msd_n: sum += i[j] msd.append(sum / number_of_ions) return step, msd
def main(): # args = parseArgs(sys.argv) for house in ['A', 'B', 'C']: for f in ['data', 'last', 'change']: loc = data_loc_str.format(house=house, feature=f) #load the data data = load.data(loc, dtype_str=False) res_obj = {"y_pred": [], "y_true": [], "acc": []} #split data into training and testing #trainDf, testDf, trainLens, testLens, testFrac = split.trainTest( # data, 5400, 5400*2, testSize=0.3) #### WITHOUT CROSSVALID #X_test = np.array_split(np.array(testDf.values[:, :testDf.shape[1] - 2], dtype=np.uint8),2) #y_test = np.array_split(np.array(testDf.values[:, testDf.shape[1] - 1], dtype=np.uint8),2) #test_CRF(X_train, X_test, y_train, y_test, house, f,999) #exit() #### WITHOUT CROSSVALID #kfold X_train = np.array( np.array_split(data.values[:, :data.shape[1] - 2], 10)) y_train = np.array( np.array_split(data.values[:, data.shape[1] - 1], 10)) kf = KFold(len(X_train), n_folds=5) #kfold #strat #X_train = np.array(data.values[:, :data.shape[1] - 2]) #y_train = np.array(data.values[:, data.shape[1] - 1]) #kf = StratifiedKFold(data['activity'], n_folds=5) #strat accuracies = [] # cross validation for i, (train_index, test_index) in enumerate(kf): print("TRAIN:", train_index, "TEST:", test_index) X_train1, X_test1 = X_train[train_index], X_train[test_index] y_train1, y_test1 = y_train[train_index], y_train[test_index] #stratfied #X_train1 = np.array_split(X_train1, 100) #X_test1 = np.array_split(X_test1, 10) #y_train1 = np.array_split(y_train1, 100) #y_test1 = np.array_split(y_test1, 10) #strat clf = train_HMM(X_train1, y_train1, house, f, i) accuracy, y_pred, y_true = test_HMM(clf, X_test1, y_test1, house, f, i) obj = { "y_pred": y_pred.tolist(), "y_true": y_true.tolist(), "acc": accuracy } #write the results: with gzip.open( 'hmm_model_f/hmm_' + house + f + str(i) + '.json.gz', 'w') as out: json.dump(obj, out) #clfs.append(clf) accuracies.append(accuracy) res_obj['y_pred'].append(y_pred.tolist()) res_obj['y_true'].append(y_true.tolist()) res_obj['acc'].append(accuracy) print accuracies with gzip.open('hmm_model_f/hmm_' + house + f + '_all.json.gz', 'w') as out: json.dump(res_obj, out)
def main(): # args = parseArgs(sys.argv) for house in [ 'A', 'B' , 'C']: for f in ['data', 'last', 'change']: loc = data_loc_str.format(house=house,feature=f) #load the data data = load.data(loc, dtype_str=False) res_obj = {"y_pred":[], "y_true":[], "acc":[]} #split data into training and testing #trainDf, testDf, trainLens, testLens, testFrac = split.trainTest( # data, 5400, 5400*2, testSize=0.3) #### WITHOUT CROSSVALID #X_test = np.array_split(np.array(testDf.values[:, :testDf.shape[1] - 2], dtype=np.uint8),2) #y_test = np.array_split(np.array(testDf.values[:, testDf.shape[1] - 1], dtype=np.uint8),2) #test_CRF(X_train, X_test, y_train, y_test, house, f,999) #exit() #### WITHOUT CROSSVALID #kfold X_train = np.array(np.array_split(data.values[:, :data.shape[1] - 2], 10)) y_train = np.array(np.array_split(data.values[:, data.shape[1] - 1], 10)) kf = KFold(len(X_train), n_folds=5) #kfold #strat #X_train = np.array(data.values[:, :data.shape[1] - 2]) #y_train = np.array(data.values[:, data.shape[1] - 1]) #kf = StratifiedKFold(data['activity'], n_folds=5) #strat accuracies = [] # cross validation for i, (train_index, test_index) in enumerate(kf): print("TRAIN:", train_index, "TEST:", test_index) X_train1, X_test1 = X_train[train_index], X_train[test_index] y_train1, y_test1 = y_train[train_index], y_train[test_index] #stratfied #X_train1 = np.array_split(X_train1, 100) #X_test1 = np.array_split(X_test1, 10) #y_train1 = np.array_split(y_train1, 100) #y_test1 = np.array_split(y_test1, 10) #strat clf = train_HMM(X_train1, y_train1, house, f, i) accuracy, y_pred, y_true = test_HMM(clf, X_test1, y_test1, house, f, i) obj = {"y_pred":y_pred.tolist(), "y_true":y_true.tolist(), "acc":accuracy} #write the results: with gzip.open('hmm_model_f/hmm_' + house + f + str(i)+ '.json.gz', 'w') as out: json.dump(obj, out) #clfs.append(clf) accuracies.append(accuracy) res_obj['y_pred'].append(y_pred.tolist()) res_obj['y_true'].append(y_true.tolist()) res_obj['acc'].append(accuracy) print accuracies with gzip.open('hmm_model_f/hmm_' + house + f +'_all.json.gz', 'w') as out: json.dump(res_obj, out)
def _load(self, file=None): # Loads list of questions from dataset self.file = file if file else self.file self.df = load.data(file) self.data = self.df.Task.values self.size = self.data.size