QLearning class

Tabular Q-Learning (advanced)

This implementation keeps the simple, well-documented API from the original version but adds commonly used features that make it practical in experiments and tests:

  • decaying epsilon (exploration) with configurable schedule
  • optional decaying learning-rate (alpha) schedule
  • safe helpers (bestAction, maxQ, reset, clone)
  • serialization to/from Map/JSON

The class maintains backwards-compatible constructor arguments where possible. States and actions are integers and the Q-table is a List<List

Constructors

QLearning({required int nStates, required int nActions, double alpha = 0.1, double gamma = 0.99, double epsilon = 0.1, int? seed, double? epsilonMin, double? epsilonDecay, double? alphaMin, double? alphaDecay})

Properties

alpha ↔ double
getter/setter pair
alphaDecay → double?
final
alphaMin → double?
final
epsilon ↔ double
getter/setter pair
epsilonDecay → double?
final
epsilonMin → double?
final
gamma → double
final
hashCode → int
The hash code for this object.
no setterinherited
nActions → int
final
nStates → int
final
qTable ↔ List<List<double>>
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

bestAction(int state) → int
Returns the greedy (best) action for a given state.
chooseAction(int state) → int
Choose an action for state using epsilon-greedy. Ties are broken by first occurrence (stable determinism under a seed).
clone() → QLearning
Create a deep clone of this agent (useful for experiments).
maxQ(int state) → double
Maximum Q-value for a given state.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset({double defaultValue = 0.0}) → void
Reset Q-table (keeps schedules and hyperparameters).
toJson() → String
toMap() → Map<String, dynamic>
toString() → String
A string representation of this object.
inherited
update(int state, int action, double reward, int nextState) → void
Perform one Q-Learning update and advance internal schedules.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

fromJson(String s, {int? seed}) → QLearning
fromMap(Map<String, dynamic> m, {int? seed}) → QLearning