Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Many statistical modeling problems reduce to a minimization problem of the general form:
or
where
There are multiple reasons why it can be helpful to check out the contours of such penalty functions
- When
is two-dimensional, the solution of problem (2-3) can be found by simply taking a look at the contours of and . - That builds intuition for what happens in more than two dimensions, and in other more general cases.
- From a Bayesian point of view, problem (1) can often be interpreted as an MAP estimator, in which case the contours of
are also contours of the prior distribution of .
Therefore, it is meaningful to visualize the set of points that
Below you see GIF images of such sets
:white_check_mark: R code to reproduce the GIFs is provided.
p-norms in 2D
First we consider the
with a varying parameter
Elastic net penalty in 2D
The elastic net penalty can be written in the form
for
Fused penalty in 2D
The fused penalty can be written in the form
It encourages neighboring coefficients
(Here I have simply evaluated the fused penalty function on a grid of points in
Sorted L1 penalty in 2D
The Sorted
where
Difference of p-norms
It holds that
or more generally, for all
Thus, it is meaningful to define a penalty function of the form
for
We visualize the same for varying
and we obtain the following GIF.
Hyperbolic tangent penalty in 2D
The hyperbolic tangent penalty, which is for example used in the method of variable selection via subtle uprooting (Su, 2015), has the form
Code
The R code uses the libraries dplyr
for data manipulation, ggplot2
for generation of figures, and magick
to combine the individual images into a GIF.
Here are the R scripts that can be used to reproduce the above GIFs:
- p-norms in 2D
- Elastic net penalty in 2D
- Fused penalty in 2D
- Sorted L1 penalty in 2D
- Difference of
-norms: in 2D - Difference of
-norms: in 2D - Hyperbolic tangent penalty
Should I come across other interesting penalty functions that make sense in 2D, then I will add corresponding further visualizations to the same Github repository.
< size="3">This work is licensed under a Creative Commons Attribution 4.0 International License. < >
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.