# Request minimum rank in LowRankApprox.jl?

**URL:** https://discourse.julialang.org/t/request-minimum-rank-in-lowrankapprox-jl/99191
**Category:** General Usage
**Tags:** linearalgebra, factorization
**Created:** [May 21, 2023, 9:40pm UTC](https://discourse.julialang.org/t/request-minimum-rank-in-lowrankapprox-jl/99191 "2023-05-21T21:40:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![miles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles/32/29112_2.png) [@miles](https://discourse.julialang.org/u/miles)
#### Post date: [May 21, 2023, 9:40pm UTC](https://discourse.julialang.org/t/request-minimum-rank-in-lowrankapprox-jl/99191/1 "2023-05-21T21:40:46Z")

</div>

I’m using the `id` method ([interpolative decomposition](https://en.wikipedia.org/wiki/Interpolative_decomposition) or ID) from the LowRankApprox.jl package. In the algorithm I’m trying to program (a variant of the “tensor cross interpolation”, reviewed in depth in [this article](https://journals.aps.org/prx/abstract/10.1103/PhysRevX.12.041018) which uses a kind of two-sided ID), it would be very helpful to be able to request a minimum rank `k`.

This way, the output matrices C and Z would be such that C would be guaranteed to contain at least `k` columns of the original matrix.

Currently, I’m just setting the `rtol` parameter and because of how my algorithm works, sometimes I am only getting C to have single column of the original matrix since it’s part of a kind of alternating optimization outer algorithm and the matrices I’m computing the ID of have approximate low rank early on in the algorithm, which is an artifact of my initial parameter choice. I could try to choose the parameters differently but it might be technical to do whereas just pushing up the rank of the matrices returned from the ID might be a sort of general, automatic solution.

Thanks to LowRankApprox developer @dlfivefifty or anyone else who might help.

---

<div class="post-metadata">

### Author: ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)
#### Post date: [July 5, 2023, 7:10pm UTC](https://discourse.julialang.org/t/request-minimum-rank-in-lowrankapprox-jl/99191/2 "2023-07-05T19:10:38Z")

</div>

I wasn’t the developer just became the maintainer

If you look at the commit history you’ll find the author of the code. Otherwise you could try asking Mikael Slevinsky who knows something about ID

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [July 6, 2023, 12:29am UTC](https://discourse.julialang.org/t/request-minimum-rank-in-lowrankapprox-jl/99191/3 "2023-07-06T00:29:49Z")

</div>

> [@miles](#):
>
> it would be very helpful to be able to request a minimum rank `k`.

At a quick glance through the code, it seems like the termination check is [here](https://github.com/JuliaLinearAlgebra/LowRankApprox.jl/blob/ede6bf2b677e8589abec53e5c3631e8ed6f10851/src/pqr.jl#L409-L413), and maybe you could just change this to something like

```julia
if jn-1 > minrank && abs(A[jn-1,jn-1]) <= ptol
    @inbounds for i = max(minrank+1, j):jn-1
        abs(A[i,i]) <= ptol && return i - 1
    end
end

```

---

<div class="post-metadata">

### Author: ![miles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles/32/29112_2.png) [@miles](https://discourse.julialang.org/u/miles)
#### Post date: [July 20, 2023, 2:50am UTC](https://discourse.julialang.org/t/request-minimum-rank-in-lowrankapprox-jl/99191/4 "2023-07-20T02:50:35Z")

</div>

Thanks for the helpful information & tips. I did try modifying the code myself earlier and it gave the desired result, but then also caused some occasional crashes that I didn’t investigate fully. Now I’ve since gone with a custom implementation of a different, but related matrix factorization.
