timor.task.CostFunctions
Attributes
Classes
A cost function composed of different atomic cost functions |
|
A base class for cost functions that are evaluated on task solutions. |
|
Increases with trajectory length needed to solve a task |
|
Increases with the torques used by a solution |
|
Cost of alpha for every goal fulfilled in the task. (negative weight --> reward) |
|
Cost proportional to the fraction of fulfilled goals. |
|
Calculate the energy used in the link side movement EXCLUDING joint friction and rotor inertia. |
|
Calculate the energy provided by the motors to move the robot along the solution trajectory. |
|
Punishes a higher number of actuated joints |
|
Increases with the joint space distance traversed by the solution |
|
Punishes higher weight of the robot |
Module Contents
- class timor.task.CostFunctions.ComposedCost(*args, weight=default_weight)

A cost function composed of different atomic cost functions
A composed cost is a container with multiple cost functions, providing a unified interface.
- Parameters:
weight (float)
- __add__(other)
The sum of two costs
- __eq__(other)
Check if two composed cost functions are the same, i.e., have the same descriptor.
- Parameters:
other (CostFunctionBase)
- Return type:
- __mul__(other)
Multiply all internal cost functions by the given number.
- __neg__()
Negate all internal cost functions.
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Divide all internal cost functions by the given number.
- _evaluate(solution)
The evaluation of the composed cost function is the sum of all internal cost functions
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- _internal = []
- default_weight = 1.0
- descriptor()
Creates a string describing this cost function. Uses alphanumeric sorting to ensure deterministic name.
- Return type:
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.CostFunctionBase(weight=default_weight)

A base class for cost functions that are evaluated on task solutions.
By default, cost functions return positive values - if they describe something positive (e.g. number of goals fulfilled), the weight must be chosen negative.
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- abstractmethod _evaluate(solution)
Interface to define class-level evaluate functions
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.CycleTime(weight=default_weight)

Increases with trajectory length needed to solve a task
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- _evaluate(solution)
The total time needed by the solution
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.Effort(weight=default_weight)

Increases with the torques used by a solution
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- _evaluate(solution)
The integral of effort over time in the solution
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.GoalsFulfilled(weight=default_weight)

Cost of alpha for every goal fulfilled in the task. (negative weight –> reward)
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- _evaluate(solution)
The number of goals fulfilled
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.GoalsFulfilledFraction(weight=default_weight)

Cost proportional to the fraction of fulfilled goals.
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- _evaluate(solution)
The fraction of goals fulfilled
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.LinkSideMechanicalEnergy(weight=default_weight)

Calculate the energy used in the link side movement EXCLUDING joint friction and rotor inertia.
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- _evaluate(solution)
The integral of mechanical power (excl. joint friction and inertia) over the solution times.
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.MechanicalEnergy(weight=default_weight)

Calculate the energy provided by the motors to move the robot along the solution trajectory.
Includes the energy to overcome joint friction, rotor inertia and all link inertias.
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- _evaluate(solution)
The integral of mechanical power over time in the solution.
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.NumJoints(weight=default_weight)

Punishes a higher number of actuated joints
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- _evaluate(solution)
The number of actuated joints in the solution robot
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.QDist(weight=default_weight)

Increases with the joint space distance traversed by the solution
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- _evaluate(solution)
The integral over time for all joint parameters (mixes up radian and meters!)
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- class timor.task.CostFunctions.RobotMass(weight=default_weight)

Punishes higher weight of the robot
create a weighted cost
The default weight should be chosen in a way that higher cost means worse outcome. In case of rewards (e.g. cost proportional to goals achieved), the weight should default to a negative value.
- Parameters:
weight (float) – Can be any number, positive or negative.
- __add__(other)
The sum of two costs
- __mul__(other)
Change the cost function’s weight by multiplying it by a float
- __neg__()
Negate the cost function’s weight (e.g. for rewards)
- __slots__ = ()
- __sub__(other)
The difference of two costs
- __truediv__(other)
Change the cost function’s weight by dividing it by a float
- _evaluate(solution)
The total mass of the solution robot
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- default_weight = 1.0
- descriptor(scale=1.0)
Creates a string describing this cost function which can be used for serialization.
- classmethod empty()
Return an empty cost function
- Return type:
- evaluate(solution)
Calculates the cost of the solution for its internally stored task
- Parameters:
solution (timor.task.Solution.SolutionBase)
- Return type:
- static from_descriptor(descriptor)
Build the cost from a string:
Takes a description string for a cost function and returns the corresponding instance
- Parameters:
descriptor (str) – Abbreviation for the cost function. Format <name> or <name_weight>
- Returns:
instance of the cost function
- Return type:
- weight = 1.0
- timor.task.CostFunctions.abbreviations
- timor.task.CostFunctions.abbreviations_inverse