Machine Learning in Energy Systems
Machine Learning in Energy Systems
1 Overview
What is machine learning (ML)? From our perspective, it is quite simply mathematical modeling
from data. Recall Chapter 1 on mathematical modeling. Recall that we outlined seven steps as a
guide for creating mathematical models. Step 6 involves training the unknown system parameter
from experimental data. This chapter dives deeply into this specific task. Note, the mathematical
model itself may arise from either first-principles, or be a generic “black-box” format. In either case,
our objective is to “fit” the unknown parameters (a.k.a. “weights” or “coefficients”) from experimen-
tal data. In energy systems, we sometimes find ourselves rich in data yet poor in engineering
insight. These techniques provide the engineer with various tools to generate system models from
data.
Machine learning is, in fact, a convergence of several other intellectual fields that include op-
timization, statistics, control theory, and computer science. We have strategically introduced op-
timization before ML in this course, because ML can be viewed as an application of optimization.
Historically, “machine learning” was coined by IBM computer scientist Arthur Samuel in 1959.
Specifically, Arthur Samuel said the following about ML: “It gives computers the ability to learn
without being explicitly programmed.” In the 1980s – 1990s, the concept of artificial intelligence
(AI) emerged as another re-branding of ML. Interestingly, AI and ML lost popularity throughout the
2000s. The main reasons include: (i) The promises of AI and ML far exceeded the results, and
therefore academia and industry disinvested in these ideas. (ii) The lack of consistent results is
partially attributed to theoretical misunderstandings, many of which have since been resolved. (iii)
We now have the computational resources to handle very large datasets and parallelized compu-
tation. Consequently, ML and AI have re-emerged in the 2010’s as “Data Science”. Now academia
and industry are re-investing heavily in these technologies. In this chapter, you will see that ML
is essentially an application of optimization, statistics, and control theory. With this view, you will
become ML experts who understand the fundamental principles.
To this end, Chapter 2 examines the following questions:
Inferring models from observations and studying their properties is the essential basis of science.
These models (a.k.a. hypotheses, laws of nature, theories) can be more or less formal in nature.
However, they all attempt to link observations together through some pattern. Machine learning
involves the inference of a system model from input-output observations, as shown in Fig. 1. The
construction of this system often falls within three different paradigms: white-box models, black-
box models, or grey-box models.
u y
- Mathematical Model |Σ -
Input variables Output variables
Parameters |θ
• [White-box Models]: Sometimes we can formulate the mathematical model equations from
first principles (e.g. Newton’s laws, Navier-Stokes, Maxwell’s equations, etc.). This white-box
model paradigm is often preferable, since it simplifies the model identification process and
endows the model with physically relevant meaning. Moreover, these models are capable of
accurately predicting behavior outside of the training data.
• [Black-box Models]: In some applications, the underlying dynamic process is too complex
to model from first principles. Examples include human behavior, biological systems, social
systems, or large-scale systems with many intertwined dynamic phenomena. The black-
box modeling paradigm starts from measurements of the system’s inputs and outputs and
determines a mathematical relation between them without attempting to model the internals
of the system. Note that these models are generally unreliable extrapolating behavior outside
of the training data range.
In this chapter, we are interested in tools applicable to white-box models, black-box models,
and all the shades of grey in between. Interested readers may refer to the textbook by Ljung [1]
for a thorough exposition of system identification methods for black-box models.
Throughout this chapter, we introduce offline and online algorithms for machine learning. Offline
(a.k.a. batch or non-recursive) algorithms operate on a fixed collection of data, asynchronous from
the true physical system. These algorithms are often simpler to formulate. However, they require
large collections of data and computational power, and are not amenable to implementation in an
embedded computational system. Sometimes one wishes to “learn” the model in a continuous
manner, where it utilizes data as it arrives and then discards it. These techniques are known as
online (a.k.a. recursive) algorithms. These algorithms are typically more difficult to formulate, but
are amenable to implementation in embedded systems in synchrony with the dynamic system.
1. Parametric Modeling
2. Gradient Algorithm
5. Offline Techniques
6. Sensitivity Analysis
2 Regression
Example 2.1 (Linear Regression). Suppose you have collected measured data pairs (xi , yi ), for
i = 1, · · · , N where N > 6, as shown in Fig. 2. You seek to fit a fifth-order polynomial to this data,
i.e.
y = c0 + c1 x + c2 x2 + c3 x3 + c4 x4 + c5 x5 (1)
Figure 2: You seek to fit a fifth-order polynomial to the measured data above.
Now we compute an optimal fit for c in the following sense. We seek the value of c which minimizes
the squared residual
1 1 1 1 1
min krk22 = rT r = (Ac − y)T (Ac − y) = cT AT Ac − y T Ac + y T y. (4)
c 2 2 2 2 2
Note that (4) is quadratic in variable c and therefore a convex function of c. This produces a
quadratic program. In this case the problem is unconstrained. That is, our immediate objective
is to solve an unconstrained QP to fit the parameters. To this end, we set the gradient with respect
to c to zero and directly solve for the minimizer.
∂ 1
krk22 = AT Ac − AT y = 0,
∂c 2
AT Ac = AT y,
This provides a direct formula for fitting the polynomial coefficients ci , i = 0, · · · , 5 using the
measured data.
Exercise 1. Consider fitting the coefficients c1 , c2 , c3 of the following sum of radial basis functions
to data pairs (xi , yi ), i = 1, · · · , N .
2 2 2
y = c1 e−(x−0.25) + c2 e−(x−0.5) + c3 e−(x−0.75) (6)
Formulate the corresponding QP problem. Derive the explicit formula for fitting the coefficients.
Exercise 2. Repeat the same exercise for the following Fourier Series:
1 1
min krk22 + kΓck22 . (8)
c 2 2
for some matrix Γ ∈ R6×6 . Derive the QP. Solve for the minimizer of this unconstrained QP. Provide
a formula for the optimal coefficients c.
4 Parametric Modeling
Algorithms and optimization receive all the glory in model identification. However, skillful paramet-
ric modeling gets grossly under-appreciated. It is a necessary initial step for any model identifica-
tion study. A cleverly formulated parametric model can render the algorithms nearly trivial. This
section discusses various canonical formulations for parametric models.
In Chapter 1, we discussed the derivation of models from first principles. This typically renders
ODEs that can be formulated into state space form as a series of first-order ODEs
where x(t) ∈ Rn×1 , u(t) ∈ Rp×1 , t represents continuous time, and θ ∈ Rp×1 are a set of constant
parameters to be identified. In practice, data is sampled in discrete-time instances. Consequently
we shall also consider discrete-time models in this chapter, which take the form
where ai , bi , for i = 0, 1, . . . , n are scalar parameters. In the stochastic process literature [1], this
is known as the famous ARX model (auto-regressive with exogenous input u()), and is a common
black-box model. If we lump all the ai , bi parameters into the vector
θ = [b0 , b1 , . . . , bn , a0 , a1 , . . . , an ]T (12)
φ(k) = [u(k), u(k − 1), . . . , u(k − n), −y(k), −y(k − 1), . . . , −y(k − n)]T (13)
Equation (14) is linear in θ which, as we show in subsequent sections, is crucial for designing
parameter identifiers to estimate θ from the measurements of y(k + 1) and φ(k).
It is always beneficial to formulate the model into the form (14) when possible. However, some-
times the model is not linear in the parameters. In these cases, the set of available algorithms
decreases dramatically and their properties generally weaken. However, these nonlinear cases
do arise in practice. Generally, a nonlinear in the parameters model takes the form of
where φ(k) is an appropriately defined vector of I/O data, y(k + 1) is the output data at time-step
k + 1, θ is the unknown parameter vector, and f (·, ·) is a nonlinear function that maps I/O data and
parameters to a scalar measured output. Artificial neural networks are an example of a nonlinear-
in-the-parameters model. In this case, we must utilize iterative optimization methods to estimate
the value of parameter vector θ that best matches the data and model.
x1
@
@
@ w1
@ #
x2 w2 @R
@
- f (·)
y -
"!
w3
x3
Example 4.1 (Artificial Neural Networks (ANN)). Artificial neural networks (ANNs) were first cre-
ated by Warren McCulloch and Walter Pitts in 1943 as a computational model for the human brain.
Recently, ANNs have re-emerged within artificial intelligence due to (i) the availability of enhanced
computational power, and (ii) resolutions to theoretical stability issues.
A neural network is composed of a weighted directed graph, as shown in Fig. 3. Each node of
the graph (a.k.a. neuron) is “activated” by inputs. The node will perform some simple computations
on these inputs, using a so-called “activation function”, and then pass its result along the network.
More specifically, each node computes a weighted sum of its inputs and then processes this sum
with its activation function, i.e. f ( i wi xi ) or written in vector notation as f (wT x).
P
Consider the trivially simple single neuron network shown in Fig. 4. Denote the input weights
by wi . There are several canonical activation functions.
Linear-in-the-parameters Model: Consider the affine activation function
f (wT x) = a · wT x + b, (16)
θ = [a, b, w1 , w2 , · · · , wn ]T . (17)
where θ ∈ Rn+2 . This is intuitive. We just collect each scalar parameter into a vector θ. However,
this yields a parametric input-output model which is nonlinear in θ. To see this, let θi be the ith
This parametric model is linear w.r.t. ϑ. Moreover, it has less parameters n + 1 versus n + 2 for θ.
Nonlinear-in-the-parameters Model: Two other common examples are the sigmoid and tanh
activation functions, given respectively by
1
f1 (wT x) = , f2 (wT x) = tanh(wT x). (21)
1 + exp(wT x)
These two activation functions produce parametric input-output models given by:
1
y= , y = tanh(wT x), (22)
1 + exp(wT x)
Example 4.2 (Flywheel Energy Storage). Consider the flywheel energy storage example from
CH1. Recall that the equation of motion is governed by Euler’s rotation equation:
˙ denotes the derivative with respect to time. Note that ω(t) is the state variable, T (t) is a
where (·)
controllable input torque, and I, b are physical parameters representing the rotational inertia and
friction coefficient, respectively. Suppose we can measure ω(t), T (t). Our ultimate goal is to learn
the unknown parameters. To this end, we must first derive a parametric model. In this example,
we will derive both linear and nonlinear-in-the-parameters models.
d ω(t+∆t)−ω(t)
Suppose we approximate the time-derivative using forward Euler’s method: dt ω(t) ≈ ∆t .
Furthermore, we define discrete-time index k such that t = k · ∆t. Then we can re-write (23) as
ω(k + 1) − ω(k)
I· = −bω(k) + T (k), (24)
∆t
b∆t ∆t
ω(k + 1) = 1 − ω(k) + T (k) (25)
I I
Linear-in-the-parameters Model: The flywheel dynamics are now in the form of ω(k + 1) = θT φ in
(14), where the parameter vector θ and regressor signal φ are:
T
b∆t ∆t
θ = 1− , , φ = [ω(k), T (k)]T . (26)
I I
Interesting, if the sampling time ∆t is known (a very mild assumption), then we can back-calculate
b∆t ∆t ∆t 1−θ1
I, b from θ1 = 1 − I , θ2 = I by the following formulae: I = θ2 , b = θ2 . Note, it is NOT
always possible to back-calculate the physical parameters from the linear parameter vector θ. A
necessary (but not sufficient) condition for back-calculating physical parameters from θ is that the
number of physical parameters equals the dimension of θ.
Nonlinear-in-the-parameters Model: Alternatively, we might initially define the parameter vector to
correspond to the physical parameters as follows: θ = [I, b]T . In this case, we have a nonlinear-
in-the-parameters model given by:
Loosely speaking, it is MUCH more difficult to identify parameters for the nonlinear-in-the-parameters
model above. Technically speaking, there are no general algorithms that are provably convergent.
Hence, linear-in-the-parameters models are always preferred.
4.3 Identifiability
A logical question to ask is: “Is it always possible to determine the model parameters by observing
a sufficient amount of data? If not, then is there a test to determine when it is possible to determine
the model parameters?” In model identification this existence question is called identifiability. We
now present several notions of identifiability:
Note that identifiability and partial identifiability depend on your data. When people say “I have
excellent data quality,” they are referring (perhaps ignorantly) to this concept. Given these con-
cepts, a simple test to determine identifiability would be extremely convenient. We shall discuss
two tests in this chapter. The first test given in Section 5.3 is specific to models that are linear-in-
the-parameters, and is known as the persistence of excitation condition. The second test given in
Section 9 is applicable to nonlinear-in-the-parameters models, and is called sensitivity analysis.
5 Gradient Algorithm
where y(t) is a scalar output, u(t) is a scalar input, and θ is an unknown scalar parameter. As-
suming that u(t), y(t) are measured, we seek an estimate of θ at each time t. We denote the
estimated version of the parameter vector as θ̂. If the measurements of y, u were noise free, one
could simply calculate θ̂(t) as
y(t)
θ̂ = (29)
u(t)
whenever u(t) 6= 0. The division (29), however, may not be desirable because u(t) may assume
values arbitrarily close to zero. Furthermore, the effect of noise on the measurement of u, y may
lead to an erroneous estimate of θ. The noise and divide-by-zero effects in (29) may be reduced
by using various other nonrecursive or offline methods, especially when θ is a constant for all t.
In our case, we are interested in a recursive or on-line method to generate θ̂(t). We are looking
for a differential equation, which (i) depends on signals that are measured, (ii) whose solution is
θ̂(t), (iii) has equilibrium point θ̂eq = θ, and (iv) this equilibrium point is asymptotically stable. The
procedure for developing such a differential equation is given below.
Using θ̂(t) as the estimate of θ at time t, we generate the estimated or predicted value ŷ(t) of
the output y(t) as
ŷ(t) = θ̂(t)u(t) (30)
Now define the parameter estimation error as θ̃(t) = θ − θ̂(t), where the error (t) can be re-written
as
(t) = θu(t) − ŷ(t) = θ̃(t)u(t) (32)
The differential equation for generating θ̂(t) is developed by minimizing various cost criteria of
with respect to θ̂. For this example, we use the simple cost criterion
1 1 2
J(θ̂) = 2 = y − θ̂u (33)
2 2
It is easy to see that, for each time t, the cost function J(θ̂) is convex over all R; therefore, any local
d
minimum of J is also global and satisfies J(θ̂) = 0. Consequently, we may utilize a gradient-
dθ̂
scheme (a.k.a. steepest descent) to generate an update law for θ̂(t), as follows
˙ d
θ̂(t) = −γ J(θ̂) = γ(y − θ̂u)u = γu, θ̂(0) = θ̂0 (34)
dθ̂
where γ > 0 is a scaling constant. In the literature, the differential equation (34) is referred to as
the update law or identification algorithm for updating θ̂(t) to estimate θ online.
Stability analysis helps us show that the solution of (34) indeed converges to the true value of
θ, under appropriate conditions. Stability is analyzed by re-writing (34) in terms of the parameter
error θ̃ = θ − θ̂, i.e.
˙ ˙
θ̃ = θ̇ − θ̂ = θ̇ − γu (35)
˙
θ̃(t) = −γu2 (t)θ̃(t) (36)
Note that the coefficient −γu2 (t) is always non-positive, which from Chapter 1 we learned proves
that the parameter error dynamics are marginally stable or stable in the sense of Lyapunov. If we
add the sufficient condition that u(t) 6= 0 uniformly in t, then we obtain the stronger condition that
the estimation error is asymptotically stable. In other words, θ̂(t) → θ as t → ∞.
Next we present the vector case of the gradient algorithm. Consider a linear parametric model of
the form
z(t) = θT φ(t) (37)
where z(t) is a scalar measurement, θ is a vector of unknown parameters, and φ(t) is a vector
of I/O data. Note this is the canonical linear in the parameters model from Section 4.1. The
corresponding prediction or estimation error (t) is given by
C
R1
_ V +
c
+
OCV(z) R2 V
_
I
Figure 5: OCV-R-RC Equivalent circuit model of a battery. Includes an open circuit voltage in series with a
resistance, in series with a resistor-capacitor pair.
Now define the parameter estimation error as θ̃(t) = θ − θ̂(t), where the error (t) can be re-written
as
(t) = θT φ(t) − ẑ(t) = θ̃T (t)φ(t) (39)
The differential equation for generating θ̂(t) is developed by minimizing various cost criteria of
with respect to θ̂. For this example, we use the simple cost criterion
1 1 2
J(θ̂) = 2 = z − θ̂T φ (40)
2 2
It is easy to see that, for each time t, the cost function J(θ̂) is convex over all R; therefore, any local
d
minimum of J is also global and satisfies J(θ̂) = 0. Consequently, we may utilize a gradient-
dθ̂
scheme (aka steepest descent) to generate an update law for θ̂(t), as follows
˙ d dJ d
θ̂(t) = −Γ J(θ̂) = −Γ = Γφ(t)(t), θ̂(0) = θ̂0 (41)
dθ̂ d dθ̂
Example 5.1 (Battery Voltage). In HW1, you studied an equivalent circuit model shown in Fig. 5,
where the battery voltage output function is,
The state variables are state-of-charge z(t) and capacitor voltage Vc (t). The input is current I(t).
In this equation, R is a parameter and function OCV (z) can be parameterized with a cubic poly-
nomial: OCV (z) = p0 + p1 z + p2 z 2 + p3 z 3 . Substituting,
Our goal is to use the gradient algorithm to recursively learn parameters p0 , p1 , p2 , p3 , R1 in the
model (43), given streaming data V (t), z(t), Vc (t), I(t).
First, we must define a parametric model. A linear-in-the-parameters model z(t) = θT φ(t) can
be defined as follows:
T
θ = [p0 , p1 , p2 , p3 , R1 ]T , φ(t) = 1, z(t), z 2 (t), z 3 (t), I(t)
z(t) = V (t) − Vc (t), (44)
˙
θ̂(t) = Γφ(t)(t), θ̂(0) = θ̂0 (45)
Similar to the scalar case, we require an extra technical condition to ensure parameter vector θ̂(t)
converges asymptotically to the true parameter θ, given sufficient input-output data. As before, we
can write the parameter estimation error dynamics as
˙ ˙
θ̃(t) = θ̇ − θ̂ = −Γφ = −Γφ(θT φ − θ̂T φ) = −Γφ(φT θ − φT θ̂),
= −ΓφφT θ̃,
= −ΓA(t)θ̃(t) (46)
where Γ is a diagonal positive-definite matrix and A(t) = φ(t)φT (t). Recalling our notion of asymp-
totic stability for an autonomous linear time-invariant (LTI) systems of the form ẋ(t) = ALT I x(t)
from Chapter 1, we require that ALT I have eigenvalues that all have strictly negative real parts. In
the present situation, we have a linear time-varying system, which requires a slightly more techni-
cal condition, known as Persistent Excitation. Intuitively, it encapsulates the fact that the data must
be sufficiently rich to excite the dynamics such that the true parameters can be inferred.
Definition 5.1. (Persistent Excitation (PE)) The (bounded) regressor signal φ(t) is called PE with
0 4.0
V(t)
3.9
1 V̂(t)
3.8
2
I(t) [amps]
3.7
Voltage
3 3.6
3.5
4
3.4
50 100 200 300 400 500 600 3.30 100 200 300 400 500 600
4.0 0.10
3.5 R̂1 (t)
3.0 0.08
2.5 p̂0 (t)
Parameters
Parameters
2.0 p̂1 (t) 0.06
1.5 p̂2 (t)
0.04
1.0 p̂3 (t)
0.5 0.02
0.0
0.50 100 200 300 400 500 600 0.000 100 200 300 400 500 600
Time [sec] Time [sec]
Figure 6: Parameter estimates of HW1 voltage model, using the gradient algorithm.
If the regressor signal φ(t) is PE, then θ̂(t) → θ as t → ∞. Note that a sufficient condition to satisfy
the PE definition (47), which can be checked numerically, is
Z t+T
T
λmin φ(τ )φ (τ )dτ >0 (48)
t
Remark 5.1. Note that the PE condition means A(t) in the dynamic system (46) must be “positive”
in some sense. Specifically, the integrated value of A(t) over some time interval of size T must be
positive definite. The “more” positive-definite the left-hand-side of (47) is, the faster the estimate
θ̂(t) converges to the true value θ. This convergence speed can be characterized by the level of
excitation, α. We summarize this important result in the following theorem.
Theorem 5.1 (Gradient Algorithm Parameter Convergence, adopted from Corollary 4.3.1 of [2]).
˙
Consider parametric model z(t) = θ̂T (t)φ(t) and update law θ̂(t) = Γφ(t)(t) with Γ diagonal and
positive definite, as defined in (37)-(41). If φ(t) is PE according to Definition 5.1 and φ(t), φ̇(t) are
bounded (i.e. stay away from infinity), then θ̂(t) → θ exponentially fast.
Proof. The proof is long and pedantic for an applied course on Energy Systems and Control. We
refer interested readers to Section 4.8 of [2].
The practical utility of this theorem is that checking if φ(t) is PE is the key step to determining
if the gradient algorithm converges exponentially fast to true parameter vector θ.
Remark 5.2. For non-identifiable models and data, the PE level is - in practice - never exactly zero.
In fact, it is usually some very small number close to zero, e.g. 10−6 . This leads to the natural
question: Does PE practically enable us to determine identifiability or non-identifiability? As an
absolute numeric value, the PE level is not very useful. However, the PE level metric allows us to
compare different data sets or different models to use for model identification.
Remark 5.3. As energy systems engineers, we can often design our input-output data. The
consequence of this is that data can be selected such that φ is PE. Checking this PE property
a priori provides a certificate that the data will indeed render estimates that converge to the true
values. More interestingly, we can seek to optimize φ(t) such that the left-hand-side of (48) is
maximum, thereby producing the richest possible data for model identification.
Example 5.2 (Battery Voltage). Consider again the equivalent circuit model shown from Ex. 5.1.
The parametric model is given by z = θT φ, where
T
θ = [p0 , p1 , p2 , p3 , R1 ]T , φ(t) = 1, z(t), z 2 (t), z 3 (t), I(t)
z(t) = V (t) − Vc (t), (49)
Using the -5A pulsed current input in Fig. 6, the PE level can be calculated via (48) to be: 10−6 .
For comparison, let us consider a linear OCV function, which gives the parametric model z = ϑT ϕ:
This parametric model has only 3 parameters, whereas the previous had 5 parameters. Com-
puting the PE level via (48) yields: 0.013. Consequently, the smaller parameterization has strong
identifiability properties, despite using a linear OCV function instead of the true cubic function.
We might also consider different data. Suppose we apply a constant -1A current input to the
battery model. The PE level for both parametric models yields a trivially small result: 10−16 . This
implies the pulsed current is better for model identification than the constant current. The results
are summarized in Table 1.
Least-squares is an old method dating back to Gauss in the eighteenth century where he used it
to determine the orbit of planets. The basic idea behind the least-squares is fitting a mathematical
model to a sequence of observed data by minimizing the sum of the squares of the difference
between the observed and computed data. In doing so, any noise or inaccuracies in the observed
data are expected to have less effect on the accuracy of the mathematical model. Next we derive a
recursive version of the famous least squares algorithm, known as recursive least squares (RLS).
The method is simple to apply and analyze for linear-in-the-parameters models of the form
As before, consider the estimate ẑ of z and the estimation error are generated as
In this case, we are interested in minimizing a cost function which integrates the squared error
over time, as follows
Z t Z th
1 2 1 i2
J(θ̂) = (τ ) dτ = z(τ ) − θ̂T (t)φ(τ ) dτ (53)
2 0 2 0
The cost J(θ̂) penalizes all the past errors from τ = 0 to t that are due to θ̂(t) 6= θ. Note the
conceptual difference between this cost function, and the cost function (40) used for the gradient
algorithm. Specifically, the gradient algorithm minimizes an instantaneous cost, whereas RLS
minimizes an integrated cost. This is a crucial point, conceptually. Since J(θ̂) is a convex function
over R at each time t, its minimizer θ̂ satisfies
Z t Z th
d dJ d T
i
0 = J(θ̂) = =− (τ )φ (τ )dτ = θ̂T (t)φ(τ ) − z(τ ) φT (τ )dτ, (54)
dθ̂ d dθ̂ 0 0
Z t Z t
0 = θ̂T (t) φ(τ )φT (τ )dτ − z(τ )φT (τ )dτ (55)
0 0
for any given time t, where dJ(θ̂)/dθ̂ ∈ R1×n is defined as a row vector. Solving for θ̂(t) results in
Z t
θ̂(t) = P (t) z(τ )φ(τ )dτ (56)
0
where −1
Z t
T
P (t) = φ(τ )φ (τ )dτ (57)
0
provided the inverse exists. This is the celebrated offline (a.k.a. batch or non-recursive) least
squares algorithm.
We can derive a recursive method using the identity
d d
P P −1 = Ṗ P −1 + P P −1 = 0 (58)
dt dt
where P0 = diag(p01 , p02 , · · · , p0n ) 0 is diagonal and positive definite. The implication of (59) is
the calculation of the inverse in (57) can be avoided by generating P as the solution to the matrix
differential equation (59). Similarly, differentiating θ̂(t) w.r.t. t in (56) and using (59) we can derive
the relation
˙
θ̂(t) = P (t)φ(t)(t) (60)
˙
θ̂(t) = P (t)φ(t)(t), θ̂(0) = θ̂0 , (61)
T
Ṗ (t) = −P (t)φ(t)φ (t)P (t), P (0) = P0 (62)
Exercise 4. Derive (59) by substituting (57) into (58) and solving for Ṗ . Next, derive (60) by
differentiating θ̂(t) w.r.t. t in (56) and using (59).
For recursive least squares (RLS), one can also prove convergence to the true parameter
values. We summarize this result with the following theorem.
Theorem 6.1 (RLS Parameter Convergence, adopted from Corollary 4.3.4 of [2]). Consider para-
˙
metric model z(t) = θ̂T (t)φ(t) and RLS update law θ̂(t) = P (t)φ(t)(t), Ṗ (t) = −P (t)φ(t)φT (t)P (t)
with P (0) = P0 diagonal and positive definite, as defined in (37) and (61)-(62). If φ(t) is PE ac-
cording to Definition 5.1 and φ(t) is bounded (i.e. stay away from infinity), then θ̂(t) → θ as t → ∞.
Proof. The proof is long and pedantic for an applied course on Energy Systems and Control. We
refer interested readers to Section 4.8 of [2].
The practical utility of this theorem is that checking if φ(t) is PE is the key step to determining
if RLS converges asymptotically fast to true parameter vector θ.
Example 6.1 (Battery Voltage). Consider once again the equivalent circuit model shown from Ex.
5.1. The parametric model is given by z = θT φ, where
T
θ = [p0 , p1 , p2 , p3 , R1 ]T , φ(t) = 1, z(t), z 2 (t), z 3 (t), I(t)
z(t) = V (t) − Vc (t), (63)
˙
θ̂(t) = P (t)φ(t)(t), θ̂(0) = θ̂0 , (64)
Ṗ (t) = −P (t)φ(t)φT (t)P (t), P (0) = P0 (65)
where P0 = diag(p01 , p02 , p03 , p04 , p05 ) 0 is a diagonal, positive-definite matrix. Think of P0 as
the initial “learning rate”, which gets automatically scaled by 65. Also, = z(t) − θ̂T (t)φ(t) is the
estimation error and θ̂0 is an initial guess for uncertain parameters θ.
Next, we implement the RLS algorithm with parameters P0 =diag(10−1 , 101 , 101 , 101 , 10−1 ),
θ̂0 = [3.5, 1, 0, 0, 0]T . The results are provided in Fig. 7, where the exit estimates are θ̂tf inal =
[3.525, 0.898, −0.370, −0.246, 0.048]T . Recall the true parameter values are θ = [3.4707, 1.6112,
−2.6287, 1.7175, 0.05]T . Also, note that some parameters estimated by RLS are slightly different
than the exit estimates from the gradient law in Ex 5.1. Observe the predicted voltage V̂ (t) =
p̂0 (t) + p̂1 (t)z(t) + p̂2 (t)z 2 (t) + p̂3 (t)z 3 (t) + Vc (t) + R̂1 (t)I(t) converges to the true voltage V (t),
but at a slower rate than the gradient algorithm. This effect is intuitive, since RLS penalizes
the integrated square error as opposed to the instantaneous square error. In other words, the
evolution of the parameter updates θ̂(t) is less sensitive to prediction errors (t) with RLS than
with the gradient algorithm.
The version of least-squares introduced above is known as “pure” least squares, to differentiate it
from the various embellished versions. For a comprehensive coverage of these various adaptive
laws, please consult [2]. These alternate versions impose constraints on the estimated parameters
(projection), weight recent data more heavily than older data (forgetting factors), and reset the
covariance (covariance resetting). A summary of various adaptive laws is given in the Appendix,
for interested readers.
Exercise 5. A popular embellishment of the least squares cost function in (53) is to add a penalty
on the parameter magnitude. These penalties ameliorate ill-conditioned problems, and are gen-
erally called “regularization” in mathematics and statistics. For example, consider the integrated
square error with weighted L2 penalty:
Z t Z th
1 1 1 i2 1
J(θ̂) = (τ )dτ + θ̂T Γθ̂ =
2
z(τ ) − θ̂T (t)φ(τ ) dτ + θ̂T (t)Γθ̂(t) (66)
2 0 2 2 0 2
0 4.0
V(t)
3.9
1 V̂(t)
3.8
2
I(t) [amps]
3.7
Voltage
3 3.6
3.5
4
3.4
50 100 200 300 400 500 600 3.30 100 200 300 400 500 600
4.0 0.10
3.5 R̂ 1 (t)
3.0 0.08
2.5 p̂ 0 (t)
Parameters
Parameters
2.0 p̂ 1 (t) 0.06
1.5 p̂ 2 (t)
0.04
1.0 p̂ 3 (t)
0.5 0.02
0.0
0.50 100 200 300 400 500 600 0.000 100 200 300 400 500 600
Time [sec] Time [sec]
Figure 7: Parameter estimates of HW1 voltage model, using recursive least squares.
where Γ is a diagonal positive definite weighting matrix. This cost function with L2 penalty is known
as Tikhonov regularization or “ridge regression” in the statistics literature. For this exercise, derive
the updates laws for θ̂(t) and P (t) for the cost function in (66). Your answer will be analogous to
(61)-(62). HINT: The answer is exactly (61)-(62), except the initial condition for P (t) is P (0) = Γ−1 .
1. Re-express the nonlinear model in terms of the parameter estimation error θ̃ = θ − θ̂.
3. Define a linearized parametric model based upon a first-order Taylor series approximation
Example 7.1 (Fuel Cell Polarization Curve). Figure 8 presents the output voltage of a fuel cell, as
a function of the current density [A/cm2 ]. This is known as the fuel cell polarization curve. The fuel
cell voltage is calculated using a combination of physical and empirical relationships, and is given
by [3]
Vf c = E − Vact − Vohm − Vconc (67)
where E is the open circuit voltage, and Vact , Vohm , Vconc are activation, ohmic, and concen-
tration over voltages, which represent losses due to various physical or chemical factors. For
pedagogical purposes, we assume Vconc is negligible. The remaining loss terms are given by
Vact = va 1 − e−c·i ,
(68)
Vohm = Ri (69)
Step 3: Truncating and re-arranging terms, we arrive at the linearized parametric model
where
h i
enl = Vf c − θ̂1 + θ̂2 1 − e−θ̂3 i + θ̂4 i, (73)
1
−θ̂3 i
e − 1
φ = −θ̂ ie−θ̂3 i
(74)
2
−i
and both enl and φ are functions of the current parameter estimate θ̂. Step 4: is to apply the least
squares parameter update law as
˙
θ̂ = P enl φ, θ̂(0) = θ̂0 (75)
T
Ṗ = −P φφ P, P (0) = P0 = P0T >0 (76)
This algorithm has local stability properties. That is, when the parameter estimate θ̂ is near its true
value, then the linear approximation is reasonably accurate and θ̂ converges asymptotically to the
true value θ under an appropriate persistence of excitation condition for the regressor φ.
Exercise 6 (Photovoltaic Array Learning). Consider a photovoltaic (PV) array. Figure 9 [top]
presents the characteristic nonlinear relationship between the array’s voltage and current. Mul-
tiplying the current by voltage yields the concave relationship between array current and output
power in Fig. 9 [bottom]. Maximum power point tracking (MPPT) algorithms seek to maintain
the PV at maximum output power, in the face of varying ambient temperatures and incident solar
irradiation (see [5] and references therein).
In this exercise, you seek to learn the characteristic nonlinear relationship in Figure 9, using
current I(t) and voltage V (t) data. Since these curves shift with varying temperature and irra-
diation levels, you seek to learn this relationship in real-time. Derive a nonlinear least squares
algorithm to identify θ = [θ1 , θ2 , θ3 , θ4 , θ5 ]T using the following nonlinear-in-the-parameters model:
h i
θ1 − θ2 e(θ3 V (t)+θ4 I(t)) − 1 − θ5 [θ3 V (t) + θ4 I(t)] = 0 (77)
Current [A]
W/m2
2
2.5 600 W/m 2.5
1.5 1.5 40°C
800 W/m2
2 2 60°C
Current [A]
Current [A]
1 1000 W/m2 1
1.5 1.5
0.5 0.5
1 1
0 0
0 5 10 15 20 25 0 5 10 15 20 25
0.5 0.5
0 0
0 5 10 15 20 25 0 5 10 15 20 25
50 50
40 40
50 50
Power [W]
Power [W]
30 30
40 40
20 20
Power [W]
Power [W]
30 30
10 10
20 20
0 0
100 5 10 15 20 25 100 5 10 15 20 25
Voltage [V] Voltage [V]
0 0
0 9: Characteristic
Figure 5 10 I-V 15
and P-V20curves 25 0 irradiation
for (a) varying 5 10 and 15
levels T = 25◦ C,
20 (b) varying
25
Voltage [V] 2 Voltage [V]
temperature levels and S = 1000W/m .
Derive expressions for enl and φ. Note, this model form is not arbitrary nor eye-balled from data.
(You are too skilled to accept such amateur approaches). It comes from an equivalent circuit
model detailed in Chapter 5 of Masters [6].
8 Offline Techniques
Offline model identification techniques consider scenarios where data is collected from the energy
system as a batch set. This data is then used for model identification, separate from the dynamic
evolution of the energy system itself. As a result, we do not recursively estimate the parameter
values as data arrives. Instead, we fit the model parameters in a single computational procedure.
In this section, we define this problem category and a general formulation. However, we do not
provide any specific algorithms and refer the reader to the optimization literature.
Consider the nonlinear-in-the-parameters model
y = f (u; θ) (78)
where y ∈ Rny is the model output, θ ∈ Rnθ is the true parameter vector, and u ∈ Rnu is a
measured input vector that may or may not be present in the model. We can then formulate an
estimated output ŷ from estimated model parameters θ̂ as follows
With this notation, we can formulate the generic offline model identification problem as an opti-
mization task
where k · k in (80) is an appropriate norm (e.g. sum of squares, maximum magnitude, integrated
over time) and S in (81) is a set of feasible values for the unknown parameters θ̂.
Depending on the mathematical structure and size of the cost function and constraints (80)-
(81), various optimization techniques can be pursued. We provide two categories of techniques
and associated keywords that interested readers can search for further information
9 Sensitivity Analysis
Sensitivity analysis addresses the identifiability question. That is, this analysis is a structured way
to determine which parameters are identifiable. Moreover, it quantifies the level of identifiability,
allowing one to rank which parameters have the greatest influence on the output of interest. This
analysis is specifically oriented toward nonlinear-in-the-parameters models, where the output does
NOT have a linear dependence on the parameters. Despite our previous presentation of gradient,
least squares, and nonlinear least squares algorithms, sensitivity analysis is a necessary first step
in nonlinear parameterized models of energy systems.
Consider the nonlinear-in-the-parameters model
y = f (u; θ) (82)
where y ∈ Rny is the model output, θ ∈ Rnθ is the parameter vector, and u ∈ Rnu is a measured
input vector that may or may not be present in the model. The sensitivity derivative of the model
outputs to the parameter vector is defined as
∂f
S = (u; θ) ∈ Rny ×nθ , (83)
∂θ
∂f ∂f ∂f
S = [S1 , S2 , · · · , Snθ ] = (u; θ), (u; θ), · · · , (u; θ) (84)
∂θ1 ∂θ2 ∂θnθ
Each column of the sensitivity derivative, which we denote Si represents one parameter’s sen-
sitivity in all outputs, and is viewed as the sensitivity direction for the corresponding parameter.
Since the model is nonlinear in the parameters, global identifiability cannot be proven. That is, the
parameter’s sensitivity in an output may depend on the particular parameter values. Moreover, it
may also depend on the input vector u. In addition, only a subset of the parameters may be iden-
tifiable. This occurs when linear dependence exists between columns of the sensitivity derivative.
Intuitively, this means an output produces nearly identical reactions when two different parameters
are perturbed. As a result, it’s essentially impossible to differentiate between these parameters
y2 y2 y2
θ3 θ3 θ3
θ1 θ1 θ1
y1 y1 y1
θ2 θ2 θ2
by observing the output. These complications motivate the need for an efficient and structured
method, which performs the following tasks:
1. Rank parameter sensitivity: This allows us to focus on identifying the most influential pa-
rameters.
For the purposes of presenting this methodology, consider nθ = 4 parameters and an arbitrary
number of output data ny . Then the sensitivity derivative is composed of S = [S1 , S2 , S3 , S4 ] ∈
Rny ×4 . A particular decomposition of matrix S T S reveals both sensitivity ranking and linear de-
pendence. Let S T S = DT CD where
hS1 ,S2 i hS1 ,S3 i hS1 ,S4 i
kS1 k 0 0 0 1 kS1 kkS2 k kS1 kkS3 k kS1 kkS4 k
hS2 ,S1 i hS2 ,S3 i hS2 ,S4 i
0 kS2 k 0 0 kS2 kkS1 k 1 kS2 kkS3 k kS2 kkS4 k
D= , C= , (85)
hS3 ,S1 i hS3 ,S2 i hS3 ,S4 i
0 0 kS3 k 0
kS3 kkS1 k kS3 kkS2 k 1 kS3 kkS4 k
hS4 ,S1 i hS4 ,S2 i hS4 ,S3 i
0 0 0 kS4 k kS4 kkS1 k kS4 kkS2 k kS4 kkS3 k 1
√
where k · k denotes the Euclidian norm (kxk = xT x) and h·, ·i is the inner product (hx, yi =
xT y). This decomposition can be generated by performing Gram-Schmidt orthonormalization of
the sensitivity column vectors. This process coincides with the economical QR decomposition with
permutation (see qr command in Matlab). Now we discuss how to interpret this decomposition.
Example 9.1 (State-of-Health Parameter Estimation in Batteries). This example considers the
identification of uncertain parameters in a nonlinear battery model based upon electrochemistry
[7]. The nonlinear in the parameters model has the form:
−1 θ2 −1 θ3
V (t) = OCV + sinh √ I(t) − sinh √ I(t) + θ4 I(t) (86)
θ1 θ1
where V (t) is battery voltage, OCV is a known open circuit potential, I(t) is battery current, and
θ1 , θ2 , θ3 , θ4 are unknown electrochemical model parameters. Interestingly, identification of these
unknown parameters corresponds directly to assessing the battery’s age - specifically capacity
fade and power fade. For more details consult [7].
An example of matrices D and C is provided in (87). This example analyzes parameter sensi-
tivity for a typical electric drive vehicle charge/discharge cycle.
2.827 0 0 0 1 −0.3000 0.2908 0.2956
0 4.501 0 0 −0.3000 1 −0.9801 −0.9805
D= , C=
.
0 0 3.958 0
0.2908 −0.9801 1 0.9322
0 0 0 15.103 0.2956 −0.9805 0.9322 1
(87)
First, it is evident from D that the parameter sensitivity ranking is as follows: θ4 , θ2 , θ3 , θ1 . Accu-
rate identification of these parameters should be prioritized accordingly. In addition, strong linear
dependence exists between θ2 , θ3 , θ4 . This means perturbations in any of these three parameters
produces almost identical changes in our measured data. Consequently, attempting to individually
separate these variables is futile. An infinite number of linear combinations of these parameters
may satisfy our data. In this case, we should only identify the most sensitive parameter among
these linearly dependent subset. As a result, we conclude the model is partially identifiable and
focus on identifying the subset θ1 , θ4 only.
In this particular application, it turns out θ1 represents - exactly - charge capacity in the battery
and θ4 represents - exactly - internal resistance. Monitoring changes in these parameters yields
directly quantifications of charge and power fade.
10 Notes
Model identification is a rich and deep area, in both theory and applications. In this chapter, we
attempt to provide students with an introduction, several popular tools, and motivation for fur-
ther study. The quintessential reference for system identification is Lennart Ljung’s textbook [1].
Model identification is also commonly used in the context of control, in what is generally known as
“adaptive control.” Excellent textbooks in this area include Ioannou & Sun [2] and Krstic, Kanel-
lakopoulos, & Kokotovic [8]. Finally, Lund & Foss give a particularly excellent article on sensitivity
analysis in nonlinear parameterized models [9].
References
[1] L. Ljung, System identification. Wiley Online Library, 1999.
[2] P. Ioannou and J. Sun, Robust Adaptive Control. Prentice-Hall, 1996.
[3] J. Pukrushpan, H. Peng, and A. G. Stefanopoulou, “Control-oriented modeling and analysis for auto-
motive fuel cell systems,” Journal of dynamic systems, measurement, and control, vol. 126, pp. 14–25,
2004.
[4] J. Pukrushpan, A. Stefanopoulou, and H. Peng, “Control of fuel cell breathing,” Control Systems, IEEE,
vol. 24, no. 2, pp. 30–46, Apr 2004.
[5] S. J. Moura and Y. A. Chang, “Lyapunov-based Switched Extremum Seeking for Photovoltaic Power
Maximization,” Control Engineering Practice, vol. 21, no. 7, pp. 971 – 980, 2013.
[6] G. M. Masters, Renewable and efficient electric power systems. John Wiley & Sons, 2013.
[7] S. J. Moura, N. Chaturvedi, and M. Krstic, “Adaptive PDE Observer for Battery SOC/SOH Estimation via
an Electrochemical Model,” ASME Journal of Dynamic Systems, Measurement, and Control, vol. 136,
no. 1, pp. 011 015–011 026, Oct 2014.
[8] M. Krstic, P. V. Kokotovic, and I. Kanellakopoulos, Nonlinear and adaptive control design. John Wiley
& Sons New York, 1995.
[9] B. F. Lund and B. A. Foss, “Parameter ranking by orthogonalization - Applied to nonlinear mechanistic
models,” Automatica, vol. 44, no. 1, pp. 278 – 281, 2008.
Adaptive laws with Normalization: Throughout these tables, we consider adaptive laws with normaliza-
tion. These laws are identical to their non-normalized variants, except the estimation model is altered to
= (z − ẑ)/m2 , where m2 is known as the normalization signal. This endows the algorithms with additional
boundedness properties, and generally provides better numerical conditioning.
Least-Squares with Forgetting Factor: Sometimes it is desirable to discount past data, relative to more
recent data. This is particularly useful for model parameters that might slowly change over time. The least
squares with forgetting factor is designed under this paradigm, where β is known as the forgetting factor.
When β = 0, then one recovers the pure least squares method. As β increases towards ∞, then one
approaches an instantaneous cost function.
Adaptive Laws with Projection: The parameter estimates θ̂ are generated by solving recursive opti-
mization problems, with appropriately formulated cost functions. In practice, one may wish to constrain
parameter estimates within a physically meaningful set. For example, heat transfer coefficients cannot
be negative, meaningful thermal resistances have upper and lower limits. Motivated by this situation, we
can add a convex constraint set to the optimization formulation. Mathematically, we enforce the constraint
θ̂ ∈ S = {θ̂ ∈ Rn | g(θ̂) ≤ 0}, where set S represents our convex constraint set that is defined by a function
g(·) that maps parameter estimate vectors to scalars. In this algorithm, we additionally require that g(·) is
a so-called “smooth” function. This means that g(·) and all its derivatives are continuous functions. This
is a mathematical technicality, but can be easily achieved in practice. A common selection for the convex
constraint set S is an ellipsoid, which is indeed parameterized by a smooth function g(·). In the algorithm
listed in Table 3, int(S) signifies the interior of set S, and δ(S) signifies the boundary of set S.
Parametric Model z = θT φ
z−ẑ
Normalized Estimation model = m2
Cost J(θ̂) = 12 2
˙
Adaptive Law θ̂ = Γφ
zφ
Q̇ = −βQ + m2
, Q(0) = 0
Cost J(θ̂) = 12 2
Parametric Model z = θT φ
˙
θ̂ = P φ
Adaptive Law
T
Ṗ = βP − P φφ
m2
P, P (0) = P0 = Q−1
0