KerasRL 2 not exploring

37 Views Asked by At

Hi I am a begginer in ai and I am using keras-rl for reinforcment learning. To start I decided to make a very simple ai where all the ai has to do is choose action 2. However, the ai keeps choosing 0 even though it is getting a -200 reward.

import random
from keras.models import Sequential
from keras.layers import Dense, Flatten
from keras.optimizers import Adam
from rl.agents import DQNAgent
from rl.policy import EpsGreedyQPolicy
from rl.memory import SequentialMemory
from rl.callbacks import ModelIntervalCheckpoint


actions = 2
shape=[2]
shape=[1]+shape
print(shape)
model = Sequential()
model.add(Flatten(input_shape=shape))
model.add(Dense(2, activation="relu"))

model.add(Dense(actions, activation="linear"))

agent = DQNAgent(
    model=model,
    memory=SequentialMemory(limit=50000, window_length=1),
    policy=EpsGreedyQPolicy(),
    nb_actions=actions,
    nb_steps_warmup=20,
    target_model_update=0.01,
)
agent.compile(Adam(lr=0.01), metrics=["mae"])


state=[0,1]
while 1:
        state=[0,1]
        
        action = agent.forward(state)
        reward=-200
        if action==1:
            reward=1
        print(reward,action)
        agent.backward(reward,state)




I tried adjusting the learning rate but nothing changed. I suspect it is not workign because I am using backwards and forwards instead of fit.

0

There are 0 best solutions below