<s> import theano . tensor as TT <EOL> import numpy as np <EOL> import theano <EOL> from rllab . distributions . categorical import Categorical <EOL> from rllab . distributions . base import Distribution <EOL> TINY = <NUM_LIT> <EOL> class RecurrentCategorical ( Distribution ) : <EOL> def __init__ ( self ) : <EOL> self . _cat = Categorical ( ) <EOL> def kl_sym ( self , old_dist_info_vars , new_dist_info_vars ) : <EOL> """<STR_LIT>""" <EOL> old_prob_var = old_dist_info_vars [ "<STR_LIT>" ] <EOL> new_prob_var = new_dist_info_vars [ "<STR_LIT>" ] <EOL> return TT . sum ( <EOL> old_prob_var * ( TT . log ( old_prob_var + TINY ) - TT . log ( new_prob_var + TINY ) ) , <EOL> axis = <NUM_LIT:2> <EOL> ) <EOL> def kl ( self , old_dist_info , new_dist_info ) : <EOL> """<STR_LIT>""" <EOL> old_prob = old_dist_info [ "<STR_LIT>" ] <EOL> new_prob = new_dist_info [ "<STR_LIT>" ] <EOL> return np . sum ( <EOL> old_prob * ( np . log ( old_prob + TINY ) - np . log ( new_prob + TINY ) ) , <EOL> axis = <NUM_LIT:2> <EOL> ) <EOL> def likelihood_ratio_sym ( self , x_var , old_dist_info_vars , new_dist_info_vars ) : <EOL> old_prob_var = old_dist_info_vars [ "<STR_LIT>" ] <EOL> new_prob_var = new_dist_info_vars [ "<STR_LIT>" ] <EOL> a_dim = x_var . shape [ - <NUM_LIT:1> ] <EOL> flat_ratios = self . _cat . likelihood_ratio_sym ( <EOL> x_var . reshape ( ( - <NUM_LIT:1> , a_dim ) ) , <EOL> dict ( prob = old_prob_var . reshape ( ( - <NUM_LIT:1> , a_dim ) ) ) , <EOL> dict ( prob = new_prob_var . reshape ( ( - <NUM_LIT:1> , a_dim ) ) ) <EOL> ) <EOL> return flat_ratios . reshape ( old_prob_var . shape [ : <NUM_LIT:2> ] ) <EOL> def entropy ( self , dist_info ) : <EOL> probs = dist_info [ "<STR_LIT>" ] <EOL> return - np . sum ( probs * np . log ( probs + TINY ) , axis = <NUM_LIT:2> ) <EOL> def log_likelihood_sym ( self , xs , dist_info_vars ) : <EOL> probs = dist_info_vars [ "<STR_LIT>" ] <EOL> a_dim = probs . shape [ - <NUM_LIT:1> ] <EOL> flat_logli = self . _cat . log_likelihood_sym ( xs . reshape ( ( - <NUM_LIT:1> , a_dim ) ) , dict ( prob = probs . reshape ( ( - <NUM_LIT:1> , a_dim ) ) ) ) <EOL> return flat_logli . reshape ( probs . shape [ : <NUM_LIT:2> ] ) <EOL> def log_likelihood ( self , xs , dist_info ) : <EOL> probs = dist_info [ "<STR_LIT>" ] <EOL> a_dim = probs . shape [ - <NUM_LIT:1> ] <EOL> flat_logli = self . _cat . log_likelihood_sym ( xs . reshape ( ( - <NUM_LIT:1> , a_dim ) ) , dict ( prob = probs . reshape ( ( - <NUM_LIT:1> , a_dim ) ) ) ) <EOL> return flat_logli . reshape ( probs . shape [ : <NUM_LIT:2> ] ) <EOL> @ property <EOL> def dist_info_keys ( self ) : <EOL> return [ "<STR_LIT>" ] </s>
