Skip to content

Commit

Permalink
restored softmax due to errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cipri-tom committed Jan 27, 2017
1 parent 7aace04 commit 760ab51
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions scripts/starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
import numpy as np
import mountaincar

# def softmax(q, tau):
# """ Numerically stable softmax probabilities with temperature tau"""
# # kudos to http://stackoverflow.com/q/3985619/29863846#29863846
# # q = q / tau
# max_q = max(0.0, np.max(q))
# rebased_q = q - max_q
# return np.exp(rebased_q - np.logaddexp(-max_q, np.logaddexp.reduce(rebased_q)))

def softmax(x, tau):
""" Numerically stable softmax probabilities with temperature tau"""
# kudos to http://stackoverflow.com/q/3985619/29863846#29863846
max_x = max(0.0, np.max(x/tau))
rebased_x = x/tau - max_x
return np.exp(rebased_x - np.logaddexp(-max_x, np.logaddexp.reduce(rebased_x)))
""" Returns softmax probabilities with temperature tau"""
e_x = np.exp(x / tau)
return e_x / e_x.sum()

class Agent():
"""A Sarsa(lambda) agent which learns its way out """
Expand Down

0 comments on commit 760ab51

Please sign in to comment.