网格搜索与随机搜索或如何在 tikz 中的矩阵附近绘制多个函数

网格搜索与随机搜索或如何在 tikz 中的矩阵附近绘制多个函数

我想创建一个像这样的 tikz 图片:

在此处输入图片描述

我拥有的是:

\documentclass[border=1.5mm]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}

\begin{document}

\begin{tikzpicture}
\draw[step=1.5] (0,-4.5) grid (4.5,0);
\foreach \x in {0,...,3}
{   \foreach \y in {0,...,3}
    {   \pgfmathtruncatemacro{\nodelabel}{\x+\y*5+1}
        \node[circle,draw=black,fill=white!80!black,minimum size=10] (\nodelabel) at (1.5*\x,-1.5*\y) {};
    }
}
\end{tikzpicture}

\end{document}

上面的输出是: 在此处输入图片描述

我怎样才能绘制这两个附加图?

答案1

\documentclass[border=1.5mm]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}



\begin{document}

\newcommand{\leftcoords}{(-2, 5) (-2.1, 4) (-2.1, 3) (-1.9, 2) (-1.8, 1) (-2, 0) (-2, -1)}
\begin{tikzpicture}


\draw[thick] plot [smooth]  coordinates  \leftcoords ;
\fill[cyan!50]   plot [smooth] coordinates  \leftcoords -- (-1,-1) -- (-1,5) -- (-2,5);

\draw (-1,-1) rectangle (5,5);
\foreach \i in {0,2,4}
{
    \foreach \j in {0,2,4}
    {
        \fill[gray, draw=black] (\i,\j) circle (0.15);
    }
}


\end{tikzpicture}


\begin{tikzpicture}

\draw[thick] plot [smooth]  coordinates  \leftcoords ;
\fill[cyan!50]   plot [smooth] coordinates  \leftcoords -- (-1,-1) -- (-1,5) -- (-2,5);

\draw (-1,-1) rectangle (5,5);
\foreach \i in {0,2,4}
{
    \foreach \j in {0,2,4}
    {
        \fill[gray, draw=black] ({\i + rand},{\j + abs(rand)}) circle (0.15);
    }
}
\end{tikzpicture}


\end{document}

您可以使用坐标改变左侧曲线的形状。同样,您可以制作上方的曲线。 在此处输入图片描述

答案2

在@sergiokapone 的帮助下,我能够创建我想要的东西:

\documentclass[border=1.5mm]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}

\begin{document}

\newcommand{\leftcoords}{(-2, 5) (-2.1, 4) (-2.1, 3) (-1.9, 2) (-1.8, 1) (-2, 0) (-2, -1)}
\newcommand{\rightcoords}{(5, 6) (4, 6.1) (3, 5.5) (2, 6.9) (1, 6.8) (0, 6) (-1, 6)}

\begin{tikzpicture}
\draw[thick] plot [smooth]  coordinates  \leftcoords ;
\fill[MidnightBlue!20]   plot [smooth] coordinates  \leftcoords -- (-1,-1) -- (-1,5) -- (-2,5);

\draw[thick] plot [smooth]  coordinates  \rightcoords ;
\fill[MidnightBlue!20]   plot [smooth] coordinates  \rightcoords -- (-1,-0) -- (-1,5) -- (5,5);

\draw (-1,-1) rectangle (5,5);

%\draw (0,0) -- (0,4);
%\draw (2,0) -- (2,4);
%\draw (4,0) -- (4,4);

%\draw (0,0) -- (4,0);
%\draw (0,2) -- (4,2);
%\draw (0,4) -- (4,4);

\foreach \i in {0,2,4}
{
    \foreach \j in {0,2,4}
    {
        \fill[gray, draw=black] (\i,\j) circle (0.15);
    }
}

\fill[gray, draw=black] (4,6.1) circle (0.15);
\fill[gray, draw=black] (2,6.9) circle (0.15);
\fill[gray, draw=black] (0,6) circle (0.15);

\node at (2,7.5) {Grid-Search};
\node at (2,-1.5) {Wichtiger Hyperparameter};
\node[rotate=90] at (-2.5,2) {Unichtiger Hyperparameter};
\end{tikzpicture}


\begin{tikzpicture}
\draw[thick] plot [smooth]  coordinates  \leftcoords ;
\fill[MidnightBlue!20]   plot [smooth] coordinates  \leftcoords -- (-1,-1) -- (-1,5) -- (-2,5);

\draw[thick] plot [smooth]  coordinates  \rightcoords ;
\fill[MidnightBlue!20]   plot [smooth] coordinates  \rightcoords -- (-1,-0) -- (-1,5) -- (5,5);

\draw (-1,-1) rectangle (5,5);

%\foreach \i in {1,2.5,4}
%{
%    \foreach \j in {0,2.4,3}
%    {
%        \fill[gray, draw=black] ({\i + rand},{\j + abs(rand)}) circle (0.15);
%        \fill[gray, draw=black] ({\i + rand},{6 + abs(rand)}) circle (0.15);
%    }
%}

\fill[gray, draw=black] (3.1,5.5) circle (0.15);
\fill[gray, draw=black] (3.1,3.5) circle (0.15);

\fill[gray, draw=black] (4.2,6.1) circle (0.15);
\fill[gray, draw=black] (4.2,2.7) circle (0.15);

\fill[gray, draw=black] (3.9,6.0) circle (0.15);
\fill[gray, draw=black] (3.9,1.5) circle (0.15);

\fill[gray, draw=black] (1.9,6.95) circle (0.15);
\fill[gray, draw=black] (1.9,3.95) circle (0.15);

\fill[gray, draw=black] (1.1,6.85) circle (0.15);
\fill[gray, draw=black] (1.1,2.85) circle (0.15);

\fill[gray, draw=black] (-0.25,6.0) circle (0.15);
\fill[gray, draw=black] (-0.25,3.0) circle (0.15);

\fill[gray, draw=black] (0.5,6.4) circle (0.15);
\fill[gray, draw=black] (0.5,2.0) circle (0.15);

\fill[gray, draw=black] (1.2,6.9) circle (0.15);
\fill[gray, draw=black] (1.2,1.5) circle (0.15);

\fill[gray, draw=black] (1.5,6.9) circle (0.15);
\fill[gray, draw=black] (1.5,1.9) circle (0.15);

\node at (2,7.5) {Random-Search};
\node at (2,-1.5) {Wichtiger Hyperparameter};
\node[rotate=90] at (-2.5,2) {Unichtiger Hyperparameter};
\end{tikzpicture}

\end{document}

输出: 在此处输入图片描述

相关内容