Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DenSumy committed Dec 2, 2019
1 parent 22c1dcd commit 661c582
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 44 deletions.
35 changes: 0 additions & 35 deletions a2c_discrete.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
import tr_helpers
import wrappers
import tensorflow as tf
import numpy as np
import collections
import time
from collections import deque, OrderedDict
from tensorboardX import SummaryWriter
from tensorflow_utils import TensorFlowVariables
import gym
import vecenv
from tf_moving_mean_std import MovingMeanStd


class RewardsMap:
def __init__(self, num_actors, width = 40):
self.width = width
self.height = width
self.num_actors = num_actors
self.array = np.zeros((num_actors, width, width))
self.pos = np.zeros((num_actors, 2))

def update(self, v, dones):
v_scale = 8.0 / 10.0
pos_shift = self.width // 2
self.pos = self.pos + v * v_scale

coords = self.pos.astype(np.int32) + pos_shift
coords = np.clip(coords, 0, self.width-1)
rewards = np.zeros(self.num_actors)
print(self.pos[0])
print(coords[0])
print(v[0])
for i in range(self.num_actors):
if (self.array[i, coords[i, 0], coords[i, 1]]) == 0:
self.array[i, coords[i, 0], coords[i, 1]] = 1
else:
rewards[i] = -1.0
self.array[i, :] = self.array[i, :] * (1.0 - dones[i])
self.pos[i, :] = self.pos[i, :] * (1.0 - dones[i])

#self.array = self.array * (1.0 - dones)
#self.pos = self.pos * (1.0 - dones)
return rewards



def swap_and_flatten01(arr):
"""
swap and then flatten axes 0 and 1
Expand Down
4 changes: 3 additions & 1 deletion download_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import zipfile


def download_file_from_google_drive(id, destination):
URL = "https://docs.google.com/uc?export=download"

Expand Down Expand Up @@ -35,10 +36,11 @@ def save_response_content(response, destination):
file_id = '1mVGfN0Xoj--26_NIPgXS48ub-Rr89GIw'
destination = os.path.dirname(os.path.abspath(__file__)) + '/networks.zip'
extract_destination = os.path.dirname(os.path.abspath(__file__)) + '/nn'
print('Starting networks download')
if os.path.isfile(destination):
print('Networks were already downloaded')
else:
download_file_from_google_drive(file_id, destination)
print('Networks were succesfully downloaded.')
with zipfile.ZipFile(destination, 'r') as zip_ref:
zip_ref.extractall(extract_destination)
zip_ref.extractall(extract_destination)
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ tensorboard==1.14.0
tensorboardX==1.6
tensorflow-gpu==1.14.0
gast==0.2.2
Pillow>=4.2.1,<=5.4.1
protobuf>=3.6,<3.7
grpcio>=1.11.0,<1.12.0
pyyaml>=5.1
jsonpickle>=1.2



12 changes: 4 additions & 8 deletions test_a2c.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
"source": [
"import env_configurations\n",
"import games_configurations\n",
"env_name = 'AnimalAIRay'#'PongNoFrameskip-v4' #'MountainCar-v0' #'SuperMarioBros-v1'# 'PongNoFrameskip-v4' #SuperMarioBros-v1'\n",
"#env_name = 'CartPole-v1'#'CartPole-v1' #'RoboschoolAnt-v1' #'CarRacing-v0' #'LunarLander-v2' #'Acrobot-v1' #\n",
"\n",
"env_name = 'AnimalAIRay'\n",
"obs_space, action_space = env_configurations.get_obs_and_action_spaces('AnimalAI')\n",
"config = games_configurations.animal_ai_ray_times3\n",
"\n",
Expand Down Expand Up @@ -56141,7 +56139,7 @@
"metadata": {},
"outputs": [],
"source": [
"agent.save('nn/last84_10_6')\n",
"agent.save('nn/last84_10_7')\n",
"ray.shutdown()"
]
},
Expand All @@ -56167,9 +56165,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gym.envs.registry.all()"
]
"source": []
},
{
"cell_type": "code",
Expand Down Expand Up @@ -56207,4 +56203,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}

0 comments on commit 661c582

Please sign in to comment.