使用 TikZ 绘制范数惩罚项的轮廓图

使用 TikZ 绘制范数惩罚项的轮廓图

我想使用 TikZ 包在 $\LaTeX$ 中绘制以下轮廓图。

摘自 Hastie (2015)《稀疏性统计学习》

我用于绘制山脊轮廓图的脚本(=2)和套索回归(=1) 如下。第一个代码块是 ridge (=2),即上图中带有圆圈的第二个图。套索的第二个代码块(=1) 旋转矩形以获得菱形,如第 3 张图所示。

\usepackage{tikz}

\begin{tikzpicture}
\draw[-] (-0.75,0) -- (0.75,0) node[anchor=north west] {$\beta_1$};
\draw[-] (0,-0.75) -- (0,0.75) node[anchor=south east] {$\beta_2$};
\draw[thick] (0,0) circle (0.5cm);
\end{tikzpicture}

\begin{tikzpicture}
\draw[-] (-0.75,0) -- (0.75,0) node[anchor=north west] {$\beta_1$};
\draw[-] (0,-0.75) -- (0,0.75) node[anchor=south east] {$\beta_2$};
\draw[thick,cm={cos(45) ,-sin(45) ,sin(45) ,cos(45),(0,0)}] (-0.4,-0.4) rectangle (0.4,0.4);
\end{tikzpicture}

完成这两个之后,我想知道如何绘制上图中具有非凸和凸几何形状的第 4、第 5 和第 1 个图。最后,我想为弹性网络创建以下图(1 和 2 之间,使用 TikZ:

摘自 Hastie 2009《统计学习要素》

有没有办法制作非凸(捏)几何形状,而无需借助 TikZ 之外的包,就像这样双曲线图? 我知道 TikZ 中有抛物线和圆弧命令,但我认为轮廓图需要控制朝向角落的弯曲程度,具体取决于

答案1

这是用来画卡通的东西。它有一个picfor that 函数,接受一个参数。如果参数大于 0,它更像圆形,如果参数小于 0,它更像十字形(我认为这里凹凸不一)。此外,你可以随意调整。(你也可以将和图片合并axisnorm penalty一个,但我觉得这样限制性更强。)

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[pics/axis/.style={code={
 \draw[-] (-0.75,0) -- (0.75,0) node[anchor=north west] {$\beta_1$};
 \draw[-] (0,-0.75) -- (0,0.75) node[anchor=south east] {$\beta_2$};
 }},pics/norm penalty/.style={code={
 \draw (0,0.5) to[out=-45+#1,in=135-#1] 
 (0.5,0) to[out=-135+#1,in=45-#1] 
 (0,-0.5) to[out=135+#1,in=-45-#1] 
 (-0.5,0) to[out=45+#1,in=-135-#1]  cycle;}}]
\path (0,0) pic{axis} (0,0) pic[blue,thick,looseness=1.5]{norm penalty=45}
(2,0) pic{axis} (2,0) pic[blue,thick,looseness=1]{norm penalty=45}
(4,0) pic{axis} (4,0) pic[blue,thick,looseness=1]{norm penalty=0}
(6,0) pic{axis} (6,0) pic[blue,thick,looseness=1]{norm penalty=-20}
(8,0) pic{axis} (8,0) pic[blue,thick,looseness=2]{norm penalty=-45}
(2,-2) pic{axis} (2,-2) pic[blue,thick,looseness=0.5]{norm penalty=45}
(4,-2) pic{axis} (4,-2) pic[blue,thick,looseness=0.2]{norm penalty=45};
\end{tikzpicture}
\end{document}

在此处输入图片描述

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[pics/axis/.style 2 args={code={
 \draw[-] (-0.75,0) -- (0.75,0) node[anchor=north west] {$\beta_1$};
 \draw[-] (0,-0.75) node[below]{#2}-- (0,0.75) node[anchor=south east] {$\beta_2$}
 node[above=0.4cm] {#1};
 }},pics/norm penalty/.style={code={
 \draw (0,0.5) to[out=-45+#1,in=135-#1] 
 (0.5,0) to[out=-135+#1,in=45-#1] 
 (0,-0.5) to[out=135+#1,in=-45-#1] 
 (-0.5,0) to[out=45+#1,in=-135-#1]  cycle;}}]
\path (0,0) pic{axis={$q=1$}{title 1}} (0,0) pic[blue,thick,looseness=1.5]{norm penalty=45}
(2,0) pic{axis={$q=4$}{title 2}} (2,0) pic[blue,thick,looseness=1]{norm penalty=45}
(4,0) pic{axis={$q=2$}{title 3}} (4,0) pic[blue,thick,looseness=1]{norm penalty=0}
(6,0) pic{axis={$q=0.5$}{title 4}} (6,0) pic[blue,thick,looseness=1]{norm penalty=-20}
(8,0) pic{axis={$q=0.1$}{title 5}} (8,0) pic[blue,thick,looseness=2]{norm penalty=-45}
(2,-3) pic{axis={$q=2$}{title 6}} (2,-3) pic[blue,thick,looseness=0.5]{norm penalty=45}
(4,-3) pic{axis={$q=3$}{title 7}} (4,-3) pic[blue,thick,looseness=0.2]{norm penalty=45};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容