Package ai.djl.modality.rl.agent
Class QAgent
- java.lang.Object
-
- ai.djl.modality.rl.agent.QAgent
-
- All Implemented Interfaces:
RlAgent
public class QAgent extends java.lang.Object implements RlAgent
AnRlAgent
that implements Q or Deep-Q Learning.Deep-Q Learning estimates the total reward that will be given until the environment ends in a particular state after taking a particular action. Then, it is trained by ensuring that the prediction before taking the action match what would be predicted after taking the action. More information can be found in the paper.
It is one of the earliest successful techniques for reinforcement learning with Deep learning. It is also a good introduction to the field. However, many better techniques are commonly used now.
-
-
Constructor Summary
Constructors Constructor Description QAgent(Trainer trainer, float rewardDiscount)
Constructs aQAgent
.QAgent(Trainer trainer, float rewardDiscount, Batchifier batchifier)
Constructs aQAgent
with a customBatchifier
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NDList
chooseAction(RlEnv env, boolean training)
Chooses the next action to take within theRlEnv
.void
trainBatch(RlEnv.Step[] batchSteps)
Trains thisRlAgent
on a batch ofRlEnv.Step
s.
-
-
-
Constructor Detail
-
QAgent
public QAgent(Trainer trainer, float rewardDiscount)
Constructs aQAgent
.It uses the
StackBatchifier
as the default batchifier.- Parameters:
trainer
- the trainer for the model to learnrewardDiscount
- the reward discount to apply to rewards from future states
-
QAgent
public QAgent(Trainer trainer, float rewardDiscount, Batchifier batchifier)
Constructs aQAgent
with a customBatchifier
.- Parameters:
trainer
- the trainer for the model to learnrewardDiscount
- the reward discount to apply to rewards from future statesbatchifier
- the batchifier to join inputs with
-
-
Method Detail
-
chooseAction
public NDList chooseAction(RlEnv env, boolean training)
Chooses the next action to take within theRlEnv
.- Specified by:
chooseAction
in interfaceRlAgent
- Parameters:
env
- the current environmenttraining
- true if the agent is currently traning- Returns:
- the action to take
-
trainBatch
public void trainBatch(RlEnv.Step[] batchSteps)
Trains thisRlAgent
on a batch ofRlEnv.Step
s.- Specified by:
trainBatch
in interfaceRlAgent
- Parameters:
batchSteps
- the steps to train on
-
-