<commit_before>import numpy as np
from rl.agent.base_agent import Agent
from rl.util import logger, log_self
from keras.models import Sequential
from keras.layers.core import Dense


class DQN(Agent):

    '''
    The base class of DQNs, with the core methods
    The simplest deep Q network,
    with epsilon-greedy method and
    Bellman equation for value, using neural net.
    '''

    def __init__(self, env_spec,
                 train_per_n_new_exp=1,
                 gamma=0.95, lr=0.1,
                 epi_change_lr=None,
                 batch_size=16, n_epoch=5, hidden_layers_shape=[4],
                 hidden_layers_activation='sigmoid',
                 output_layer_activation='linear',
                 **kwargs):  # absorb generic param without breaking
        super(DQN, self).__init__(env_spec)

        self.train_per_n_new_exp = train_per_n_new_exp
        self.gamma = gamma
        self.lr = lr
        self.epi_change_lr = epi_change_lr
        self.batch_size = batch_size
        self.n_epoch = 1
        self.final_n_epoch = n_epoch
        self.hidden_layers = hidden_layers_shape
        self.hidden_layers_activation = hidden_layers_activation
        self.output_layer_activation = output_layer_activation
        self.clip_val = 10000
        log_self(self)
        self.build_model()

    def build_hidden_layers(self, model):
        '''
        build the hidden layers into model using parameter self.hidden_layers
        '''
        model.add(Dense(self.hidden_layers[0],
                        input_shape=(self.env_spec['state_dim'],),
                        activation=self.hidden_layers_activation,
                        init='lecun_uniform'))

        # inner hidden layer: no specification of input shape
        if (len(self.hidden_layers) > 1):
            for i in range(1, len(self.hidden_layers)):
                model.add(Dense(self.hidden_layers[i],
                                init='lecun_uniform',
                                activation=self.hidden_layers_activation))

        return model

    def build_model(self):
        model = Sequential()
        self.build_hidden_layers(model)
        model.add(Dense(self.env_spec['action_dim'],
                        init='lecun_uniform',
                        activation=self.output_layer_activation))
        logger.info("Model summary")<commit_msg>move dqn param array defaulting to body<commit_after>import numpy as np
from rl.agent.base_agent import Agent
from rl.util import logger, log_self
from keras.models import Sequential
from keras.layers.core import Dense


class DQN(Agent):

    '''
    The base class of DQNs, with the core methods
    The simplest deep Q network,
    with epsilon-greedy method and
    Bellman equation for value, using neural net.
    '''

    def __init__(self, env_spec,
                 train_per_n_new_exp=1,
                 gamma=0.95, lr=0.1,
                 epi_change_lr=None,
                 batch_size=16, n_epoch=5, hidden_layers_shape=None,
                 hidden_layers_activation='sigmoid',
                 output_layer_activation='linear',
                 **kwargs):  # absorb generic param without breaking
        super(DQN, self).__init__(env_spec)

        self.train_per_n_new_exp = train_per_n_new_exp
        self.gamma = gamma
        self.lr = lr
        self.epi_change_lr = epi_change_lr
        self.batch_size = batch_size
        self.n_epoch = 1
        self.final_n_epoch = n_epoch
        self.hidden_layers = hidden_layers_shape or [4]
        self.hidden_layers_activation = hidden_layers_activation
        self.output_layer_activation = output_layer_activation
        self.clip_val = 10000
        log_self(self)
        self.build_model()

    def build_hidden_layers(self, model):
        '''
        build the hidden layers into model using parameter self.hidden_layers
        '''
        model.add(Dense(self.hidden_layers[0],
                        input_shape=(self.env_spec['state_dim'],),
                        activation=self.hidden_layers_activation,
                        init='lecun_uniform'))

        # inner hidden layer: no specification of input shape
        if (len(self.hidden_layers) > 1):
            for i in range(1, len(self.hidden_layers)):
                model.add(Dense(self.hidden_layers[i],
                                init='lecun_uniform',
                                activation=self.hidden_layers_activation))

        return model

    def build_model(self):
        model = Sequential()
        self.build_hidden_layers(model)
        model.add(Dense(self.env_spec['action_dim'],
                        init='lecun_uniform',
                        activation=self.output_layer_activation))
        logger.info("Model summary")
{'fraction_non_alphanumeric': 0.07914572864321608, 'fraction_numerical': 0.007956448911222781, 'mean_word_length': 2.07598197037991, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1252010', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1316, 'n_words': 285}