Skip to content

PERF: speed up iteratively reweighted least squares #2287

Closed

Description

@josef-pkt

both RLM and GLM create WLS instances during iterations even though we only need a little bit of it.

see for example
https://github.com/ceholden/yatsm/blob/master/sandbox/benchmark/robustLM/README.md
https://github.com/ceholden/yatsm/blob/master/yatsm/regression/robust_fit.py#L87

related #2203 for simplified, special case models
for GLM there is a nice page for julia in terms of speeding up and reducing memory, link ?

Activity

  1. added this to the 0.8 milestone on Feb 21, 2015
  2. guyrt commented on Apr 4, 2015

    @guyrt
    Contributor

    I'm looking at this ticket, but something isn't clear. The time in either solver should be dominated by the matrix inversion, which is dominated by either a qr decomp or an svd. This is backed up by the fact that the benchmark lists numpy.linalg.svd as the most expensive operation in statsmodels and SVD via dgelsd in the yatsm solver. If anything, it looks like lstsq is simply faster.

    If we include a simplified solver, we'll want to make it use lstsq by default. First, should we try to add numpy.linalg.lstsq as an optional solver in the full Regression case? If yes, then the work looks like this:

    1. Add lstsq as an option for the general solver and make RLM use it.
    2. Benchmark to see if this brings down the runtime.
    3. If no, then create a SimpleRegression class and strip out more of Regression. Unless I'm mistaken, the remaining things we would remove are O(n) where n == number of samples.
  3. josef-pkt commented on Apr 5, 2015

    @josef-pkt
    MemberAuthor

    @guyrt Solving the least squares problem might be the single most expensive operation, and I don't think we can gain a large amount by changing it, however, the WLS class still has much additional overhead. From the profile it looks like there is still the second call to svd for the rank, and there is a larger amount of time spent in ufunc.reduce.

    My guess is that we gain most by stripping all calculations and checks from WLS that are not directly relevant for the IRLS. (no constant check, no rank check, not data handling with label creation, no extra results and not holding on to any temporaries for more than the minimum amount.

    I would directly compare the call to WLS with a call to a WLSminimal or wls_minimal, and see what slack we can remove.

    I don't think linalg.lstsq is a solution for OLS/WLS fit itself, because it still leaves us with an extra step to calculate the normalized_cov_params in the "standard" usage.

    I would prefer GLM as a test case, because I'm currently more familiar with it than with RLM, and more improvements are currently targeted for GLM. However, that's not really important, and I guess the same improvements will be used by all IRLS estimation methods.

  4. added 8 commits that reference this issue on Jun 20, 2016
    c5c2438
    764e8de
    b8621d7
    0003fae
    930c70f
    4c90241
    bf1126e
    27c549a
  5. 2 remaining items

  6. added 4 commits that reference this issue on Jun 21, 2016
    0c68ec6
    759212e
    b57c974
    bd2dcab
  7. added a commit that references this issue on Jul 11, 2016
    fab9868
  8. added a commit that references this issue on Aug 10, 2016
    680eb0e
  9. added a commit that references this issue on Aug 29, 2016
    1d47815
  10. added a commit that references this issue on Dec 30, 2016
    c288a1c
  11. added a commit that references this issue on Jan 22, 2017
    f8a1c21
  12. added 5 commits that reference this issue on Jan 31, 2017
    31483c7
    37f713d
    18b7284
    056674f
    015e96e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions