epyt_control.controllers
epyt_control.controllers.pid
This module contains an implementation of a PID controller and a learner (i.e. tuning method) based on an evolutionary algorithm.
- class epyt_control.controllers.pid.PidController(proportional_gain: float, integral_gain: float, derivative_gain: float, target_value: float, action_lower_bound: float | None = None, action_upper_bound: float | None = None)[source]
Bases:
objectImplementation of a Proportional-Integral-Derivative (PID) controller.
- Parameters:
proportional_gain (float) – Proportional gain coefficient.
integral_gain (float) – Integral gain coefficient.
derivative_gain (float) – Derivative gain coefficient.
target_value (float) – Target value (observed system state) which the controller is supposed to reach.
action_lower_bound (float, optional) –
Lower bound of the computed action. Smaller control outputs will be clipped.
The default is None.
action_upper_bound (float, optional) –
Upper bound of the computed action. Control outputs exceeding this upper bound will be clipped.
The default is None.
- property action_lower_bound: float
Lower bound of the computed action. Smaller control outputs will be clipped.
- Returns:
Lower bound of the computed action.
- Return type:
float
- property action_upper_bound: float
Upper bound of the computed action. Control outputs exceeding this upper bound will be clipped.
- Returns:
Upper bound of the computed action.
- Return type:
float
- property derivative_gain: float
Returns the derivative gain coefficient.
- Returns:
Derivative gain coefficient.
- Return type:
float
- property integral_gain: float
Returns the integral gain coefficient.
- Returns:
Integral gain coefficient.
- Return type:
float
- property proportional_gain: float
Returns the proportional gain coefficient.
- Returns:
Proportional gain coefficient.
- Return type:
float
- step(cur_value: float) float[source]
Computes the current/next control action/signal based on the given observation (i.e. system state).
- Parameters:
cur_value (float) – Current observation (i.e. system state).
- Returns:
Computed action – i.e. control signal.
- Return type:
float
- property target_value: float
Returns the target value (observed system state) which the controller is supposed to reach.
- Returns:
Target value (system state).
- Return type:
float
epyt_control.controllers.lqr
This module contains implementations of different Linear Quadratic Regulator (LQR) variants.
- epyt_control.controllers.lqr.linear_quadratic_regulator(current_state: numpy.ndarray, state_cost_mat: numpy.ndarray, action_cost_mat: numpy.ndarray, state_transition_mat: numpy.ndarray, action_transition_mat: numpy.ndarray, time_horizon: int, final_state_cost_mat: numpy.ndarray | None = None) list[numpy.ndarray][source]
Computes the Linear Quadratic Regulator (LQR) control solution of a given inite-horizon & discrete-time LQR problem.
- Parameters:
current_state (numpy.ndarray) – Current system state.
state_cost_mat – Cost matrix of states – i.e. a s.p.s.d. matrix specifying the cost of a given state.
action_cost_mat – Cost matrix of actions – i.e. a s.p.d. matrix specifying the cost of a action state.
state_transition_mat – State transition matrix – i.e. mapping a given state to the next state (without any action).
action_transition_mat – Action transition matrix – i.e. mapping specifying the state change/influence of taking an action.
time_horizon (int) – Time horizon.
final_state_cost_mat – Cost matrix of the final state – i.e. a s.p.s.d. matrix specifying the cost of the final state. If None, ‘state_cost_mat’ will be used for the final state cost.
- Returns:
List of actions for reaching the specified target space.
- Return type:
list[numpy.ndarray]
- epyt_control.controllers.lqr.time_varying_lqr(current_state: numpy.ndarray, state_cost: Callable[[int], numpy.ndarray], action_cost: Callable[[int], numpy.ndarray], state_transition: Callable[[int], numpy.ndarray], action_transition: Callable[[int], numpy.ndarray], time_horizon: int, final_state_cost_mat: numpy.ndarray | None = None) list[numpy.ndarray][source]
Computes the Linear Quadratic Regulator (LQR) control solution of a given inite-horizon & discrete-time LQR problem with time varying parameters.
- Parameters:
current_state – Current system state.
state_cost – Time varying cost matrix of states – i.e. mapping time to a s.p.s.d. matrix specifying the cost of a given state.
action_cost – Time varying cost matrix of actions – i.e. mapping time to a s.p.d. matrix specifying the cost of a action state.
state_transition – Time varying state transition matrix – i.e. mapping time to a matrix for mapping a given state to the next state (without any action).
action_transition – Time varying action transition matrix – i.e. mapping time to a matri for specifying the state change/influence of taking an action.
time_horizon (int) – Time horizon.
final_state_cost_mat – Cost matrix of the final state – i.e. a s.p.s.d. matrix specifying the cost of the final state. If None, ‘state_cost’ will be used for getting final state cost.
- Returns:
List of actions for reaching the specified target space.
- Return type:
list[numpy.ndarray]