🧮 Mathematik zu ML und AI

Verallgemeinertes Skalarprodukt

Wie eine symmetrisch positiv definite Matrix A jedes Standard-Skalarprodukt zu einer ganzen Familie gültiger Skalarprodukte erweitert.

Allgemeine Form des Skalarprodukts

Ein Skalarprodukt auf dem Rn\mathbb{R}^n lässt sich über eine symmetrisch positiv definite Matrix A\mathbf{A} definieren:

Die verallgemeinerte Definition

x,y=xAy\langle \mathbf{x}, \mathbf{y} \rangle = \mathbf{x}^\top \mathbf{A}\, \mathbf{y}

Das Standard-Skalarprodukt (Punktprodukt) ist der Spezialfall A=I\mathbf{A} = \mathbf{I} (Einheitsmatrix): xy=x1y1+x2y2\mathbf{x} \cdot \mathbf{y} = x_1 y_1 + x_2 y_2. Gleichung 3.19 wählt ein konkretes AI\mathbf{A} \neq \mathbf{I} und liefert damit ein anderes, ebenso gültiges Skalarprodukt.

Gleichung 3.19 — das konkrete Beispiel

Die Matrix A\mathbf{A} lautet:

A=(112121)\mathbf{A} = \begin{pmatrix} 1 & -\tfrac{1}{2} \\[4pt] -\tfrac{1}{2} & 1 \end{pmatrix}

Eingesetzt in xAy\mathbf{x}^\top \mathbf{A}\, \mathbf{y} ergibt sich die rechte Seite von 3.19:

x,y=x1y112(x1y2+x2y1)+x2y2\langle \mathbf{x}, \mathbf{y} \rangle = x_1 y_1 - \tfrac{1}{2}\bigl(x_1 y_2 + x_2 y_1\bigr) + x_2 y_2

Der Unterschied zum Punktprodukt ist der Mischterm 12(x1y2+x2y1)-\tfrac{1}{2}(x_1 y_2 + x_2 y_1). Die Matrix A\mathbf{A} ist symmetrisch und positiv definit (Eigenwerte 34\tfrac{3}{4} und 12\tfrac{1}{2}) — daher ist dies ein gültiges Skalarprodukt.

Schritt für Schritt: x⊤ A y

Dank der Assoziativität der Matrixmultiplikation gilt (xA)y=x(Ay)(\mathbf{x}^\top \mathbf{A})\,\mathbf{y} = \mathbf{x}^\top (\mathbf{A}\,\mathbf{y}). Man kann die Klammern frei setzen — die Faktoren bleiben in ihrer Reihenfolge.

Schritt 1 — xAx^\top \cdot A (Zeile × Matrix)

x\mathbf{x}^\top ist ein Zeilenvektor (1×21\times2), A\mathbf{A} eine 2×22\times2-Matrix. Das Ergebnis ist wieder ein Zeilenvektor (1×21\times2):

xA=(x112x212x1+x2)\mathbf{x}^\top \mathbf{A} = \begin{pmatrix} x_1 - \tfrac{1}{2}x_2 & -\tfrac{1}{2}x_1 + x_2 \end{pmatrix}

Schritt 2 — AyA \cdot y (Matrix × Spalte)

A\mathbf{A} ist 2×22\times2, y\mathbf{y} ein Spaltenvektor (2×12\times1). Das Ergebnis ist wieder ein Spaltenvektor (2×12\times1):

Ay=(y112y212y1+y2)\mathbf{A}\,\mathbf{y} = \begin{pmatrix} y_1 - \tfrac{1}{2}y_2 \\[4pt] -\tfrac{1}{2}y_1 + y_2 \end{pmatrix}

Schritt 3 — finales Skalarprodukt

Der Zeilenvektor aus Schritt 1 wird mit dem Spaltenvektor aus Schritt 2 multipliziert. Das Ergebnis ist ein Skalar:

x(Ay)=x1y112(x1y2+x2y1)+x2y2\mathbf{x}^\top(\mathbf{A}\,\mathbf{y}) = x_1 y_1 - \tfrac{1}{2}\bigl(x_1 y_2 + x_2 y_1\bigr) + x_2 y_2

