Difference between revisions of "Piecewise Linear Function"
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | In mathematics and statistics, a '''piecewise linear''', '''PL''' or '''segmented''' function is a real-valued function of a real variable, whose graph is composed of straight-line segments. | ||
+ | |||
+ | ==Definition== | ||
+ | A piecewise linear function is a function defined on a (possibly unbounded) interval of real numbers, such that there is a collection of intervals on each of which the function is an affine function. If the domain of the function is compact, there needs to be a finite collection of such intervals; if the domain is not compact, it may either be required to be finite or to be locally finite in the reals. | ||
+ | |||
+ | ==Examples== | ||
+ | [[Image:Piecewise linear function.svg|right|thumb|A continuous piecewise linear function]] | ||
+ | The function defined by | ||
+ | : <math>f(x) = | ||
+ | \begin{cases} | ||
+ | -x - 3 & \text{if }x \leq -3 \\ | ||
+ | x + 3 & \text{if }-3 < x < 0 \\ | ||
+ | -2x + 3 & \text{if }0 \leq x < 3 \\ | ||
+ | 0.5x - 4.5 & \text{if }x \geq 3 | ||
+ | \end{cases}</math> | ||
+ | is piecewise linear with four pieces. The graph of this function is shown to the right. Since the graph of a linear function is a line, the graph of a piecewise linear function consists of line segments and rays. The ''x'' values (in the above example −3, 0, and 3) where the slope changes are typically called breakpoints, changepoints, threshold values or knots. As in many applications, this function is also continuous. The graph of a continuous piecewise linear function on a compact interval is a polygonal chain. | ||
+ | |||
[[Image:Upper_semi.svg|right]]A piecewise function is a function that is given by different expressions on different intervals. The graph of <math>f(x) = \begin{cases} x^2, & \mbox{if}\ x< 2 \\ - \left(x - 3\right)^2 +9, & \mbox{if}\ x\ge2 \end{cases}</math> is shown on the right. The open circle indicates that the point is not included on the graph and the closed circle indicates that the point is included on the graph. So <math>f(2)</math> = 8 not 4. | [[Image:Upper_semi.svg|right]]A piecewise function is a function that is given by different expressions on different intervals. The graph of <math>f(x) = \begin{cases} x^2, & \mbox{if}\ x< 2 \\ - \left(x - 3\right)^2 +9, & \mbox{if}\ x\ge2 \end{cases}</math> is shown on the right. The open circle indicates that the point is not included on the graph and the closed circle indicates that the point is included on the graph. So <math>f(2)</math> = 8 not 4. | ||
− | <math> \ | + | Other examples of piecewise linear functions include the absolute value function, the sawtooth function, and the floor function. |
+ | |||
+ | ==Fitting to a curve== | ||
+ | |||
+ | [[Image:Finite element method 1D illustration1.svg|right|thumb|A function (blue) and a piecewise linear approximation to it (red)]] | ||
+ | An approximation to a known curve can be found by sampling the curve and interpolating linearly between the points. An algorithm for computing the most significant points subject to a given error tolerance has been published. | ||
+ | |||
+ | ==Fitting to data== | ||
+ | If partitions, and then breakpoints, are already known, linear regression can be performed independently on these partitions. | ||
+ | However, continuity is not preserved in that case, and also there is no unique reference model underlying the observed data. A stable algorithm with this case has been derived. | ||
+ | |||
+ | If partitions are not known, the residual sum of squares can be used to choose optimal separation points. However efficient computation and joint estimation of all model parameters (including the breakpoints) may be obtained by an iterative procedure currently implemented in the package <code>segmented</code> for the R language. | ||
+ | |||
+ | A variant of decision tree learning called model trees learns piecewise linear functions. | ||
+ | |||
+ | ==Notation== | ||
+ | [[Image:Piecewise linear function2D.svg|right|thumbnail|A piecewise linear function in two dimensions (top) and the convex polytopes on which it is linear (bottom)]] | ||
+ | |||
+ | The notion of a piecewise linear function makes sense in several different contexts. Piecewise linear functions may be defined on ''n''-dimensional Euclidean space, or more generally any vector space or affine space, as well as on piecewise linear manifolds, simplicial complexes, and so forth. In each case, the function may be real-valued, or it may take values from a vector space, an affine space, a piecewise linear manifold, or a simplicial complex. (In these contexts, the term “linear” does not refer solely to linear transformations, but to more general affine linear functions.) | ||
+ | |||
+ | In dimensions higher than one, it is common to require the domain of each piece to be a polygon or polytope. This guarantees that the graph of the function will be composed of polygonal or polytopal pieces. | ||
+ | |||
+ | Important sub-classes of piecewise linear functions include the continuous piecewise linear functions and the convex piecewise linear functions. | ||
+ | In general, for every ''n''-dimensional continuous piecewise linear function <math>f : \mathbb{R}^n \to \mathbb{R}</math>, there is a | ||
+ | : <math>\Pi \in \mathcal{P}(\mathcal{P}(\mathbb{R}^{n+1}))</math> | ||
+ | |||
+ | such that | ||
+ | : <math>f(\vec{x}) = \min_{\Sigma \in \Pi} \max_{(\vec{a}, b) \in \Sigma} \vec{a} \cdot \vec{x} + b.</math> | ||
+ | |||
+ | If <math>f</math> is convex and continuous, then there is a | ||
+ | : <math>\Sigma \in \mathcal{P}(\mathbb{R}^{n+1})</math> | ||
+ | |||
+ | such that | ||
+ | : <math>f(\vec{x}) = \max_{(\vec{a},b) \in \Sigma} \vec{a} \cdot \vec{x} + b.</math> | ||
+ | |||
+ | Splines generalize piecewise linear functions to higher-order polynomials, which are in turn contained in the category of piecewise-differentiable functions, PDIFF. | ||
+ | |||
+ | == Applications == | ||
+ | |||
+ | [[File: R-3VAR1.JPG|thumb|left|Crop response to depth of the watertable]] | ||
+ | [[File:Mustard segm regr no effect.png|thumb|right|Example of crop response to soil salinity]] | ||
+ | |||
+ | In agriculture piecewise regression analysis of measured data is used to detect the range over which growth factors affect the yield and the range over which the crop is not sensitive to changes in these factors. | ||
+ | |||
+ | The image on the left shows that at shallow watertables the yield declines, whereas at deeper (> 7 dm) watertables the yield is unaffected. The graph is made using the method of least squares to find the two segments with the best fit. | ||
+ | |||
+ | The graph on the right reveals that crop yields tolerate a soil salinity up to ECe = 8 dS/m (ECe is the electric conductivity of an extract of a saturated soil sample), while beyond that value the crop production reduces. The graph is made with the method of partial regression to find the longest range of "no effect", i.e. where the line is horizontal. The two segments need not join at the same point. Only for the second segment method of least squares is used. | ||
+ | |||
+ | == Licensing == | ||
+ | Content obtained and/or adapted from: | ||
+ | * [https://en.wikipedia.org/wiki/Piecewise_linear_function Piecewise linear function, Wikipedia] under a CC BY-SA license |
Latest revision as of 22:29, 30 October 2021
In mathematics and statistics, a piecewise linear, PL or segmented function is a real-valued function of a real variable, whose graph is composed of straight-line segments.
Contents
Definition
A piecewise linear function is a function defined on a (possibly unbounded) interval of real numbers, such that there is a collection of intervals on each of which the function is an affine function. If the domain of the function is compact, there needs to be a finite collection of such intervals; if the domain is not compact, it may either be required to be finite or to be locally finite in the reals.
Examples
The function defined by
is piecewise linear with four pieces. The graph of this function is shown to the right. Since the graph of a linear function is a line, the graph of a piecewise linear function consists of line segments and rays. The x values (in the above example −3, 0, and 3) where the slope changes are typically called breakpoints, changepoints, threshold values or knots. As in many applications, this function is also continuous. The graph of a continuous piecewise linear function on a compact interval is a polygonal chain.
A piecewise function is a function that is given by different expressions on different intervals. The graph of is shown on the right. The open circle indicates that the point is not included on the graph and the closed circle indicates that the point is included on the graph. So = 8 not 4.
Other examples of piecewise linear functions include the absolute value function, the sawtooth function, and the floor function.
Fitting to a curve
An approximation to a known curve can be found by sampling the curve and interpolating linearly between the points. An algorithm for computing the most significant points subject to a given error tolerance has been published.
Fitting to data
If partitions, and then breakpoints, are already known, linear regression can be performed independently on these partitions. However, continuity is not preserved in that case, and also there is no unique reference model underlying the observed data. A stable algorithm with this case has been derived.
If partitions are not known, the residual sum of squares can be used to choose optimal separation points. However efficient computation and joint estimation of all model parameters (including the breakpoints) may be obtained by an iterative procedure currently implemented in the package segmented
for the R language.
A variant of decision tree learning called model trees learns piecewise linear functions.
Notation
The notion of a piecewise linear function makes sense in several different contexts. Piecewise linear functions may be defined on n-dimensional Euclidean space, or more generally any vector space or affine space, as well as on piecewise linear manifolds, simplicial complexes, and so forth. In each case, the function may be real-valued, or it may take values from a vector space, an affine space, a piecewise linear manifold, or a simplicial complex. (In these contexts, the term “linear” does not refer solely to linear transformations, but to more general affine linear functions.)
In dimensions higher than one, it is common to require the domain of each piece to be a polygon or polytope. This guarantees that the graph of the function will be composed of polygonal or polytopal pieces.
Important sub-classes of piecewise linear functions include the continuous piecewise linear functions and the convex piecewise linear functions. In general, for every n-dimensional continuous piecewise linear function , there is a
such that
If is convex and continuous, then there is a
such that
Splines generalize piecewise linear functions to higher-order polynomials, which are in turn contained in the category of piecewise-differentiable functions, PDIFF.
Applications
In agriculture piecewise regression analysis of measured data is used to detect the range over which growth factors affect the yield and the range over which the crop is not sensitive to changes in these factors.
The image on the left shows that at shallow watertables the yield declines, whereas at deeper (> 7 dm) watertables the yield is unaffected. The graph is made using the method of least squares to find the two segments with the best fit.
The graph on the right reveals that crop yields tolerate a soil salinity up to ECe = 8 dS/m (ECe is the electric conductivity of an extract of a saturated soil sample), while beyond that value the crop production reduces. The graph is made with the method of partial regression to find the longest range of "no effect", i.e. where the line is horizontal. The two segments need not join at the same point. Only for the second segment method of least squares is used.
Licensing
Content obtained and/or adapted from:
- Piecewise linear function, Wikipedia under a CC BY-SA license