Why do we want to decompose a function?
Decomposing a function means breaking it down into its component parts. The reason for doing so is the same as why we wanted to decompose a matrix in Chapter 3 using the eigendecomposition or using the SVD – to break it down into simpler parts. By simpler, we mean breaking a function down into a sum of functions that are easier to understand, have nicer properties, and behave in ways we understand when we transform them.
What is a decomposition of a function?
We have already answered this question to some degree. Decomposing a function, , means writing that function as a sum of other functions. In math, that means we write the following:
Eq. 1
The number of functions, , that we decompose, , into could be finite or infinite. It depends on what we want to do with the decomposition on the right-hand side of Eq. 1.
We also haven’t said what the component functions, , are yet. Again, the choice of components, , will depend on how we want to use the decomposition. However, the fact that we have included some coefficients, , in the decomposition hints at the idea that we usually take the component functions, , to be “standardized” in some way. This means they will have properties and behaviors we understand. This is one of the main benefits of decomposing a function. Consider that we have some linear transformation, represented by , that we want to apply to . If we use our decomposition in Eq. 1, when we apply , we get the following:
Eq. 2
So, if we know and understand what the effect of the transformation, , has on the component functions, , then we understand what effect has on our function, . Often, we will choose the component functions, , because they have a simple behavior when the transformation, , is applied to them – in other words, the mathematical form of determines what component functions, , we use. We’ll learn more about this in the next section. However, to finish this short section, we’ll look at a couple of examples where we decompose a function not based on a transformation we want to apply to the function, , but based on the properties of the function, , that we to want understand. This will help reinforce the concept that sometimes, what we decompose depends on what properties we want to analyze or what properties we would like our component functions to have.
Example 1 – decomposing a one-dimensional function into symmetric and anti-symmetric parts
For this example, we’ll be looking at one-dimensional functions – that is, functions, , where , so can be anywhere on the real number line. Some one-dimensional functions are symmetric, so they have the nice property that . This property can be useful because if we already have code that computes , we don’t need any further code to calculate . Similarly, other mathematical calculations such as integration and differentiation of can sometimes be simplified using the knowledge that is symmetric.
Likewise, some one-dimensional functions are anti-symmetric, meaning . Knowing that a function is anti-symmetric is useful in the same way that knowing a function is symmetric – we can simplify various mathematical and computational calculations.
What happens if a one-dimensional function is neither symmetric nor anti-symmetric? It turns out that any one-dimensional function can be decomposed into (written as a sum of) a symmetric function and an anti-symmetric function. So, we can always write like so:
Eq. 3
The right-hand side of Eq. 3 is a decomposition of of the form given in Eq. 1. It is a sum of two functions, so , with coefficients, . The two functions are a symmetric function, , and an anti-symmetric function, .
This is great, but how do we work out what and are? Very easily – we calculate . Using the decomposition on the right-hand side of Eq. 3, we find the following:
Eq. 4
The last step in Eq. 4 follows from the fact that and . From Eq. 4, we have the following:
Eq. 5
A similar calculation reveals the following:
Eq. 6
This was a very simple example, so we’ll look at a more realistic one next.
Example 2 – decomposing a time series into its seasonal and non-seasonal components
The left-hand plot in Figure 9.1 shows the daily sales level (number of units sold) of a supermarket product over 3 years. We can think of this time series data as a one-dimensional function. It has a value for each value of the timepoint variable, .
The sales time series clearly shows a yearly seasonal pattern. This is not unusual for supermarket products. The size of the seasonal variation is large, with around a 400-unit change from low season to high season. Unfortunately, the seasonal variation, which we can’t control, is hiding the variation in sales due to price changes, which we can control. The effect of price changes on sales is what we’d like to understand. The daily sales level, with the effect of the seasonality removed, is shown in the right-hand plot of Figure 9.1. Having removed the seasonality, the right-hand plot clearly shows the effect of the price changes that have occurred:
Figure 9.1: Decomposing a sales time series into its seasonal and non-seasonal components
If we can separate the seasonal component from the original data, we can build a model of the remaining part using price as a predictive feature. Then, we can make forecasts of future sales levels at new price points. This means we want to decompose , like so:
Eq. 7
Again, Eq. 7 is a simple example of the general form in Eq. 1, with just two component functions with coefficients and . There are numerous techniques we can use to do this decomposition. For example, the seasonal component in the left-hand plot of Figure 9.1 looks like a sinusoidal pattern, so we could create a new sine wave feature (with a 1-year period) and fit this new feature to the data. We won’t go into the details of how to do this. What’s more important to understand is that decomposing the time series data into its various components is an example of function decomposition, and that function decomposition serves a useful purpose by allowing us to understand how a function or even data is comprised. This is the main lesson from this short section. Now is a good point at which to summarize that lesson.
What we’ve learned
In this section, we learned the following:
- Decomposing a function means breaking it down into several component functions that are easier to work with
- When we decompose a function, we write it as a sum of component functions multiplied by a coefficient
- We choose the component functions because they have convenient properties or behavior, such as when we apply a particular transformation to them
Having introduced the basic concept of function decomposition, in the next section, we will move beyond the simple examples we used in this section and show how to decompose using a set of standardized components that have pre-specified properties.