rlang.grounding package

rlang.grounding.groundings module

Module containing all RLang groundings.

class rlang.grounding.groundings.Grounding[source]

Bases: object

Parent class for all groundings.

For all intents and purposes, this is an abstract class.

__init__(name=None)[source]
class rlang.grounding.groundings.GroundingFunction[source]

Bases: Grounding

Parent class for groundings that are callable. In general, only the children of this class should be used.

All GroundingFunctions have a specified domain and codomain. They are invoked using keyword arguments that correspond to their domain:

from rlang import Domain

def can_move_fun(*args, **kwargs):
    return not kwargs['state'] in pit_states and kwargs['action'] in move_actions

can_move = GroundingFunction(domain=Domain.STATE_ACTION, codomain=Domain.BOOLEAN, function=can_move_fun)
can_move(state=0, action=1)
>> True
__init__(domain, codomain, function, name=None)[source]

Initialize a GroundingFunction.

Parameters
  • domain (Union[str, Domain]) – Domain of the function.

  • codomain (Union[str, Domain]) – Codomain of the function.

  • function (Callable) – the function.

  • name (Optional[str]) – the name of the Grounding.

class rlang.grounding.groundings.PrimitiveGrounding[source]

Bases: GroundingFunction

GroundingFunction which requires no arguments, i.e. domain=Domain.ANY

__init__(codomain, value, name=None)[source]

Initialize a GroundingFunction.

Parameters
  • domain – Domain of the function.

  • codomain (Domain) – Codomain of the function.

  • function – the function.

  • name (Optional[str]) – the name of the Grounding.

  • value (Any) –

class rlang.grounding.groundings.ConstantGrounding[source]

Bases: PrimitiveGrounding

GroundingFunction for defined RLang Constants

class rlang.grounding.groundings.ParameterizedActionExecution[source]

Bases: GroundingFunction

__init__(parameterized_action, arguments)[source]

Initialize a GroundingFunction.

Parameters
  • domain – Domain of the function.

  • codomain – Codomain of the function.

  • function – the function.

  • name – the name of the Grounding.

  • arguments (List[GroundingFunction]) –

class rlang.grounding.groundings.ActionReference[source]

Bases: GroundingFunction

Represents a reference to a specified action.

__init__(action, name=None)[source]
Parameters
  • action (Any) – the action.

  • name (optional) – name of the action.

class rlang.grounding.groundings.IdentityGrounding[source]

Bases: GroundingFunction

Grounding for representing S, A, and S’.

__init__(domain)[source]

Initialize a new IdentityGrounding.

Parameters

domain (Union[str, Domain]) –

class rlang.grounding.groundings.MDPClassGrounding[source]

Bases: GroundingFunction

__init__(cls)[source]

Initialize a GroundingFunction.

Parameters
  • domain – Domain of the function.

  • codomain – Codomain of the function.

  • function – the function.

  • name – the name of the Grounding.

class rlang.grounding.groundings.MDPObjectGrounding[source]

Bases: GroundingFunction

For representing objects, which may have properties that are functions of state.

__init__(obj, name=None, domain=Domain.ANY)[source]

Initialize an abstract object grounding.

Parameters
  • obj (MDPObject) – the MDPObject.

  • name (optional) – the name of the object.

class rlang.grounding.groundings.MDPObjectAttributeGrounding[source]

Bases: GroundingFunction

For referencing attributes of abstract objects that are not in the state.

__init__(grounding, attribute_chain)[source]

Initialize a grounding for referencing abstract object attributes.

Parameters
  • grounding (GroundingFunction) – the MDPObjectGrounding whose attribute you are referencing.

  • attribute_chain (List) – a list of attribute/sub-attributes (e.g. [“color”, “red_value”])

class rlang.grounding.groundings.PredicateEvaluation[source]

Bases: GroundingFunction

__init__(predicate, arguments)[source]

Initialize a GroundingFunction.

Parameters
  • domain – Domain of the function.

  • codomain – Codomain of the function.

  • function – the function.

  • name – the name of the Grounding.

  • arguments (List[GroundingFunction]) –

class rlang.grounding.groundings.StateObjectAttributeGrounding[source]

Bases: GroundingFunction

For referencing attributes of objects in the state when the state is object-oriented.

__init__(attribute_chain, domain=Domain.STATE)[source]

Initialize a grounding for referencing object attributes, when those objects are in the state.

Parameters
  • attribute_chain (List) – a list of attribute/sub-attributes (e.g. [“ball”, “color”, “red_value”])

  • domain (Union[str, Domain]) – either “state” or “next_state”.

class rlang.grounding.groundings.Factor[source]

Bases: GroundingFunction

Represents a factor of the state space.

__init__(state_indexer, name=None, domain=Domain.STATE)[source]
Parameters
  • state_indexer (Any) – the indices or slice of the state space.

  • name (optional) – the name of the grounding.

  • domain (optional [str]) – the domain of the Factor.

class rlang.grounding.groundings.Feature[source]

Bases: GroundingFunction

Represents a feature of the state space.

Can represent any function of the state space.

__init__(function, name=None, domain=Domain.STATE)[source]
Parameters
  • function (Callable) – a function of state.

  • name (optional) – the name of the grounding.

  • domain (optional [str]) – the domain of the Feature.

class rlang.grounding.groundings.MarkovFeature[source]

Bases: GroundingFunction

Represents a Grounding that is a function of (state, action, next_state)

__init__(function, name)[source]
Parameters
  • function (Callable) – a function of (state, action, next_state)

  • name (str) –

class rlang.grounding.groundings.Proposition[source]

Bases: GroundingFunction

Represents a function which has a truth value.

A Proposition is a feature with a codomain restricted to True or False.

