- improved
git-svn-id: http://moon:8086/svn/projects/RL-lab@344 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -32,7 +32,8 @@ def to_this_door(door_last_room):
|
||||
q, r = divmod(door_last_room + 2, 4)
|
||||
return r
|
||||
|
||||
def choose_door(Pn):
|
||||
def choose_door(P):
|
||||
Pn = P / np.sum(P)
|
||||
Pnorm = np.cumsum(Pn)
|
||||
size = len(Pn)
|
||||
Z = np.random.uniform(0,1)
|
||||
@@ -60,7 +61,7 @@ def forget(forgetting_factor):
|
||||
pos = (x,y)
|
||||
P_door[pos,:] *= forgetting_factor
|
||||
|
||||
def run(pos, N_trials, learning_rate, penalty_factor=0.99, forgetting_factor=0.999):
|
||||
def run(pos, N_trials, learning_rate, penalty_factor=0.99, forgetting_factor=0.99):
|
||||
lab_visited = np.zeros((lab_size_x, lab_size_y))
|
||||
moves_needed = 0
|
||||
door_last = -1
|
||||
@@ -71,12 +72,10 @@ def run(pos, N_trials, learning_rate, penalty_factor=0.99, forgetting_factor=0.9
|
||||
|
||||
# forget(forgetting_factor)
|
||||
|
||||
Pn = P_door[pos]/np.sum(P_door[pos])
|
||||
|
||||
P_door[pos,:] *= forgetting_factor
|
||||
while True:
|
||||
fail = False
|
||||
door = choose_door(Pn)
|
||||
door = choose_door(P_door[pos])
|
||||
if door_last >= 0:
|
||||
this_door = to_this_door(door_last)
|
||||
if this_door == door:
|
||||
@@ -124,7 +123,6 @@ print('Visited map after {} moves:'.format(moves_needed))
|
||||
print(lab_visited)
|
||||
print ('P_door after {} moves:'.format(moves_needed))
|
||||
|
||||
P = normalize(P_door)
|
||||
for i in range(0, num_doors_per_room):
|
||||
print (P[:,:,i])
|
||||
print (P_door[:,:,i])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user