diff --git a/experiments/final.py b/experiments/final.py index f70c4e2..73c41f7 100644 --- a/experiments/final.py +++ b/experiments/final.py @@ -11,20 +11,59 @@ filenames_valid = ['2016'] features_train = ['air_temperature'] features_predict = ['air_temperature'] +regularization = None +""" +Experiment I: Nodes per layer +""" +n_nodes = [0.2, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0] +act = 'relu' +n_memory = 1 +n_dense_pre = 3 +n_dense_pos = 3 +memory_unit = 'lstm' +for n_node in n_nodes: + model = create_model(batch_size=batch_size, + t_train=t_train_h, + t_pred=int(t_pred_d * 24 / t_pred_resolution_h), + n_features_train=len(features_train), + n_stations=n_stations, + memory_unit=memory_unit, + width=n_dense_pre, + n_layers_memory=n_memory, + n_layers_preprocessing=n_dense_pre, + n_layers_postprocessing=n_dense_pos, + n_features_pred=len(features_predict), + activation=act, + mask_value=MASK_VALUE, + regularization=regularization) + + # '{layer_pre}x{n_nodes}*{act}->[{memory}]{n_lstm}->{layer_pos}{n_nodes}*{act}' + log_dir = 'out/{}-{}-{}-{}{}-{}-{}-{}'.format(n_dense_pre, int(n_node * 10), act, memory_unit, n_memory, + n_dense_pos, int(n_stations / n_dense_pre), act) + + train(radius=radius, + batch_size=batch_size, + log_dir=log_dir, + t_train_h=t_train_h, + t_pred_d=t_pred_d, + t_pred_resolution_h=t_pred_resolution_h, + model_name=model, + filenames_train=filenames_train, + filenames_valid=filenames_valid, + features_train=features_train, + features_predict=features_predict, + ) """ -Experiment I: Final +Experiment II: Memory Depth """ -n_dense_pres = [1, 2, 3] +n_lstms = [1, 2, 4, 8] n_node = 1.0 act = 'relu' -n_memory = 2 -n_dense_poss = [1, 2, 3] +n_dense_pre = 3 +n_dense_pos = 3 memory_unit = 'lstm' -reg = None -for i in range(3): - n_dense_pos = n_dense_poss[i] - n_dense_pre = n_dense_pres[i] +for n_memory in n_lstms: model = create_model(batch_size=batch_size, t_train=t_train_h, t_pred=int(t_pred_d * 24 / t_pred_resolution_h), @@ -38,7 +77,7 @@ n_features_pred=len(features_predict), activation=act, mask_value=MASK_VALUE, - regularization=None) + regularization=regularization) # '{layer_pre}x{n_nodes}*{act}->[{memory}]{n_lstm}->{layer_pos}{n_nodes}*{act}' log_dir = 'out/{}-{}-{}-{}{}-{}-{}-{}'.format(n_dense_pre, int(n_node * 10), act, memory_unit, n_memory, @@ -56,3 +95,46 @@ features_train=features_train, features_predict=features_predict, ) + +""" +Experiment III: Regularization +""" +n_nodes = 1.0 +act = 'relu' +regs = ['Dropout50', 'Dropout25', 'l1', 'l2'] +n_memory = 2 +n_dense_pre = 3 +n_dense_pos = 3 +memory_unit = 'lstm' +for reg in regs: + model = create_model(batch_size=batch_size, + t_train=t_train_h, + t_pred=int(t_pred_d * 24 / t_pred_resolution_h), + n_features_train=len(features_train), + n_stations=n_stations, + memory_unit=memory_unit, + width=n_dense_pre, + n_layers_memory=n_memory, + n_layers_preprocessing=n_dense_pre, + n_layers_postprocessing=n_dense_pos, + n_features_pred=len(features_predict), + activation=act, + mask_value=MASK_VALUE, + regularization=reg) + + # '{layer_pre}x{n_nodes}*{act}->[{memory}]{n_lstm}->{layer_pos}{n_nodes}*{act}' + log_dir = 'out/{}-{}-{}-{}{}-{}-{}-{}'.format(n_dense_pre, int(n_node * 10), act, memory_unit, n_memory, + n_dense_pos, int(n_stations / n_dense_pre), act) + + train(radius=radius, + batch_size=batch_size, + log_dir=log_dir, + t_train_h=t_train_h, + t_pred_d=t_pred_d, + t_pred_resolution_h=t_pred_resolution_h, + model_name=model, + filenames_train=filenames_train, + filenames_valid=filenames_valid, + features_train=features_train, + features_predict=features_predict, + ) \ No newline at end of file diff --git a/plots/plot_architecture.py b/plots/plot_architecture.py index 4af4780..4772e3b 100644 --- a/plots/plot_architecture.py +++ b/plots/plot_architecture.py @@ -3,30 +3,61 @@ from downloadData.functions.file_utils import load_file -model_names = ['1-10-relu-lstm1-3-41-relu', '2-10-relu-lstm1-3-20-relu', '3-2-relu-lstm1-3-13-relu', +csfont = {'fontname': 'Century Gothic'} +std = 10.67839587 +post = ['3-10-relu-lstm1-1-55-relu', '3-10-relu-lstm1-2-55-relu' ,'3-10-relu-lstm1-4-55-relu', + '3-10-relu-lstm1-8-55-relu'] +pre = ['1-10-relu-lstm1-1-165-relu', '2-10-relu-lstm1-2-82-relu', '4-10-relu-lstm1-3-41-relu', + '8-10-relu-lstm1-8-20-relu'] +memory = ['3-10-relu-lstm1-3-13-relu', '3-10-relu-lstm2-3-13-relu', '3-10-relu-lstm4-3-13-relu', + '3-10-relu-lstm8-3-13-relu'] +layers = np.array([1, 2, 4, 8]) +plt.subplot(2, 1, 1) +performances = [] +for i, r in enumerate(post): + mat = np.array(load_file('../out/' + r + '/log.csv')) + valid_loss = mat[1:, 2].astype(np.float32) + y = np.min(valid_loss)*std**2 + performances.append(y) +plt.bar(layers, performances, width=0.2, color='b', align='center') +performances = [] +for i, r in enumerate(pre): + mat = np.array(load_file('../out/' + r + '/log.csv')) + valid_loss = mat[1:, 2].astype(np.float32) + y = np.min(valid_loss)*std**2 + performances.append(y) +plt.bar(layers - 0.2, performances, width=0.2, color='g', align='center') +layers = np.array([1, 2, 4, 8]) +performances = [] +for i, r in enumerate(memory): + mat = np.array(load_file('../out/' + r + '/log.csv')) + valid_loss = mat[1:, 2].astype(np.float32) + y = np.min(valid_loss)*std**2 + performances.append(y) +plt.bar(layers + 0.2, performances, width=0.2, color='r', align='center') +plt.legend(['Postprocessing', 'Preprocessing', 'Memory'], fontsize=16, prop={'family': 'Century Gothic'}) +plt.xlabel('Layers',fontsize=16, **csfont) +plt.ylabel('Mean Squared Error [$^\circ$C$^2$]', fontsize=16, **csfont) +plt.grid('on') +plt.title('Evaluation of Model Architecture in Terms of Validation Loss ', fontsize=20, **csfont) +plt.subplot(2, 1, 2) + +width = [0.2, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0] +model_names = ['3-2-relu-lstm1-3-13-relu', '3-5-relu-lstm1-3-13-relu', - '3-10-relu-lstm1-1-13-relu', '3-10-relu-lstm1-2-13-relu', '3-10-relu-lstm1-4-13-relu', - '3-10-relu-lstm1-8-13-relu', '3-10-relu-lstm2-3-13-relu', '3-10-relu-lstm4-3-13-relu', - '3-10-relu-lstm8-3-13-relu', '3-15-relu-lstm1-3-13-relu', '3-20-relu-lstm1-3-13-relu', - '3-25-relu-lstm1-3-13-relu', '3-30-relu-lstm1-3-13-relu', '4-10-relu-lstm1-3-10-relu', - '8-10-relu-lstm1-3-5-relu'] -legend = ['pre1-mem1-post3', 'pre2-mem1-post3', 'pre2-mem1-post3','pre3-mem1-post3', 'pre3-mem1-post1', 'pre3-mem1-post2', - 'pre3-mem1-post4', - 'pre3-mem1-post8', 'pre3-mem2-post3', 'pre3-mem4-post3', 'pre3-mem8-post3', 'pre3-mem1-post3', - 'pre3-mem1-post3', - 'pre3-mem1-post3', 'pre3-mem1-post3', 'pre4-mem1-post3', 'pre8-mem1-post3'] -legend = model_names -layers = [5, 6, 6,7,5, 6, 8, 12, 8, 10, 14, 7, 7, 7, 7, 8, 12] + '3-10-relu-lstm1-3-13-relu', + '3-15-relu-lstm1-3-13-relu', + '3-20-relu-lstm1-3-13-relu', + '3-25-relu-lstm1-3-13-relu', '3-30-relu-lstm1-3-13-relu'] +performances = [] for i, r in enumerate(model_names): mat = np.array(load_file('../out/' + r + '/log.csv')) valid_loss = mat[1:, 2].astype(np.float32) - x = layers[i] - y = np.min(valid_loss) - plt.plot(x, y, '*') - plt.annotate(legend[i], xy=(x, y)) + y = np.min(valid_loss)*std**2 + performances.append(y) +plt.plot(width, performances, '--*') -plt.xlabel('Layers') -plt.ylabel('Normalized Mean Squared Error [°C^2]') +plt.xlabel('*N_Nodes', fontsize=16, **csfont) +plt.ylabel('Mean Squared Error [$^\circ$C$^2$]', fontsize=16, **csfont) plt.grid('on') -plt.title('Evaluation of Model Architecture in Terms of Validation Loss') plt.show()