__init__(function, name=None, domain=Domain.STATE)[source]
Parameters
  • function (Callable) – a function of state that evaluates to a bool.

  • name (optional) – the name of the grounding.

  • domain (optional [str]) – the domain of the Proposition.

class rlang.grounding.groundings.Goal[source]

Bases: Proposition

class rlang.grounding.groundings.ValueFunction[source]

Bases: GroundingFunction

Represents a value function.

__init__(function)[source]

Initialize a GroundingFunction.

Parameters
  • domain – Domain of the function.

  • codomain – Codomain of the function.

  • function (Callable) – the function.

  • name – the name of the Grounding.

class rlang.grounding.groundings.ProbabilisticFunction[source]

Bases: GroundingFunction

Represents a function that provides stochastic output.

__init__(probability=1.0, *args, **kwargs)[source]

Initialize a GroundingFunction.

Parameters
  • domain – Domain of the function.

  • codomain – Codomain of the function.

  • function – the function.

  • name – the name of the Grounding.

  • probability (float) –

class rlang.grounding.groundings.ProbabilityDistribution[source]

Bases: MutableMapping

__init__(distribution=None)[source]
class rlang.grounding.groundings.ActionDistribution[source]

Bases: ProbabilityDistribution

Represents a distribution of possible next actions, options, or policies

Parameters

distribution – a dictionary of the form {Action/Option/Policy: probability,}

class rlang.grounding.groundings.StateDistribution[source]

Bases: ProbabilityDistribution

__init__(distribution=None)[source]
class rlang.grounding.groundings.RewardDistribution[source]

Bases: ProbabilityDistribution

__init__(distribution=None)[source]
class rlang.grounding.groundings.GroundingDistribution[source]

Bases: ProbabilityDistribution

__init__(grounding, distribution=None, complete=False)[source]
Parameters

grounding (Grounding) –

class rlang.grounding.groundings.Policy[source]

Bases: ProbabilisticFunction

Represents a closed-loop policy function

__init__(function, domain=Domain.STATE, *args, **kwargs)[source]
Parameters
  • function (Callable) – a function from states to action distributions.

  • domain (Domain) –

class rlang.grounding.groundings.Plan[source]

Bases: Grounding

Represents an open-loop policy

__init__(function=None, name=None)[source]
Parameters
  • function (Optional[Callable]) –

  • name (Optional[str]) –

class rlang.grounding.groundings.IteratedPlan[source]

Bases: Plan

One kind of plan implementation

__init__(plan_steps, name=None)[source]
Parameters

name (Optional[str]) –

class rlang.grounding.groundings.PlanExecution[source]

Bases: GroundingFunction

__init__(plan, arguments=None)[source]

Initialize a GroundingFunction.

Parameters
  • domain – Domain of the function.

  • codomain – Codomain of the function.

  • function – the function.

  • name – the name of the Grounding.

  • arguments (Optional[List[GroundingFunction]]) –

class rlang.grounding.groundings.OptionTermination[source]

Bases: object

class rlang.grounding.groundings.Option[source]

Bases: Grounding

Grounding object for an option.

__init__(initiation, policy, termination, name=None)[source]
Parameters
  • initiation (Proposition) – A Proposition capturing the initiation set of the option.

  • policy (Policy) – A PolicyOld capturing the policy of the option.

  • termination (Proposition) – A Proposition capturing the termination set of the option.

  • name (optional) – the name of the grounding.

can_initiate(*args, **kwargs)[source]

Determines whether the option can be executed in a given state.

Parameters

state – A State object.

Returns

True iff the option can be executed in the given state.

Return type

bool

class rlang.grounding.groundings.TransitionFunction[source]

Bases: ProbabilisticFunction

Represents a transition function.

__init__(function=None, domain=Domain.STATE_ACTION, *args, **kwargs)[source]

Initialize a GroundingFunction.

Parameters
  • domain (Domain) – Domain of the function.

  • codomain – Codomain of the function.

  • function (Optional[Callable]) – the function.

  • name – the name of the Grounding.

class rlang.grounding.groundings.RewardFunction[source]

Bases: ProbabilisticFunction

Represents function of expected reward.

__init__(function=None, domain=Domain.ANY, *args, **kwargs)[source]

Initialize a GroundingFunction.

Parameters
  • domain (Domain) – Domain of the function.

  • codomain – Codomain of the function.

  • function (Optional[Callable]) – the function.

  • name – the name of the Grounding.

class rlang.grounding.groundings.Prediction[source]

Bases: ProbabilisticFunction

GroundingFunction for an RLang Prediction object.

Used to express the predicted value of another RLang object. Limited to GroundingFunctions with a domain of (S) or (S, A).

__init__(grounding, function=None, domain=Domain.STATE_ACTION, complete=False, *args, **kwargs)[source]
Parameters
  • grounding (Grounding) – the grounding whom’s value we are predicting

  • function (Callable, optional) – a function that predicts the value of grounding; can use a GroundingFunction

  • domain (Domain) –

classmethod from_grounding_distribution(grounding, function, complete=False)[source]
Parameters
class rlang.grounding.groundings.Effect[source]

Bases: Grounding

GroundingFunction for an RLang Effect object.

Contains an optional RewardFunction, TransitionFunction, and list of Predictions.

__init__(reward_function=None, transition_function=None, predictions=None, name=None, probability=1.0)[source]
Parameters
  • reward_function (Optional[RewardFunction]) – a RewardFunction

  • transition_function (Optional[TransitionFunction]) – a TransitionFunction

  • predictions (Optional[List[Prediction]]) – a list of Predictions

  • name (Optional[str]) – name of the Effect

  • probability (Optional[float]) – probability of this effect occurring; default: 1

Subpackages