def objective(params): #optimize_model = build_lstm_v1.lstm_model_102(params, train_data.shape[2], 24, 24) #optimize_model = build_lstm_v1.lstm_model_106(params, train_data.shape[2], 24) optimize_model = build_lstm_v1.lstm_model_110b(params, train_data.shape[2], 24) #for epochs in range(5): for ep in range(20): #optimize_history = optimize_model.fit(X_seq, Y_seq, batch_size=1, nb_epoch=3, validation_split=(X_seq, Y_seq), shuffle=False) optimize_history = optimize_model.fit(train_data, H_t, batch_size=1, nb_epoch=1, validation_data=(val_data, H_val), shuffle=False) #optimize_history = optimize_model.fit(train_data, H_t, batch_size=1, nb_epoch=1, validation_split=0.3, shuffle=False) optimize_model.reset_states() loss_v = optimize_history.history['val_loss'] print loss_v loss_out = loss_v[-1] return {'loss': loss_out, 'status': STATUS_OK}
def objective(params): optimize_model = build_lstm_v1.lstm_model_110b(params, train_data.shape[2], 24) loss_out = NNFunctions.model_optimizer_101(optimize_model, train_data, H_t, val_data, H_val, 10) return {'loss': loss_out, 'status': STATUS_OK}
optimize_model = build_lstm_v1.lstm_model_110b(params, train_data.shape[2], 24) loss_out = NNFunctions.model_optimizer_101(optimize_model, train_data, H_t, val_data, H_val, 10) return {'loss': loss_out, 'status': STATUS_OK} trials = Trials() best = fmin(objective, space, algo=tpe.suggest, trials=trials, max_evals=5) #Building Stateful Model lstm_hidden = hyperopt.space_eval(space, best) print lstm_hidden tsteps = 24 out_dim = 24 #lstm_model = build_lstm_v1.lstm_model_102(lstm_hidden, train_data.shape[2], out_dim, tsteps) lstm_model = build_lstm_v1.lstm_model_110b(lstm_hidden, train_data.shape[2], tsteps) save_model = lstm_model ##callbacks for Early Stopping callbacks = [EarlyStopping(monitor='val_loss', patience=3)] #parameters for simulation attempt_max = 3 epoch_max = 20 min_epoch = 10 #Criterion for early stopping tau = 5 e_mat = numpy.zeros((epoch_max, attempt_max)) e_temp = numpy.zeros((tau, ))