|
| 1 | +/* ***************************************************************************** |
| 2 | + * Copyright (c) 2020 Konduit, Inc. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Apache License, Version 2.0 which is available at |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0. |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 | + * License for the specific language governing permissions and limitations |
| 12 | + * under the License. |
| 13 | + * |
| 14 | + * SPDX-License-Identifier: Apache-2.0 |
| 15 | + ******************************************************************************/ |
| 16 | + |
| 17 | +import org.deeplearning4j.rl4j.learning.HistoryProcessor; |
1 | 18 | import org.deeplearning4j.rl4j.mdp.ale.ALEMDP;
|
2 | 19 | import org.deeplearning4j.rl4j.policy.ACPolicy;
|
3 | 20 |
|
4 | 21 | import java.io.IOException;
|
5 |
| -import java.util.logging.Logger; |
6 | 22 |
|
| 23 | +/** |
| 24 | + * @author robaltena |
| 25 | + * |
| 26 | + * This sample shows how to plat an ALE game with a trained model. |
| 27 | + */ |
7 | 28 | public class PlayALE {
|
8 | 29 | public static void main(String[] args) throws IOException {
|
9 |
| - ALEMDP mdp = new ALEMDP("E:\\projects\\ArcadeLearningEnvironment\\pong.bin"); |
| 30 | + ALEMDP mdp = new ALEMDP("pong.bin", true); |
10 | 31 |
|
11 |
| - //load the previous agent |
| 32 | + //load the trained agent |
12 | 33 | ACPolicy<ALEMDP.GameScreen> pol2 = ACPolicy.load("ale-a3c.model");
|
13 | 34 |
|
14 |
| - //evaluate the agent |
15 |
| - double rewards = 0; |
16 |
| - for (int i = 0; i < 10; i++) { |
17 |
| - mdp.reset(); |
18 |
| - double reward = pol2.play(mdp); |
19 |
| - rewards += reward; |
20 |
| - Logger.getAnonymousLogger().info("Reward: " + reward); |
21 |
| - } |
22 |
| - |
23 |
| - Logger.getAnonymousLogger().info("average: " + rewards/1000); |
| 35 | + //The training history processor used for data pre processing steps. |
| 36 | + HistoryProcessor.Configuration ALE_HP = new HistoryProcessor.Configuration( |
| 37 | + 4, //History length |
| 38 | + 84, //resize width |
| 39 | + 110, //resize height |
| 40 | + 84, //crop width |
| 41 | + 84, //crop height |
| 42 | + 0, //cropping x offset |
| 43 | + 0, //cropping y offset |
| 44 | + 4 //skip mod (one frame is picked every x |
| 45 | + ); |
24 | 46 |
|
| 47 | + pol2.play(mdp, ALE_HP); |
| 48 | + mdp.close(); |
25 | 49 | }
|
26 | 50 | }
|
0 commit comments