# Singular Value Decomposition¶

This notebook introduces the da.linalg.svd algorithms for the Singular Value Decomposition

## Start Dask Client for Dashboard¶

Starting the Dask Client is optional. It will provide a dashboard which is useful to gain insight on the computation.

The link to the dashboard will become visible when you create the client below. We recommend having it open on one side of your screen while using your notebook on the other side. This can take some effort to arrange your windows, but seeing them both at the same is very useful when learning.

In [ ]:
from dask.distributed import Client, progress
n_workers=1, memory_limit='2GB')
client


## Compute SVD of Tall-and-Skinny Matrix¶

For many applications the provided matrix has many more rows than columns. In this case a specialized algorithm can be used.

In [ ]:
import dask.array as da

X = da.random.random((200000, 100), chunks=(10000, 100)).persist()

In [ ]:
import dask

u, s, v = da.linalg.svd(X)

In [ ]:
v.compute()


## Compute SVD of General Non-Skinny Matrix with Approximate algorithm¶

When there are also many chunks in columns then we use an approximate randomized algorithm to collect only a few of the singular values and vectors.

In [ ]:
import dask.array as da

X = da.random.random((10000, 10000), chunks=(2000, 2000)).persist()

In [ ]:
import dask

u, s, v = da.linalg.svd_compressed(X, k=5)

v.compute()