4
Variational Inference for Predictive and Reactive Controllers Mohamed Baioumy Matias Mattamala Nick Hawes Abstract— Active inference is a general framework for decision-making prominent neuroscience that utilizes varia- tional inference. Recent work in robotics adopted this frame- work for control and state-estimation; however, these ap- proaches provide a form of ‘reactive’ control which fails to track fast-moving reference trajectories. In this work, we present a variational inference predictive controller. Given a reference trajectory, the controller uses its forward dynamic model to predict future states and chooses appropriate actions. Further- more, we highlight the limitation of the reactive controller such as the dependency between estimation and control. I. INTRODUCTION Recent approaches in robotics have taken inspiration from active inference [1], a theory of the brain prominent in neuroscience. Active inference provides a framework for understanding decision-making of biological agents. Under the active inference framework, optimal behavior arises from minimising variational free-energy: a measure of the fit be- tween an internal model and (past) sensory observations [2]. Additionally, agents act to fulfill prior beliefs about preferred future observations. This framework has been employed to explain and simulate a wide range of complex behaviors, including planning, abstract rule learning, reading, and social conformity (see Table 1 of [3] for references). A handful of approaches have used active inference to control robotic systems. For example, in [4] an implemen- tation of an active inference controller is presented for a 3 DoF humanoid robot. It was capable of performing reaching behaviors in the visual field under noisy observation. How- ever, the control was performed using velocity commands rather than torque commands. Second, in [5], a method for joint space control of robotic manipulators is presented and compared to the state-of-the-art Model Reference Adaptive Control in adaptability. In [6], [7] this approach is extended to included hyperparameter learning. In this work, we show how the approach in [4], [5] provides a form of ‘reactive’ control (the error occurs first, then the controller reacts to it). It can only track slow references and has a a significant time-delay. Our main contribution is to present a predictive controller based on variational inference. Given a reference trajectory, the controller uses its forward dynamic model to predict future states and choose appropriate actions to reach the desired trajectory. Additionally, unlike the reactive approach, the state-estimation and control steps are separated which allows for faster response of the controller. The authors are with the Oxford Robotics Institute, University of Ox- ford, UK. Use {mohamed, matias, nickh}@robots.ox.ac.uk for correspondence. II. REACTIVE CONTROLLER BASED ON ACTIVE I NFERENCE Active Inference considers an agent in a dynamic environ- ment that receives observations o about states s. The agent then infers the posterior p(s|o) given a model of the agent’s world. Instead of exactly calculating p(s|o), which could be computationally expensive, the agents approximates p(s|o) with a ‘variational distribution’ Q(s) which we can define to have a standard form (Gaussian for instance). The goal is then to minimize the difference between the two distributions which computed by the KL-divergence [8]: KL(Q(s)||p(s|o)) = Z Q(s) ln Q(s) p(s, o) ds + ln p(o) = F + ln p(o). (1) The quantity F is referred to as the (variational) free- energy -or Evidence lower bound- and minimizing F mini- mizes the KL-divergence. If we choose Q(s) to be a Gaussian distribution with mean μ, and utilize the Laplace approxima- tion [9], the free-energy expression simplifies to: F ≈- ln p(μ, o). (2) Now the expression for variational free-energy is solely dependent on one parameter, μ, which is referred to as the ‘belief state’. The objective is to find μ which minimizes F ; this results in the agent finding the best estimate of its state. Generalised motions (GM) [10] are used to represent the (belief) states of a dynamical system, using increasingly higher order derivatives of the system state. This means that the n-dimensional state μ and its higher order derivatives are combined in ˜ μ ˜ μ ˜ μ ( ˜ μ ˜ μ ˜ μ =[μ,μ 0 μ 0 μ 0 ...]). The same can be done for the observations (˜ o =[o, o 0 ...]). For instance, in the context of a robotic manipulator, o represents the sensory observation of a joint position, while o 0 represents the joint’s velocity observation. We consider GM up to the second order. A. Observation model and state transition model Taking generalized motions into account, the joint proba- bility from Equation (2) can be written as: po, ˜ μ ˜ μ ˜ μ)= po| ˜ μ ˜ μ ˜ μ)pμ ˜ μ ˜ μ)= p(o|μ)p(o 0 | μ 0 μ 0 μ 0 ) | {z } Observation model p( μ 0 μ 0 μ 0 |μ)p( μ 00 μ 00 μ 00 | μ 0 μ 0 μ 0 ) | {z } Transition model , (3) where p(o|μ) is the probability of receiving an observation o while in (belief) state μ, and p( μ 0 μ 0 μ 0 |μ) is the state transi- tion model (also referred to as the dynamic model or the

Variational Inference for Predictive and Reactive Controllersmobile/Papers/Brain-PIL_2020_paper... · 2020. 5. 19. · neuroscience. Active inference provides a framework for understanding

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Variational Inference for Predictive and Reactive Controllersmobile/Papers/Brain-PIL_2020_paper... · 2020. 5. 19. · neuroscience. Active inference provides a framework for understanding

Variational Inference for Predictive and Reactive Controllers

Mohamed Baioumy Matias Mattamala Nick Hawes

Abstract— Active inference is a general framework fordecision-making prominent neuroscience that utilizes varia-tional inference. Recent work in robotics adopted this frame-work for control and state-estimation; however, these ap-proaches provide a form of ‘reactive’ control which fails to trackfast-moving reference trajectories. In this work, we present avariational inference predictive controller. Given a referencetrajectory, the controller uses its forward dynamic model topredict future states and chooses appropriate actions. Further-more, we highlight the limitation of the reactive controller suchas the dependency between estimation and control.

I. INTRODUCTION

Recent approaches in robotics have taken inspiration fromactive inference [1], a theory of the brain prominent inneuroscience. Active inference provides a framework forunderstanding decision-making of biological agents. Underthe active inference framework, optimal behavior arises fromminimising variational free-energy: a measure of the fit be-tween an internal model and (past) sensory observations [2].Additionally, agents act to fulfill prior beliefs about preferredfuture observations. This framework has been employed toexplain and simulate a wide range of complex behaviors,including planning, abstract rule learning, reading, and socialconformity (see Table 1 of [3] for references).

A handful of approaches have used active inference tocontrol robotic systems. For example, in [4] an implemen-tation of an active inference controller is presented for a 3DoF humanoid robot. It was capable of performing reachingbehaviors in the visual field under noisy observation. How-ever, the control was performed using velocity commandsrather than torque commands. Second, in [5], a method forjoint space control of robotic manipulators is presented andcompared to the state-of-the-art Model Reference AdaptiveControl in adaptability. In [6], [7] this approach is extendedto included hyperparameter learning.

In this work, we show how the approach in [4], [5]provides a form of ‘reactive’ control (the error occurs first,then the controller reacts to it). It can only track slowreferences and has a a significant time-delay.

Our main contribution is to present a predictive controllerbased on variational inference. Given a reference trajectory,the controller uses its forward dynamic model to predictfuture states and choose appropriate actions to reach thedesired trajectory. Additionally, unlike the reactive approach,the state-estimation and control steps are separated whichallows for faster response of the controller.

The authors are with the Oxford Robotics Institute, University of Ox-ford, UK. Use {mohamed, matias, nickh}@robots.ox.ac.ukfor correspondence.

II. REACTIVE CONTROLLER BASED ON ACTIVEINFERENCE

Active Inference considers an agent in a dynamic environ-ment that receives observations o about states s. The agentthen infers the posterior p(s|o) given a model of the agent’sworld. Instead of exactly calculating p(s|o), which could becomputationally expensive, the agents approximates p(s|o)with a ‘variational distribution’ Q(s) which we can defineto have a standard form (Gaussian for instance). The goal isthen to minimize the difference between the two distributionswhich computed by the KL-divergence [8]:

KL(Q(s)||p(s|o)) =

∫Q(s) ln

Q(s)

p(s,o)ds + ln p(o)

= F + ln p(o).

(1)

The quantity F is referred to as the (variational) free-energy -or Evidence lower bound- and minimizing F mini-mizes the KL-divergence. If we choose Q(s) to be a Gaussiandistribution with mean µµµ, and utilize the Laplace approxima-tion [9], the free-energy expression simplifies to:

F ≈− ln p(µµµ,o). (2)

Now the expression for variational free-energy is solelydependent on one parameter, µµµ, which is referred to as the‘belief state’. The objective is to find µµµ which minimizes F ;this results in the agent finding the best estimate of its state.

Generalised motions (GM) [10] are used to represent the(belief) states of a dynamical system, using increasinglyhigher order derivatives of the system state. This means thatthe n-dimensional state µµµ and its higher order derivatives arecombined in µµµ (µµµ = [µµµ,µ′µ′µ′...]). The same can be done forthe observations (o = [o,o′ ...]).

For instance, in the context of a robotic manipulator, orepresents the sensory observation of a joint position, whileo′ represents the joint’s velocity observation. We considerGM up to the second order.

A. Observation model and state transition model

Taking generalized motions into account, the joint proba-bility from Equation (2) can be written as:

p(o, µµµ) = p(o|µµµ)p(µµµ) = p(o|µµµ)p(o′|µ′µ′µ′)︸ ︷︷ ︸Observation model

p(µ′µ′µ′|µµµ)p(µ′′µ′′µ′′|µ′µ′µ′)︸ ︷︷ ︸Transition model

,

(3)

where p(o|µµµ) is the probability of receiving an observationo while in (belief) state µµµ, and p(µ′µ′µ′|µµµ) is the state transi-tion model (also referred to as the dynamic model or the

Page 2: Variational Inference for Predictive and Reactive Controllersmobile/Papers/Brain-PIL_2020_paper... · 2020. 5. 19. · neuroscience. Active inference provides a framework for understanding

generative model). The state transition model predicts thestate evolution given the current state. These distributionsare assumed Gaussian according to:

p(o|µµµ) = N (o; g(µµµ),Σo), p(o′|µ′µ′µ′) = N (o′; g′(µ′µ′µ′),Σo′),

p(µ′µ′µ′|µµµ) = N (µ′µ′µ′; f(µµµ),Σµ), p(µ′′µ′′µ′′|µ′µ′µ′) = N (µ′′µ′′µ′′; f ′(µ′µ′µ′),Σµ′),(4)

where the functions g(µµµ) and g′(µ′µ′µ′) represent a mappingbetween observations and states. For many application thestate is directly observable, thus g(µµµ) = µµµ and g′(µ′µ′µ′) = µ′µ′µ′.

The functions f(µµµ) and f(µ′µ′µ′) represent the evolution ofthe belief state over time. This encodes the agent’s preferenceover future states (in this case the preferred future state is thereference trajectory, µdµdµd). We assume: f(µµµ) = (µdµdµd − µµµ)τ−1

and f ′(µ′µ′µ′) = (µ′dµ′dµ′d−µµµ′)τ−1, where µdµdµd is the desired trajectory

and τ is a temporal parameter.Given that all distributions are Gaussian, the expression

for F become a sum of quadratic terms and the naturallogarithms as:

F =1

2(∑i

εεε>i Σ−1i εεεi + ln |Σi|) + C, (5)

where i ∈ {o,o′,µµµ,µµµ′} and εµεµεµ = µ′µ′µ′ − (µdµdµd − µµµ)τ−1, εµ′εµ′εµ′ =µ′′µ′′µ′′ − (µ′dµ

′dµ′d − µµµ′)τ−1, εoεoεo = o − µµµ and εo′εo′εo′ = o′ − µ′µ′µ′ and C

refers to constant terms.

B. Estimation and control

To achieve state estimation, we perform gradient descenton F using the following update rules:

˙µµµ = Dµµµ− κµ∂F

∂µµµ, (6)

where κµ is the gradient descent step size and D is atemporal derivative operator.

We thus perform one gradient descent step for eachiteration. To find suitable control actions, we would also alsouse one-step gradient descent; however, the expression forF does not include any actions and thus we resort to usingthe chain rule, assuming an implicit dependence betweenthe actions performed by the agent and the measurements itacquires.

a = −κa∂F

∂a= −κa

∂F

∂o

∂o

∂a, (7)

where κa is the gradient descent step size. The term ∂o∂a is

assumed linear, and equal to the identity matrix (multipliedby a constant) similar to existing work [5], [4].

C. Simultaneous state-estimation and control

Under this formulation, estimation and control are solvedsimultaneously and both processes are dependent. The obser-vation terms (such as εoεoεo) refine the current belief µµµ, whereasthe reference terms εµεµεµ bias the estimated state towards thetarget µdµdµd. In addition, if the parameters τ−1 and Σ−1µ arelarger, the estimate µµµ is biased more towards the target µdµdµd.

0 2 4 6 8 10 12 14Time (s)

−1.0

−0.5

0.0

0.5

1.0

Posit

ion

(m)

Belief (μ(t)) about position (x) for different values of τ−1

Referencex (True position)μ(τ−1 = 0.1)

μ(τ−1 = 2)μ(τ−1 = 8)

Fig. 1: State-estimation for different values of τ−1. Highervalues of τ−1 give more bias towards the target.

0 2 4 6 8 10 12 14Time (s)

−0.75

−0.50

−0.25

0.00

0.25

0.50

0.75

1.00

1.25

Posit

ion

(m)

Control behaviour for different values of τ−1

Referencex(τ−1 = 0.1)x(τ−1 = 1.2)x(τ−1 = 2.4)

Fig. 2: Control behaviour for different values of τ−1. Highervalues of τ−1 potentially introduce overshoot oscillations.

To illustrate this, consider the mass damper system givenby the equation: x = a(t)−k1x−k2x, where x is the positionof the mass, a(t) the control action, k1 the spring constant(set to 1N/m), k2 the damper coefficient (set to 0.1Ns/m)and the system has unit mass. We simulated it with initialconditions x(0) = −0.5m, x(0) = −1m/s and a(t) = 0N .Figure 1 shows the results for the simulation when solvingEquation 6 for different values of τ−1.

It is clear that higher values of τ−1 give more bias towardsthe target. For τ−1 = 8 (green line), the estimate is close tothe target (black dashed line) and far away form the actualposition (blue dashed line) as opposed to setting τ−1 = 0.1(red line). If τ−1 → 0, the estimation step reduces to a pureestimator, which would follow the trajectory without any biastowards the target.

The controller steers the system based on the observationerror terms (εoεoεo and εo′εo′εo′ ). Since larger values of τ−1 movethe estimate more towards the target, the difference given byo−µµµ is larger and thus the controller is more aggressive. Anillustration for the control behaviour given different valuesof τ−1 is shown in Figure 2.

D. Limitations of the reactive formulation

As explained in [6], the presented formulation has twoextremes depending on the value of τ−1. If τ−1 → 0,the estimation step has zero bias towards the target. As

Page 3: Variational Inference for Predictive and Reactive Controllersmobile/Papers/Brain-PIL_2020_paper... · 2020. 5. 19. · neuroscience. Active inference provides a framework for understanding

Figure 1 has shown, for very small values of τ−1, theestimator follows the real position without bias and thusonly performing state estimation. The control action in thiscase will never steer the system towards the target. On theother hand, if If τ−1 →∞ the system is completely biasedtowards the target. In this formulation the approach performsno state-estimation at all and the controller is equivalent toa PID controller. For any other value for τ−1, there is acompromise between estimation and control.

Additionally, we also recognize that it is not intuitive tohave an implicit notion of actions in the model. Recall thatF does not include actions a, but its relationships is inferredfrom observations through the chain rule (Equation 7).

III. PREDICTIVE CONTROLLER

Given the previous limitations, we present a predictivecontroller which explicitly models actions and transitions tofuture states.

A. Predictive generative model

The model for the predictive controller includes the currentstate st, the future state st+1, the control action a and the ob-servation o. The aim is to compute p(st, st+1,a|o). Similarlyto the reactive case we approximate this distribution with avariational distribution, use the mean-field assumption andutilize the Laplace approximation. The posteriors over statesst and st+1 would have the means, µµµs and µµµs+1 respectively.The distribution over actions is also assumed Gaussian witha mean of µµµa. This results in the following model:

pt(µµµs, µµµs+1, o,µµµa) ∝ p(o|µµµs)p(µµµs)p(µµµa)

p(µµµs+1|f(µµµs,µµµa))p(µµµs+1),(8)

where p(o|µµµs) is the observation model, similar to thereactive controller. The term p(µµµs) is a prior on the currentstate µµµs given the result from the previous time step. Thelast term, p(µµµs+1), is a prior on the next state whichsets it to the desired target (from the reference trajectory).p(µµµs+1|f(µµµs,µµµa)), where f(µµµs,µµµa) is a forward dynamicmodel that predicts future states. Finally, the prior over ac-tions p(µµµa) can embed any information about the dynamics,but set to a Gaussian with mean zero and a large variance(Σ−1 → 0) otherwise.

Intuitively, we are not only using past information andcurrent measurements to obtain a current state estimate µµµs,but also using information from dynamic models f(µµµs,µµµa)to compute an action µµµa that will enforce the next state µµµs+1

to be closer to the desired reference. This contrasts witha filtering scheme in which we are only concerned aboutthe current state estimate, and also with a classic predictivecontroller in which we assume the current state is given.

B. Free-energy for a predictive controller

Again, given that all distributions are Gaussian, the ex-pression for F becomes a sum of quadratic terms and thenatural logarithm of the covariances as:

F =1

2(∑i

εεε>i Σ−1i εεεi + ln |Σi|) + C, (9)

where i ∈{o,o′,µµµ,µµµ′,p,p′,d,d′, a

}. There errors terms are

defined as:

εoεoεo = o−µµµs, εo′εo′εo′ = o′ −µµµ′s,

εµεµεµ = µµµs+1 − f(o,µµµs), εµ′εµ′εµ′ = µµµ′s+1 − f(o′,µµµ′s),

εpεpεp = µµµs −µµµp, εp′εp′εp′ = µµµ′s −µµµ′p,

εdεdεd = µµµs+1 −µµµd, εd′εd′εd′ = µµµ′t+1 −µµµ′d.

Finally, if we consider a feedforward signal (s(t)),

εaεaεa = µµµa − s(t),

otherwise εaεaεa is set to zero. The feedforward function is onlydependant on time. This function has to be based on anaccurate dynamic model since it does not account for anydisturbances or imperfections in the model. Even when thefeedforward function s(t) is used, it should have a higheruncertainty in the optimization compared to the forwarddynamic model f(µµµs,µµµa).

C. Estimation and control

For the reactive case, every optimization was done bytaking one step of gradient descent separately. The same isdone in the predictive case. For every time-step t we run thefollowing update rules:

µµµs ← µµµs − kµ∂F

∂µµµs

µµµs+1 ← µµµs+1 − kµ∂F

∂µµµs+1

µµµa ← µµµa − ka∂F

∂µµµa,

(10)

where ka is the gradient descent step for actions and is setto a much larger value that kµ. Subsequently , we move tothe next time-step and µµµs is set to the prior for the next timestep µµµp.

IV. RESULTS

In the results section, we evaluate the the reactive andpredictive approaches on a slow trajectory (µd = sin(0.3t))and a faster trajectory (µd = sin(t)).

A. Tracking a slow trajectory

The response to tracking µd = sin(0.3t) is given inFigure 3. The reactive controller can successfully trackthe reference; however, with a time delay. The predictivecontroller does not suffer from the time delay. In TableI and Fig. 4 the error is given. The error of the reactivecontroller is very large; however, this is partially due to thetime delay. It is also shown how including the (accurate)feedforward signal s(t) improves the performance of thepredictive controller.

Page 4: Variational Inference for Predictive and Reactive Controllersmobile/Papers/Brain-PIL_2020_paper... · 2020. 5. 19. · neuroscience. Active inference provides a framework for understanding

0 5 10 15 20 25 30 35 40Time (s)

−1.00

−0.75

−0.50

−0.25

0.00

0.25

0.50

0.75

1.00Po

sitio

n (m

)Response given a slow trajectory.

ReferencePredictive + s(t)PredictiveReactive

Fig. 3: Response given a slow trajectory µd = sin(0.3t).

0 5 10 15 20 25 30 35 40Time (s)

−0.3

−0.2

−0.1

0.0

0.1

0.2

0.3

Posit

ion

(m)

Error (μd − x) given a slow trajectory.Predictive + s(t)PredictiveReactive

Fig. 4: Error given a slow trajectory µd = sin(0.3t).

Reactive Predictive Predictive + s(t)sin(0.3t) 1.75× 10−1 5.34× 10−2 9.89× 10−5

sin(t) 4.52× 10−1 1.21× 10−2 4.78× 10−3

TABLE I: The Mean Absolute Error (MAE) values associ-ated with figures 3 and 5 are shown. As evident, the reactivecontroller has the highest error.

B. Tracking a fast trajectory

The response for tracking sin(t) is given in Figure 5.The reactive controller in this case struggles to track thereference. By re-tuning the reactive controller, the responsetime can be decreased; however, this introduces oscillationswhich get amplified over time. The predictive controller does

0 5 10 15 20 25 30 35 40Time (s)

−1.00

−0.75

−0.50

−0.25

0.00

0.25

0.50

0.75

1.00

Posit

ion

(m)

Response given a fast trajectory.

Reference Predictive + s(t) Predictive Reactive

Fig. 5: Response given a fast trajectory µd = sin(t).

not suffer from the time delay and has no issue tracking thefast trajectory. Again, in Table I the error is shown. For bothtrajectories, the predictive controller along with an accuratefeedforward signal performs best.

V. CONCLUSIONS AND FUTURE WORK

In this work we presented a predictive controller basedon variational inference. Given a reference trajectory, thecontroller uses its forward dynamic model to predict futurestates and choose appropriate actions to reach the desiredtrajectory. This overcomes the shortcomings of the reactivecontroller such as the compromise between estimation andcontrol. For the predictive controller the actions are explicitin the free-energy expression.

In [6] the covariance and the temporal parameter τ (usedin the reactive controller) were estimated during execution.Future work will focus on learning appropriate variances forthe predictive controller. Additionally, model parameters canbe estimated during the optimization process as well (thespring constant for instance).

Furthermore, the predictive model can be extended toinclude future H time-steps which would allow the agentto plan ahead. This is intimately related to work on planningas inference [11]. This extensions could be efficiently imple-mented using Probabilistic Graphical Models such as factorgraphs [12].

REFERENCES

[1] Karl Friston, Thomas FitzGerald, Francesco Rigoli, PhilippSchwartenbeck, and Giovanni Pezzulo. Active inference: a processtheory. Neural computation, 29(1):1–49, 2017.

[2] Karl Friston. The free-energy principle: a unified brain theory? NatureReviews Neuroscience, 11:127 EP –, 01 2010.

[3] Lancelot Da Costa, Thomas Parr, Noor Sajid, Sebastijan Veselic,Victorita Neacsu, and Karl Friston. Active inference on discrete state-spaces: a synthesis. arXiv preprint arXiv:2001.07203, 2020.

[4] Guillermo Oliver, Pablo Lanillos, and Gordon Cheng. Active inferencebody perception and action for humanoid robots. arXiv preprintarXiv:1906.03022, 2019.

[5] Corrado Pezzato, Riccardo MG Ferrari, and Carlos Hernandez. Anovel adaptive controller for robot manipulators based on activeinference. IEEE Robotics and Automation Letters, 2020.

[6] Mohamed Baioumy, Paul Duckworth, Bruno Lacerda, and NickHawes. Active inference for integrated state-estimation, control, andlearning, 2020.

[7] Mohamed Baioumy, Matias Mattamala, Paul Duckworth, Bruno Lac-erda, and Nick Hawes. Adaptive manipulator control using activeinference with precision learning. In UKRAS20 Conference: “Robotsinto the real world” Proceedings, Lincoln, United Kingdom, May2020.

[8] Charles W Fox and Stephen J Roberts. A tutorial on variationalbayesian inference. Artificial intelligence review, 38(2):85–95, 2012.

[9] Karl Friston, Jeremie Mattout, Nelson Trujillo-Barreto, John Ash-burner, and Will Penny. Variational free energy and the laplaceapproximation. Neuroimage, 34(1):220–234, 2007.

[10] Karl Friston. Hierarchical models in the brain. PLoS computationalbiology, 4(11):e1000211, 2008.

[11] Matthew Botvinick and Marc Toussaint. Planning as inference. Trendsin cognitive sciences, 16(10):485–488, 2012.

[12] Mees Vanderbroeck, Mohamed Baioumy, Daan van der Lans, Rensde Rooij, and Tiis van der Werf. Active inference for robot control: Afactor graph approach. Student Undergraduate Research E-journal!,5:1–5, 2019.