Dimensionen auf einen Blick

AusdruckFormatErgebnis
x\mathbf{x}^\top1×21\times2 (Zeile)
A\mathbf{A}2×22\times2 (Matrix)
y\mathbf{y}2×12\times1 (Spalte)
xA\mathbf{x}^\top \cdot \mathbf{A}1×22×21\times2 \cdot 2\times21×21\times2 (Zeile)
(xA)y(\mathbf{x}^\top\mathbf{A}) \cdot \mathbf{y}1×22×11\times2 \cdot 2\times11×11\times1 (Skalar)
Ay\mathbf{A} \cdot \mathbf{y}2×22×12\times2 \cdot 2\times12×12\times1 (Spalte)
x(Ay)\mathbf{x}^\top \cdot (\mathbf{A}\,\mathbf{y})1×22×11\times2 \cdot 2\times11×11\times1 (Skalar)

Gleichung 3.20 — konkretes Zahlenbeispiel

Wir setzen den konkreten Vektor x=y=(1,1)\mathbf{x} = \mathbf{y} = (1, 1)^\top ein und vergleichen seine Länge unter beiden Skalarprodukten. Der einzige Unterschied ist der Mischterm x1x2-x_1 x_2 aus 3.19.

Norm unter dem neuen Skalarprodukt (3.19)

x,x=1211Mischterm+12=1xA=1=1\langle \mathbf{x}, \mathbf{x} \rangle = 1^2 - \underbrace{1\cdot 1}_{\text{Mischterm}} + 1^2 = 1 \quad\Longrightarrow\quad \lVert \mathbf{x} \rVert_{\mathbf{A}} = \sqrt{1} = 1
Standard-Punktprodukt zum Vergleich:  x,x=12+12=2    x=21,41\langle \mathbf{x}, \mathbf{x} \rangle = 1^2 + 1^2 = 2 \;\Rightarrow\; \lVert \mathbf{x} \rVert = \sqrt{2} \approx 1{,}41

Derselbe Vektor misst unter 3.19 die Länge 11 statt 2\sqrt{2} — er ist also kürzer. Der Mischterm x1x2-x_1 x_2 zählt hier 1-1 und zieht das Quadrat der Norm von 22 auf 11 herunter.

Warum ist er kürzer?

Für x,x\langle \mathbf{x}, \mathbf{x} \rangle setzt man y=x\mathbf{y} = \mathbf{x}:

x,x=x12x1x2+x22=(x12+x22)x1x2\langle \mathbf{x}, \mathbf{x} \rangle = x_1^2 - x_1 x_2 + x_2^2 = \bigl(x_1^2 + x_2^2\bigr) - x_1 x_2

Der Mischterm entscheidet, ob die Norm gegenüber dem Standard wächst oder schrumpft:

FallMischtermNorm vs. Standard
x1x2>0x_1 x_2 > 0 (gleiches Vorzeichen)wird subtrahiertkleiner (kürzer)
x1x2<0x_1 x_2 < 0 (verschiedene Vorzeichen)wird addiertgrößer (länger)

Schlüsselbegriffe

Die wichtigsten Begriffe

Assoziativität

(xA)y=x(Ay)(\mathbf{x}^\top\mathbf{A})\,\mathbf{y} = \mathbf{x}^\top(\mathbf{A}\,\mathbf{y}) — die Klammerung ist frei wählbar, die Reihenfolge der Faktoren bleibt erhalten.

Kommutativität

Gilt für Matrizen nicht: ABBA\mathbf{A}\mathbf{B} \neq \mathbf{B}\mathbf{A} im Allgemeinen.

Spaltenvektoren

x\mathbf{x} und y\mathbf{y} sind per Konvention Spalten (n×1n\times1). x\mathbf{x}^\top macht daraus eine Zeile (1×n1\times n).

Positiv definit

x,x>0\langle \mathbf{x}, \mathbf{x} \rangle > 0 für alle x0\mathbf{x} \neq \mathbf{0} — die Voraussetzung für ein gültiges Skalarprodukt.

Quelle: Deisenroth, Faisal & Ong — Mathematics for Machine Learning, Cambridge University Press 2020, Kapitel 3 (mml-book.com).