class mlpy.agents.modules.AgentModuleFactory[source]

Bases: object

The agent module factory.

An instance of an agent module can be created by passing the agent module type. The module type is the name of the module. The set of agent modules can be extended by inheriting from IAgentModule. However, for the agent module to be registered, the custom module must be imported by the time the agent module factory is called.


The agent module factory is being called by the Agent during initialization to create the agents controller.


>>> from mlpy.agents.modules import AgentModuleFactory
>>> AgentModuleFactory.create('learningmodule', 'qlearner', max_steps=10)

This creates a LearningModule instance performing q-learning with max_steps set to 10.

>>> def get_reward(state, action):
...     return 1.0
>>> AgentModuleFactory().create('learningmodule', 'qlearner', get_reward,
...                             max_steps=10)

This creates a q-learning learning module instance passing a reward callback function and sets max_steps to 10.

>>> from mlpy.mdp.discrete import DiscreteModel
>>> from mlpy.planners.discrete import ValueIteration
>>> planner = ValueIteration(DiscreteModel(['out', 'in', 'kick']))
>>> AgentModuleFactory().create('learningmodule', 'rldtlearner', None, planner,
...                             max_steps=10)

This creates a learning module using the RLDTLearner. The parameters for the learner are appended to the end of the argument list. Notice that since positional arguments are used to pass the planner, the reward callback must be accounted for by setting it to None.

Alternatively non-positional arguments can be used:

>>> AgentModuleFactory().create('learningmodule', 'rldtlearner', planner=planner,
...                             max_steps=10)


create(_type, *args, **kwargs) Create an agent module of the given type.