On the conjugate function
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
In the MAT7381 course (graduate course on regression models), we will talk about optimization, and a classical tool is the so-called conjugate. Given a function f:Rp→R its conjugate is function f⋆:Rp→R such that f⋆(y)=maxx{x⊤y−f(x)}so, long story short, f⋆(y) is the maximum gap between the linear function x⊤y and f(x).
Just to visualize, consider a simple parabolic function (in dimension 1) f(x)=x2/2, then f⋆(2) is the maximum gap between the line x↦2x and function f(x).
x = seq(-100,100,length=6001)
f = function(x) x^2/2
vf = Vectorize(f)(x)
fstar = function(y) max(y*x-vf)
vfstar = Vectorize(fstar)(x)
We can see it on the figure below.
viz = function(x0=1,YL=NA){
idx=which(abs(x)<=3) par(mfrow=c(1,2)) plot(x[idx],vf[idx],type="l",xlab="",ylab="",col="blue",lwd=2) abline(h=0,col="grey") abline(v=0,col="grey") idx2=which(x0*x>=vf)
polygon(c(x[idx2],rev(x[idx2])),c(vf[idx2],rev(x0*x[idx2])),col=rgb(0,1,0,.3),border=NA)
abline(a=0,b=x0,col="red")
i=which.max(x0*x-vf)
segments(x[i],x0*x[i],x[i],f(x[i]),lwd=3,col="red")
if(is.na(YL)) YL=range(vfstar[idx])
plot(x[idx],vfstar[idx],type="l",xlab="",ylab="",col="red",lwd=1,ylim=YL)
abline(h=0,col="grey")
abline(v=0,col="grey")
segments(x0,0,x0,fstar(x0),lwd=3,col="red")
points(x0,fstar(x0),pch=19,col="red")
}
viz(1)
or
viz(1.5)
In that case, we can actually compute f⋆, since f⋆(y)=maxx{xy−f(x)}=maxx{xy−x2/2}The first order condition is here x⋆=y and thusf⋆(y)=maxx{xy−x2/2}={x⋆y−(x⋆)2/2}={y2−y2/2}=y2/2And actually, that can be related to two results. The first one is to observe that f(x)=‖x‖22/2 and in that case f⋆(y)=‖y‖22/2 from the following general result : if f(x)=‖x‖pp/p with p>1, where ‖⋅‖p denotes the standard ℓp norm, then f⋆(y)=‖y‖qq/q where1p+1q=1The second one is the conjugate of a quadratic function. More specifically if f(x)=x⊤Qx/2 for some definite positive matrix Q, f⋆(y)=y⊤Q−1y/2. In our case, it was a univariate problem with Q=1.
For the conjugate of the ℓp norm, we can use the following code to visualize it
p = 3
f = function(x) abs(x)^p/p
vf = Vectorize(f)(x)
fstar = function(y) max(y*x-vf)
vfstar = Vectorize(fstar)(x)
viz(1.5)
or
p = 1.1
f = function(x) abs(x)^p/p
vf = Vectorize(f)(x)
fstar = function(y) max(y*x-vf)
vfstar = Vectorize(fstar)(x)
viz(1, YL=c(0,10))
Actually, in that case, we almost visualize that if f(x)=|x| thenf⋆(y)={0,|y|≤1∞,|y|>1.
To conclude, another popular case, f(x)=exp(x) then{\displaystyle f^{\star}\left(y\right)={{ylog(y)−y,y>00,y=0∞,y<0.
f = function(x) exp(x)
vf = Vectorize(f)(x)
fstar = function(y) max(y*x-vf)
vfstar = Vectorize(fstar)(x)
viz(1,YL=c(-3,3))
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.