Skip to content

PERF: pinv during GLM model specification #4622

Closed

Description

@thequackdaddy

So this is small issue I've always had with the genmod procedure.

My large-ish model--11.9M observations, 54 DF--takes a little over 1 minute for the pinv step during the initialize method on GLM.

I think the numpy pinv formula is quicker than others I've found. scipy.linalg.pinv2 takes about 90 seconds. scipy.linalg.pinv throws MemoryError.

self.pinv_wexog = np.linalg.pinv(self.exog)
self.normalized_cov_params = np.dot(self.pinv_wexog,
np.transpose(self.pinv_wexog))

Again, pardon my ignorance if I'm missing something, but I'm wondering if there's a way to speed this up? I think the only thing useful about this is self.normalized_cov_params which is only used oonly for robust covariance (again, I think).

Would it be possible to...

  1. Randomly reduce the number of records that goes into the pinv to speed the matrix?
  2. Allow the user to skip this step and only use if you want a robust covariance?
  3. Perform the pinv as part of fit, only if you select a robus covariance?
  4. Use joblib to fork a separate thread to calculate this
  5. Others?

Activity

  1. added this to the 0.10 milestone on May 12, 2018
  2. josef-pkt commented on May 12, 2018

    @josef-pkt
    Member

    How many iterations do irls and newton take?

    I think the main improvement would be to remove as much as possible for an initial estimate and during optimization, and only do a full version at the end.
    e.g. we still need a WLS version that uses moment matrices instead of a full exog linalg decomposition.

    Is it relatively cheap to split the data into subsets of observations where each subset has full rank exog, i.e. each categorical level shows up in each subset?

  3. thequackdaddy commented on May 12, 2018

    @thequackdaddy
    MemberAuthor

    To be clear, pinv runs before fit method is run... this piece runs once you instantiate the GLM class.

    newton with eim I used max_start_irls=1 and iterations was 7
    newton with oim I used max_start_irls=1 and iterations is 5
    irls takes 7 iterations

  4. josef-pkt commented on May 12, 2018

    @josef-pkt
    Member

    Ok, I didn't realize that this is about GLM.initialize

    see
    #1720 (comment)
    I never checked this in detail.
    I think these parts can be removed and we only compute the things that we actually need.

  5. added a commit that references this issue on May 14, 2018
    fa065c7
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