Skip to content

Commit

Permalink
more efficient; remove pyc
Browse files Browse the repository at this point in the history
  • Loading branch information
yfzhang committed Nov 22, 2018
1 parent 6233565 commit 1edb5b7
Show file tree
Hide file tree
Showing 18 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def load(grid_size):
sns.heatmap(r, cmap='viridis')
plt.show()
r_vector = r.reshape(n_states) # convert 2D reward matrix to a 1D vector
value_vector = model.find_optimal_value(r_vector, 0.005)
value_vector = model.find_optimal_value(r_vector, 0.1)
policy = model.find_stochastic_policy(value_vector, r_vector)
past_traj_len = past_traj.shape[0]
svf_vector = model.find_svf_demo(policy, past_traj_len)
Expand Down
Binary file removed loader/__init__.pyc
Binary file not shown.
Binary file removed loader/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed loader/__pycache__/offroad_loader.cpython-36.pyc
Binary file not shown.
Binary file removed loader/__pycache__/util.cpython-36.pyc
Binary file not shown.
Binary file removed loader/offroad_loader.pyc
Binary file not shown.
Binary file removed mdp/__init__.pyc
Binary file not shown.
Binary file removed mdp/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed mdp/__pycache__/offroad_grid.cpython-36.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions mdp/offroad_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def find_optimal_value(self, reward, thresh=0.005):
:param reward: numpy array (n_states)
:return:
"""
start = time.clock()
value = np.zeros(self.n_states)
step = 0
import warnings
Expand All @@ -239,8 +240,7 @@ def find_optimal_value(self, reward, thresh=0.005):

for s in range(self.n_states):
next_s_list = [self.transit_table[s, a] for a in range(self.n_actions)]
r_list = [reward[s] + self.discount * value[ss] for ss in next_s_list]
new_v = max(r_list)
new_v = reward[s] + max([self.discount * value[ss] for ss in next_s_list])

# find the largest update through out the whole sweep over all states
max_update = max(max_update, abs(value[s] - new_v))
Expand All @@ -250,7 +250,7 @@ def find_optimal_value(self, reward, thresh=0.005):
warnings.warn('value iteration does not converge', RuntimeWarning)
break

print('find_optimal_value. iteration {}, last update {}'.format(step, max_update))
print('find_optimal_value. iter {}, last update {:.2f}, took {:.2f}'.format(step, max_update, time.clock()-start))
return value

def select_action(self, s, value, epsilon):
Expand Down
Binary file removed mdp/offroad_grid.pyc
Binary file not shown.
Binary file removed network/__init__.pyc
Binary file not shown.
Binary file removed network/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed network/__pycache__/hybrid_dilated.cpython-36.pyc
Binary file not shown.
Binary file removed network/__pycache__/hybrid_fcn.cpython-36.pyc
Binary file not shown.
Binary file removed network/__pycache__/simple_fcn.cpython-36.pyc
Binary file not shown.
Binary file removed network/__pycache__/simple_nn.cpython-36.pyc
Binary file not shown.
Binary file removed network/hybrid_fcn.pyc
Binary file not shown.

0 comments on commit 1edb5b7

Please sign in to comment.