quimb.linalg.rand_linalg ======================== .. py:module:: quimb.linalg.rand_linalg .. autoapi-nested-parse:: Randomized iterative methods for decompositions. Functions --------- .. autoapisummary:: quimb.linalg.rand_linalg.lu_orthog quimb.linalg.rand_linalg.qr_orthog quimb.linalg.rand_linalg.orthog quimb.linalg.rand_linalg.QB_to_svd quimb.linalg.rand_linalg.trim quimb.linalg.rand_linalg.possibly_extend_randn quimb.linalg.rand_linalg.isstring quimb.linalg.rand_linalg.rsvd_qb quimb.linalg.rand_linalg.rsvd_core quimb.linalg.rand_linalg.is_sorted quimb.linalg.rand_linalg.gen_k_steps quimb.linalg.rand_linalg.rsvd_iterate quimb.linalg.rand_linalg.count_svdvals_needed quimb.linalg.rand_linalg.isdouble quimb.linalg.rand_linalg.estimate_rank quimb.linalg.rand_linalg.maybe_flip quimb.linalg.rand_linalg.rsvd Module Contents --------------- .. py:function:: lu_orthog(X) .. py:function:: qr_orthog(X) .. py:function:: orthog(X, lu=False) .. py:function:: QB_to_svd(Q, B, compute_uv=True) .. py:function:: trim(arrays, k) .. py:function:: possibly_extend_randn(G, k, p, A) .. py:function:: isstring(x, s) .. py:function:: rsvd_qb(A, k, q, p, state, AH=None) .. py:function:: rsvd_core(A, k, compute_uv=True, q=2, p=0, state=None, AH=None) Core R3SVD algorithm. :param A: Operator to decompose, assumed m >= n. :type A: linear operator, shape (m, n) :param k: Number of singular values to find. :type k: int :param compute_uv: Return the left and right singular vectors. :type compute_uv: bool, optional :param q: Number of power iterations. :type q: int, optional :param p: Over sampling factor. :type p: int, optional :param state: Iterate based on these previous results: - None: basic mode. - array_like: use this as the initial subspace. - 'begin-svd': begin block iterations, return U, s, VH, G - (G0,) : begin block iterations with this subspace - (U0, s0, VH0, G0): continue block iterations, return G :type state: {None, array_like, (), (G0,), (U0, s0, VH0, G0)}, optional .. py:function:: is_sorted(x) .. py:function:: gen_k_steps(start, incr=1.4) .. py:function:: rsvd_iterate(A, eps, compute_uv=True, q=2, p=0, G0=None, k_max=None, k_start=2, k_incr=1.4, AH=None, use_qb=20) Handle rank-adaptively calling ``rsvd_core``. .. py:function:: count_svdvals_needed(s, eps) .. py:function:: isdouble(dtype) Check if ``dtype`` is double precision. .. py:function:: estimate_rank(A, eps, k_max=None, use_sli=True, k_start=2, k_incr=1.4, q=0, p=0, get_vectors=False, G0=None, AH=None, use_qb=20) Estimate the rank of an linear operator. Uses a low quality random SVD with a resolution of ~ 10. :param A: The operator to find rank of. :type A: linear operator :param eps: Find rank to this relative (compared to largest singular value) precision. :type eps: float :param k_max: The maximum rank to find. :type k_max: int, optional :param use_sli: Whether to use :func:`scipy.linalg.interpolative.estimate_rank` if possible (double precision and no ``k_max`` set). :type use_sli: bool, optional :param k_start: Begin the adaptive SVD with a block of this size. :type k_start: int, optional :param k_incr: Adaptive rank increment factor. Increase the k-step (from k_start) by this factor each time. Set to 1 to use a constant step. :type k_incr: float, optional :param q: Number of power iterations. :type q: int, optional :param get_vectors: Return the right singular vectors found in the pass. :type get_vectors: bool, optional :param G0: :type G0: , optional :returns: * **rank** (*int*) -- The rank. * **VH** (*array*) -- The (adjoint) right singular vectors if ``get_vectors=True``. .. py:function:: maybe_flip(UsV, flipped) .. py:function:: rsvd(A, eps_or_k, compute_uv=True, mode='adapt+block', use_qb=20, q=2, p=0, k_max=None, k_start=2, k_incr=1.4, G0=None, AH=None) Fast, randomized, iterative SVD. Adaptive variant of method due originally to Halko. This scales as ``log(k)`` rather than ``k`` so can be more efficient. :param A: The operator to decompose. :type A: operator, shape (m, n) :param eps_or_k: Either the relative precision or the number of singular values to target. If precision, this is relative to the largest singular value. :type eps_or_k: float or int :param compute_uv: Whether to return the left and right singular vectors. :type compute_uv: bool, optional :param mode: How to perform the randomized SVD. If ``eps_or_k`` is an integer then this is implicitly 'block' and ignored. Else: - 'adapt+block', perform an initial low quality pass to estimate the rank of ``A``, then use the subspace and rank from that to perform an accurate fully blocked RSVD. - 'adapt', just perform the adaptive randomized SVD. :type mode: {'adapt+block', 'adapt', 'block'}, optional :param q: The number of power iterations, increase for accuracy at the expense of runtime. :type q: int, optional :param p: Oversampling factor. Perform projections with this many extra columns and then throw then away. :type p: int, optional :param k_max: Maximum adaptive rank. Default: ``min(A.shape)``. :type k_max: int, optional :param k_start: Initial k when increasing rank adaptively. :type k_start: int, optional :param k_incr: Adaptive rank increment factor. Increase the k-step (from k_start) by this factor each time. Set to 1 to use a constant step. :type k_incr: float, optional :param G0: Initial subspace to start iterating on. If not given a random one will be generated. :type G0: array_like, shape (n, k), optional :returns: * *U, array, shape (m, k)* -- Left singular vectors, if ``compute_uv=True``. * *s, array, shape (k,)* -- Singular values. * *V, array, shape (k, n)* -- Right singular vectors, if ``compute_uv=True``.