В этом примере мы покажем, как решать простые задачи из области линейной алгебры – нахождение детерминанта, перемножение матриц и SVG факторизацию.
Для начала, пожалуйста, запустите подготовительную ячейку с кодом.
Нахождение детерминанта матрицы¶
Найдите детерминант матрицы $\left [ \begin{array}{cc}1 & 2 & 3 \\4 & 1 & 6 \\ 7 & 8 & 1 \end{array} \right ]$
Перемножение матриц¶
Найдите координаты точки (1,2,0) при повороте вокруг оси Z на угол $90^{\circ}$.
[-2.0, 1.0000000000000002, 0.0]
Снижение размерности матрицы через факторизацию¶
Дана матрица признаков трёх объектов:
$A = \left [ \begin{array}{cc}1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\
11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20\\
21 & 22 & 23 & 24 & 25 & 26 & 27 & 28 & 29 & 30 \end{array} \right ]$
Столбцы содержат признаки объектов, но в них содержится избыточная информация. Выполните снижение размерности до двух переменных при помощи SVD и дополнительных операций. Конкретные шаги алгоритма:
- Разложите матрицу на компоненты
U, s, VT
при помощи функции svd()
.
- Создайте нулевую матрицу
Sigma
того же размера, что и матрица A
, и заполните ее главную диагональ элементами вектора S
.
- Отделите 2 столбца матрицы
Sigma
и 2 строки матрицы V
, чтобы найти проекцию матрицы в пространство сниженной размерности при помощи команд T = U * Sigma
.
Out[0]:
3×2 Matrix{Float64}:
-18.5216 6.47697
-49.8131 1.91182
-81.1046 -2.65333
Out[0]:
3×3 Matrix{Float64}:
2.80454 7.16027 12.4563
11.5326 25.8784 22.6968
20.2608 44.5964 32.9373
{"id": "44d99da5-ee4e-4124-a6b2-e7e4570582fb", "data": [{"showlegend": true, "mode": "markers", "xaxis": "x", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y", "zaxis": "z", "legendgroup": "y1", "z": [0], "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [2], "type": "scatter3d", "scene": "scene", "x": [1]}], "config": {"showlegend": false, "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "annotations": [], "height": 500, "margin": {"l": 0, "b": 20, "r": 0, "t": 20}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "scene": {"camera": {"up": {"x": 0, "y": 0, "z": 1}, "center": {"x": 0, "y": 0, "z": 0}, "eye": {"x": 1.2883056996112483, "y": -1.5101087427261743, "z": 1.0285409634817124}, "projection": {"type": "perspective"}}, "xaxis": {"tickangle": 0, "showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "gridwidth": 0.5, "visible": true, "ticks": "inside", "range": [-1.073132491389208, 2.0731324913892077], "tickmode": "array", "tickvals": [-1, 0, 1, 2], "tickcolor": "rgba(0, 0, 0, 0)", "ticktext": ["-1", "0", "1", "2"], "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "zeroline": true, "type": "linear", "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "zerolinecolor": "rgba(0, 0, 0, 1)", "mirror": false}, "domain": {"y": [0.03762029746281716, 0.9901574803149606], "x": [0.05100612423447075, 0.9934383202099736]}, "yaxis": {"tickangle": 0, "showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "gridwidth": 0.5, "visible": true, "ticks": "inside", "range": [-0.06000000000000005, 2.06], "tickmode": "array", "tickvals": [0, 0.5, 1, 1.5, 2], "tickcolor": "rgba(0, 0, 0, 0)", "ticktext": ["0.0", "0.5", "1.0", "1.5", "2.0"], "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "zeroline": true, "type": "linear", "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "zerolinecolor": "rgba(0, 0, 0, 1)", "mirror": false}, "zaxis": {"tickangle": 0, "showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "gridwidth": 0.5, "visible": true, "ticks": "inside", "range": [-0.030000000000000027, 1.03], "tickmode": "array", "tickvals": [0, 0.25, 0.5, 0.75, 1], "tickcolor": "rgba(0, 0, 0, 0)", "ticktext": ["0.00", "0.25", "0.50", "0.75", "1.00"], "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "zeroline": true, "type": "linear", "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "zerolinecolor": "rgba(0, 0, 0, 1)", "mirror": false}, "aspectratio": {"x": 1, "y": 1, "z": 1}, "aspectmode": "auto"}, "width": 736.640625}}
{"id": "8f726af1-0bb6-4751-8ebe-61bf140dd593", "data": [{"showlegend": true, "mode": "markers", "xaxis": "x", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y", "zaxis": "z", "legendgroup": "y1", "z": [0], "marker": {"symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [2], "type": "scatter3d", "scene": "scene", "x": [1]}, {"showlegend": true, "mode": "markers", "xaxis": "x", "colorbar": {"title": {"text": ""}}, "name": "y2", "zmin": null, "yaxis": "y", "zaxis": "z", "legendgroup": "y2", "z": [0], "marker": {"symbol": "circle", "color": "rgba(227, 111, 71, 1.000)", "line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "size": 8}, "zmax": null, "y": [1.0000000000000002], "type": "scatter3d", "scene": "scene", "x": [-2]}], "config": {"showlegend": false, "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "annotations": [], "height": 500, "margin": {"l": 0, "b": 20, "r": 0, "t": 20}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "scene": {"camera": {"up": {"x": 0, "y": 0, "z": 1}, "center": {"x": 0, "y": 0, "z": 0}, "eye": {"x": 1.9715572022580123, "y": -1.3426762553071998, "z": 1.0344963371896456}, "projection": {"type": "perspective"}}, "xaxis": {"tickangle": 0, "showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "gridwidth": 0.5, "visible": true, "ticks": "inside", "range": [-2.09, 1.09], "tickmode": "array", "tickvals": [-2, -1, 0, 1], "tickcolor": "rgba(0, 0, 0, 0)", "ticktext": ["-2", "-1", "0", "1"], "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "zeroline": true, "type": "linear", "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "zerolinecolor": "rgba(0, 0, 0, 1)", "mirror": false}, "domain": {"y": [0.03762029746281716, 0.9901574803149606], "x": [0.05100612423447069, 0.9934383202099737]}, "yaxis": {"tickangle": 0, "showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "gridwidth": 0.5, "visible": true, "ticks": "inside", "range": [-0.07136557742294825, 2.0713655774229482], "tickmode": "array", "tickvals": [0, 0.5, 1, 1.5, 2], "tickcolor": "rgba(0, 0, 0, 0)", "ticktext": ["0.0", "0.5", "1.0", "1.5", "2.0"], "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "zeroline": true, "type": "linear", "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "zerolinecolor": "rgba(0, 0, 0, 1)", "mirror": false}, "zaxis": {"tickangle": 0, "showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "gridwidth": 0.5, "visible": true, "ticks": "inside", "range": [-0.030000000000000027, 1.03], "tickmode": "array", "tickvals": [0, 0.25, 0.5, 0.75, 1], "tickcolor": "rgba(0, 0, 0, 0)", "ticktext": ["0.00", "0.25", "0.50", "0.75", "1.00"], "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "zeroline": true, "type": "linear", "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "zerolinecolor": "rgba(0, 0, 0, 1)", "mirror": false}, "aspectratio": {"x": 2.0800838230519045, "y": 0.6933612743506347, "z": 0.6933612743506348}, "aspectmode": "auto"}, "width": 736.640625}}