更改矩阵样式

更改矩阵样式

我有以下矩阵及其相应的代码。附图显示了输出。由于我必须将该图像放入学术论文中,我认为我的实际设计在风格方面有点过分,也就是说,我需要让它看起来更“数学化”。

\documentclass{standalone}
%\usepackage[showframe]{geometry}
\usepackage{tikz}
\definecolor{gris}{RGB}{250,250,250}
\usepackage{lmodern}
\usetikzlibrary{matrix,
    positioning}
\tikzset{
    mymatrix/.style = {matrix of nodes,
        nodes in empty cells,
        nodes={minimum height=3ex, minimum width=1em,
            inner sep=0pt, outer sep=0pt, anchor=center,
            draw, very thin,scale=0.8,transform shape},
        column sep=0pt,
        row sep=0pt,
        inner sep=0.5\pgflinewidth, outer sep=1pt,
        draw, thick},
    empty node/.style = {draw,fill=gris},
    every label/.append style = {font=\large, text=teal}
}
\makeatletter
\def\tikz@lib@matrix@empty@cell{%
    \iftikz@lib@matrix@empty%
    \node[name=\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn,empty node]{};\fi}
\makeatother

\usepackage{bm}
\newcommand{\MatrixVariable}[1]{\bm{{#1}}}

\begin{document}

    \begin{tikzpicture}[node distance=0pt,scale=0.6,nodes={transform
        shape}]
    \matrix (m1) [mymatrix,
    label={[rotate=90, anchor=south,black]left: Movies},
    label={[black]below:$\MatrixVariable{{R}}$},
    label={[black]above:Users},
    nodes={fill=gray!30}]
    {
        1   &   & 3 &   &   & 5 &   &   & 5 &   & 4 &   \\
        &   & 5 & 4 &   &   & 4 &   &   & 2 & 1 & 3 \\
        2   & 4 &   & 1 & 2 &   & 3 &   & 4 & 3 & 5 &   \\
        & 2 & 4 &   & 5 &   &   & 4 &   &   & 2 &   \\
        &   & 4 & 3 & 4 & 2 &   &   &   &   & 2 & 5 \\
        1   &   & 3 &   & 3 &   &   & 2 &   &   & 4 &   \\
    };
    \node (approx) [right=of m1,scale=2] {$\approx$};
    \matrix (m2) [mymatrix=none, right=0.1em of approx,
    label={[rotate=90, anchor=south east,xshift=-0.7em,black]left: Movies},
    label={[black]below:$\MatrixVariable{{Q}}$},
    label={[black]above:$f$-factors},
    nodes={minimum width=2.2em,fill=white}]
    {
        0.1& -0.4  & -0.2 \\
        -0.5& 0.6 & 0.5 \\
        -0.2& 0.3 &0.5  \\
        1.1& 2.1 & 0.3 \\
        -0.7&2.1  & -2 \\
        -1& 0.7 & 0.3 \\
    };
    \node (times) [right=of m2,scale=2] {$\cdot$};
    \matrix (m3) [mymatrix=none, right=of times,
    label={[rotate=90, anchor=north,black]right: $f$-factors},
    label={[black]below:$\MatrixVariable{{P}^{T}}$},
    label={[black]above:Users},
    nodes={minimum width=2em,fill=white}]
    {
        1.1&-2  & 0.3 & 0.5 &-2  &  -0.5 & 0.8 & -0.4 & 0.3 & 1.4 & 2.4 &  -0.9\\
        -0.8& 0.7 & 0.5 & 1.4 &0.3  & -1 & 1.4 & 2.9 & 0.7 & - 1.2 & 1.3& 0.4\\
        2.1& -0.4 & 0.6 & 1.7 & 2.4 & 0.9 & -0.3 & 0.4 &  0.8 &   0.7 & -0.6&0.1 \\
    };
    \end{tikzpicture}

\end{document}

在此处输入图片描述

我的想法是这样的:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \[
    \begin{pmatrix}
    x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
    x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
    \hdotsfor{5} \\
    x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
    \end{pmatrix}
    =
    \begin{pmatrix}
    x_{11} & x_{12} & x_{13} & \dots  & x_{1n} \\
    x_{21} & x_{22} & x_{23} & \dots  & x_{2n} \\
    \vdots & \vdots & \vdots & \ddots & \vdots \\
    x_{d1} & x_{d2} & x_{d3} & \dots  & x_{dn}
    \end{pmatrix}
    \]
\end{document}

在此处输入图片描述

我对电影、用户和因素标签有些困惑。你能帮我解决这个问题吗?

ps:我也想到了这一点,但如果能增加更多的 k 因子就更好了:

在此处输入图片描述

答案1

使用arrayrotatebox

在此处输入图片描述

平均能量损失

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\begin{document}
\[\begin{array}{ccc}
 \text{Users} & &  \text{factors}\\
    \rotatebox[origin=c]{90}{\text{Movies}}
    \begin{pmatrix}
    x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
    x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
    \hdotsfor{5} \\
    x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
    \end{pmatrix}
    &=&
    \rotatebox[origin=c]{90}{\text{Movies}}
    \begin{pmatrix}
    x_{11} & x_{12} & x_{13} & \dots  & x_{1n} \\
    x_{21} & x_{22} & x_{23} & \dots  & x_{2n} \\
    \vdots & \vdots & \vdots & \ddots & \vdots \\
    x_{d1} & x_{d2} & x_{d3} & \dots  & x_{dn}
    \end{pmatrix}
\end{array}\]
\end{document}

答案2

也许你喜欢:

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \[
    \underbrace{\!
    \begin{pmatrix}
    x_{11} & x_{12} & \dots  & x_{1n} \\
    x_{21} & x_{22} & \dots  & x_{2n} \\
    \vdots & \vdots & \ddots & \vdots \\
    x_{d1} & x_{d2} & \dots  & x_{dn}
    \end{pmatrix}\!
    }_{\mathbf{R}_{\text{Movies}\times \text{Users}}}
    \approx
    \underbrace{\!
    \begin{pmatrix}
    y_{11} & y_{12} & \dots  & y_{1n} \\
    y_{21} & y_{22} & \dots  & y_{2n} \\
    \vdots & \vdots & \ddots & \vdots \\
    y_{d1} & y_{d2} & \dots  & y_{dn}
    \end{pmatrix}\!
    }_{\mathbf{Q}_{\text{Movies}\times f\text{-factors}}}
    \cdot
    \underbrace{
    \begin{pmatrix}\!
    z_{11} & z_{12} & \dots  & z_{1n} \\
    z_{21} & z_{22} & \dots  & z_{2n} \\
    \vdots & \vdots & \ddots & \vdots \\
    z_{d1} & z_{d2} & \dots  & z_{dn}
    \end{pmatrix}\!
    }_{\mathbf{P}^T_{f\text{-factors}\times\text{Users}}}
    \]
\end{document}

相关内容