Class QLearningAgent<S,A>

java.lang.Object
org.episteme.natural.computing.ai.rl.QLearningAgent<S,A>
Type Parameters:
S - The type of the state (must properly implement equals/hashCode).
A - The type of the action.

public class QLearningAgent<S,A> extends Object
A generic Q-Learning agent implementation. Learns a policy mapping states to actions to maximize cumulative reward.
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Constructor Details

    • QLearningAgent

      public QLearningAgent(List<A> possibleActions)
  • Method Details

    • chooseAction

      public A chooseAction(S state)
      Chooses an action based on the current state using an epsilon-greedy policy.
      Parameters:
      state - The current state.
      Returns:
      The chosen action.
    • learn

      public void learn(S state, A action, double reward, S nextState)
      Updates the Q-value for a state-action pair based on the received reward and next state. Q(s, a) = Q(s, a) + alpha * (reward + gamma * max(Q(s', a')) - Q(s, a))
      Parameters:
      state - The previous state.
      action - The action taken.
      reward - The reward received.
      nextState - The new state arrived at.
    • learn

      public void learn(S state, A action, Real reward, S nextState)
    • getBestAction

      public A getBestAction(S state)
      Returns the best action for a given state (exploitation).
    • getMaxQ

      public double getMaxQ(S state)
      Gets the maximum Q-value for a given state.
    • setLearningRate

      public void setLearningRate(double alpha)
    • setDiscountFactor

      public void setDiscountFactor(double gamma)
    • setExplorationRate

      public void setExplorationRate(double epsilon)