Skip to content

Commit 70dbae8

Browse files
committed
ready to pypi
1 parent 495ca42 commit 70dbae8

File tree

3 files changed

+52
-104
lines changed

3 files changed

+52
-104
lines changed

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pip3 install git+https://github.com/pvnetto/URNAI-Tools/
2424

2525
The basic installation will install all the *basic* required dependencies, including OpenAI Gym and SC2LE. But for other supported environments, you will need to install them for yourself. We describe how to do this on the next section.
2626

27+
To use tensorflowp-cpu instead of gpu, go to Optional below.
28+
2729
### Optional
2830

2931
#### Starcraft II
@@ -48,6 +50,10 @@ set "URNAI_2048=1" && pip3 install urnai
4850

4951
#### VizDoom
5052

53+
Before setting urnai to install vizdoom, please see if you have all dependencies installed.
54+
55+
Go [here] first.(https://github.com/mwydmuch/ViZDoom/blob/master/doc/Building.md#deps)
56+
5157
To install urnai with vizdoom support, use:
5258

5359
- On Unix:
@@ -87,17 +93,39 @@ URNAI_DEEPRTS=1 URNAI_VIZDOOM=1 URNAI_2048=1 pip3 install urnai
8793
```
8894
set "URNAI_DEEPRTS=1" && set "URNAI_VIZDOOM=1" && set "URNAI_2048=1" && pip3 install urnai
8995
```
96+
#### Tensorflow CPU
97+
98+
By default, urnai depdens on tensorflow-gpu, to use tf-cpu instead, use:
99+
100+
- On Unix:
101+
```
102+
URNAI_TF_CPU=1 pip3 install urnai
103+
```
90104

105+
- On Windows:
106+
```
107+
set "URNAI_TF_CPU=1" && pip3 install urnai
108+
```
91109
### Running the examples
92110

93-
To execute any of the examples we've included, just navigate to the project's folder and run them using Python.
111+
From version 0.0.2+ you can use json-files:
112+
113+
```
114+
git clone https://github.com/marcocspc/URNAI-Tools
115+
cd 'URNAI-Tools/urnai/test/solves'
116+
urnai train --json-file=solve_x.json
117+
```
118+
119+
## Command line
120+
121+
You can now use urnai on command line. Commands:
94122

123+
To see what you can do, use:
95124
```
96-
cd 'project/save/path'
97-
python solve_x.py
125+
urnai -h
98126
```
99127

100-
## Guide
128+
## Building your own code
101129

102130
Follow these instructions to start developing new stuff using our library.
103131

@@ -139,7 +167,6 @@ Here you'll find all the things that we plan to do in this project. **Bold** ite
139167
* [X] Frozenlake
140168
* [X] Cartpole-V0
141169
* [X] Cartpole-V1
142-
* [X] Taxi-V2
143170
* [ ] Flappy Bird
144171
* [ ] **StarCraft II - Simple 64 Map - Very Easy difficulty**
145172

urnai/agents/rewards/vizdoom.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,27 @@ def __init__(self):
3030
POSITION_Y = 15
3131
POSITION_Z = 16
3232
GENERAL_REWARD = 17
33+
34+
METHOD_CUMULATIVE = "cumulative"
35+
METHOD_DIFFERENCE = "difference"
36+
METHOD_POSITIVE_ONLY = "positive_only"
37+
38+
def __init__(self, method):
39+
self.method = method
3340

3441
def get_reward(self, obs, reward, done):
3542
r = 0
3643

37-
#r += -10 * obs.game_variables[VizDoomHealthGatheringReward.DEAD]
38-
#r += 15 * obs.game_variables[VizDoomHealthGatheringReward.ITEMCOUNT]
39-
r += obs.game_variables[VizDoomHealthGatheringReward.HEALTH] - self.prev_health
40-
#r += -10 * reward
41-
42-
if r >0: r *= 5
43-
44-
self.prev_health = obs.game_variables[VizDoomHealthGatheringReward.HEALTH]
44+
if method == VizDoomHealthGatheringReward.METHOD_CUMULATIVE:
45+
r += obs.game_variables[VizDoomHealthGatheringReward.HEALTH]
46+
elif method == VizDoomHealthGatheringReward.METHOD_DIFFERENCE:
47+
r += obs.game_variables[VizDoomHealthGatheringReward.HEALTH] - self.prev_health
48+
self.prev_health = obs.game_variables[VizDoomHealthGatheringReward.HEALTH]
49+
elif method == VizDoomHealthGatheringReward.METHOD_POSITIVE_ONLY:
50+
r += obs.game_variables[VizDoomHealthGatheringReward.HEALTH] - self.prev_health
51+
self.prev_health = obs.game_variables[VizDoomHealthGatheringReward.HEALTH]
52+
53+
if r < 0: r = 0
4554

4655
return r
4756

urnai/test/solves/solve_vizdoom.json

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -58,101 +58,13 @@
5858
},
5959
"reward" : {
6060
"class" : "VizDoomHealthGatheringReward",
61-
"params" : {}
62-
},
63-
"agent" : {
64-
"class" : "GenericAgent",
65-
"params" : {}
66-
},
67-
"trainer" : {
68-
"class" : "Trainer",
6961
"params" : {
70-
"file_name" : "vizdoom_jsontrainer_test",
71-
"save_every" : "100",
72-
"enable_save" : true
73-
}
74-
},
75-
"json_trainer" : {
76-
"train": {
77-
"num_episodes" : 3000,
78-
"reward_from_env" : true,
79-
"max_steps" : 500
80-
},
81-
"play" : {
82-
"num_matches" : 100
83-
}
84-
}
85-
},
86-
{
87-
"env" : {
88-
"class" : "VizdoomEnv",
89-
"params" : {
90-
"wad" : "/Users/marcocspc/git/URNAI-Tools/urnai/utils/vizdoomwads/health_gathering.wad",
91-
"render" : true,
92-
"doommap" : null
93-
}
94-
},
95-
"action-wrapper" : {
96-
"class" : "VizdoomHealthGatheringWrapper",
97-
"params" : {}
98-
},
99-
"state_builder" : {
100-
"class" : "VizDoomHealthGatheringState",
101-
"params" : {
102-
"screen_width" : 160,
103-
"screen_height" : 120
104-
}
105-
},
106-
"model" : {
107-
"class" : "DQNKerasMem",
108-
"params" : {
109-
"learning_rate" : 0.005,
110-
"gamma" : 0.9,
111-
"use_memory" : false,
112-
"per_episode_epsilon_decay" : true,
113-
"build_model" : [
114-
{
115-
"type": "conv",
116-
"filters": 32,
117-
"filter_shape": [3, 3],
118-
"padding": "same",
119-
"name": "default0",
120-
"input_shape": [120, 160, 1],
121-
"max_pooling_pool_size_shape": [2, 2]
122-
},
123-
{
124-
"type": "conv",
125-
"filters": 32,
126-
"filter_shape": [3, 3],
127-
"padding": "same",
128-
"name": "default1",
129-
"input_shape": null,
130-
"max_pooling_pool_size_shape": [2, 2]
131-
},
132-
{
133-
"type": "fullyconn",
134-
"nodes": 256,
135-
"name": "default2"
136-
},
137-
{
138-
"type": "fullyconn",
139-
"nodes": 50,
140-
"name": "default3"
141-
},
142-
{
143-
"type": "output",
144-
"length": 3
145-
}
146-
]
147-
}
148-
},
149-
"reward" : {
150-
"class" : "VizDoomHealthGatheringReward",
151-
"params" : {}
62+
"method" : "cumulative"
63+
}
15264
},
15365
"agent" : {
15466
"class" : "GenericAgent",
155-
"params" : {}
67+
"params" : {}
15668
},
15769
"trainer" : {
15870
"class" : "Trainer",

0 commit comments

Comments
 (0)