В этом примере мы покажем, как решать простые задачи из области линейной алгебры – нахождение детерминанта, перемножение матриц и 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": [{"xaxis": "x", "mode": "markers", "x": [1], "showlegend": true, "name": "y1", "colorbar": {"title": {"text": ""}}, "zmin": null, "z": [0], "legendgroup": "y1", "y": [2], "zaxis": "z", "zmax": null, "scene": "scene", "yaxis": "y", "marker": {"line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "size": 8}, "type": "scatter3d"}], "config": {"showlegend": false, "height": 500, "annotations": [], "scene": {"zaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["0.00", "0.25", "0.50", "0.75", "1.00"], "range": [-0.030000000000000027, 1.03], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [0, 0.25, 0.5, 0.75, 1], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "aspectratio": {"x": 1, "z": 1, "y": 1}, "camera": {"eye": {"x": 1.2883056996112483, "z": 1.0285409634817124, "y": -1.5101087427261743}, "center": {"x": 0, "z": 0, "y": 0}, "projection": {"type": "perspective"}, "up": {"x": 0, "z": 1, "y": 0}}, "xaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["-1", "0", "1", "2"], "range": [-1.073132491389208, 2.0731324913892077], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [-1, 0, 1, 2], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "domain": {"x": [0.05100612423447075, 0.9934383202099736], "y": [0.03762029746281716, 0.9901574803149606]}, "yaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["0.0", "0.5", "1.0", "1.5", "2.0"], "range": [-0.06000000000000005, 2.06], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [0, 0.5, 1, 1.5, 2], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "aspectmode": "auto"}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "margin": {"t": 20, "b": 20, "r": 0, "l": 0}, "width": 736.640625}}
{"id": "8f726af1-0bb6-4751-8ebe-61bf140dd593", "data": [{"xaxis": "x", "mode": "markers", "x": [1], "showlegend": true, "name": "y1", "colorbar": {"title": {"text": ""}}, "zmin": null, "z": [0], "legendgroup": "y1", "y": [2], "zaxis": "z", "zmax": null, "scene": "scene", "yaxis": "y", "marker": {"line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "size": 8}, "type": "scatter3d"}, {"xaxis": "x", "mode": "markers", "x": [-2], "showlegend": true, "name": "y2", "colorbar": {"title": {"text": ""}}, "zmin": null, "z": [0], "legendgroup": "y2", "y": [1.0000000000000002], "zaxis": "z", "zmax": null, "scene": "scene", "yaxis": "y", "marker": {"line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "symbol": "circle", "color": "rgba(227, 111, 71, 1.000)", "size": 8}, "type": "scatter3d"}], "config": {"showlegend": false, "height": 500, "annotations": [], "scene": {"zaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["0.00", "0.25", "0.50", "0.75", "1.00"], "range": [-0.030000000000000027, 1.03], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [0, 0.25, 0.5, 0.75, 1], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "aspectratio": {"x": 2.0800838230519045, "z": 0.6933612743506348, "y": 0.6933612743506347}, "camera": {"eye": {"x": 1.9715572022580123, "z": 1.0344963371896456, "y": -1.3426762553071998}, "center": {"x": 0, "z": 0, "y": 0}, "projection": {"type": "perspective"}, "up": {"x": 0, "z": 1, "y": 0}}, "xaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["-2", "-1", "0", "1"], "range": [-2.09, 1.09], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [-2, -1, 0, 1], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "domain": {"x": [0.05100612423447069, 0.9934383202099737], "y": [0.03762029746281716, 0.9901574803149606]}, "yaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["0.0", "0.5", "1.0", "1.5", "2.0"], "range": [-0.07136557742294825, 2.0713655774229482], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [0, 0.5, 1, 1.5, 2], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "aspectmode": "auto"}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "margin": {"t": 20, "b": 20, "r": 0, "l": 0}, "width": 736.640625}}