A multi-layer perceptron
(input_dim, n_action, n_hidden_layers=1, hidden_dim=32)
| 90 | |
| 91 | |
| 92 | def mlp(input_dim, n_action, n_hidden_layers=1, hidden_dim=32): |
| 93 | """ A multi-layer perceptron """ |
| 94 | |
| 95 | # input layer |
| 96 | i = Input(shape=(input_dim,)) |
| 97 | x = i |
| 98 | |
| 99 | # hidden layers |
| 100 | for _ in range(n_hidden_layers): |
| 101 | x = Dense(hidden_dim, activation='relu')(x) |
| 102 | |
| 103 | # final layer |
| 104 | x = Dense(n_action)(x) |
| 105 | |
| 106 | # make the model |
| 107 | model = Model(i, x) |
| 108 | |
| 109 | model.compile(loss='mse', optimizer='adam') |
| 110 | print((model.summary())) |
| 111 | return model |
| 112 | |
| 113 | |
| 114 |