Skip to content

Distributed estimation - #3055

Closed
lbybee wants to merge 80 commits into
statsmodels:masterfrom
lbybee:distributed_estimation
Closed

lbybee wants to merge 80 commits into
statsmodels:masterfrom
lbybee:distributed_estimation

Conversation

@lbybee

@lbybee lbybee commented Jun 21, 2016 •

Copy link
Copy Markdown
Contributor

Ok, I wanted to make a PR for this, there are still a couple of things that I need to fix but things are pretty close to done and I'm happy with the current approach.

The key part of the current approach is a function distributed_estimation. This function works by taking a generator for endog and exog, endog_generator and exog_generator, as well as a series of functions and key word arguments to be run on each machine and then used to recombine the results. The generator approach allows for a variety of use cases and can handle a lot of the ideas discussed in the initial proposal. For each data set yielded by the generators a model is initialized using model_class and init_kwds and then the function estimation_method is applied to the model along with the key words fit_kwds and estimation_kwds. Finally, the results are recombined from each data set using join_method.

Currently, this defaults to the distributed regularized approach discussed here:

http://arxiv.org/pdf/1503.04337v3.pdf

but the way I've set things up means that the user should be able to apply any number of procedures here.

The current todo list:

  • Fix hess_obs
  • Fix joblib fit
  • Add dask fit
  • Add WLS/GLS for debiased regularized fit
  • Add likelihood result
  • Add data tests

Let me know if there are any comments/questions/criticisms, as I've said, it certainly isn't complete but I wanted to get this out there so I can start integrating any changes as I finish it up.

@coveralls

coveralls commented Jun 21, 2016 •

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 0433295 on lbybee:distributed_estimation into * on statsmodels:master*.

@kshedden

kshedden commented Jun 23, 2016 •

Copy link
Copy Markdown
Contributor

I would consider having a single generator that yields both endog and exog. There are several reasons for this:

  • Danger that the two separate generators become desynchronized and no obvious way to verify that they are synchronized
  • Should be more efficient since in most cases endog and exog are obtained from the same source and we may end up creating arrays or reading files twice if there are separate generators
  • Function signatures will become shorter
  • No obvious use case for having separate generators
  • More analogous to what Patsy does with dmatrices

@kshedden

Copy link
Copy Markdown
Contributor

Not sure what @josef-pkt thinks but perhaps fit_distributed would be a better top-level name than distributed_estimation (for the method or function, the module name is fine)

@josef-pkt

Copy link
Copy Markdown
Member

(I haven't looked at pr yet)
One question is how to support generated exog, e.g. Polynomials, sparse dummy sets. Sparse exog would be created on the fly and not stored on disk.
In other context i was thinking of adding an exog-extra)

estimation_method=None, estimation_kwds=None,
join_method=None, join_kwds=None):
"""
This functions handles a general approach to distributed estimation,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First line of docstring should be one line. Then blank line, then can have additional text that is longer than one line.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.5%) to 89.283% when pulling 678d061 on lbybee:distributed_estimation into 032a9ab on statsmodels:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.5%) to 89.277% when pulling 0850ff2 on lbybee:distributed_estimation into 032a9ab on statsmodels:master.

along with the average gradient. For the OLS case,
approx_inv_cov is an approximation for

(1 / n X^T X)^{-1}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? I think n * (X^T X)^{-1} is what you want?

X^T(y - X^T params)
"""

grad = -mod.score(np.r_[params], **score_kwds)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.asarray is preferable to np.r_ (I think np.r_ always makes a copy, even if not needed). You shouldn't need the copy here, but if you do I think params.copy() is more clear. If the only goal is to be sure that an ndarray is going into the score function, np.asarray will do that.


where k corresponds to the index of the partition

For the simple linear case:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really "simple linear" if there are more than 1 covariates, better to use "OLS" I think.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.8%) to 88.002% when pulling c281625 on lbybee:distributed_estimation into 032a9ab on statsmodels:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.8%) to 88.009% when pulling f7a8839 on lbybee:distributed_estimation into 032a9ab on statsmodels:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.8%) to 88.016% when pulling 8c18621 on lbybee:distributed_estimation into 032a9ab on statsmodels:master.

@lbybee

lbybee commented Nov 24, 2016

Copy link
Copy Markdown
Contributor Author

@kshedden @josef-pkt

I believe that this should be ready to be merged whenever the pandas issue is solved since that is where the failures for the tests are coming from.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.7%) to 88.102% when pulling 7ab4634 on lbybee:distributed_estimation into 032a9ab on statsmodels:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.7%) to 88.102% when pulling fb16379 on lbybee:distributed_estimation into 032a9ab on statsmodels:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.7%) to 88.102% when pulling fb16379 on lbybee:distributed_estimation into 032a9ab on statsmodels:master.

@kshedden

Copy link
Copy Markdown
Contributor

@lbybee @josef-pkt

This looks good, I will merge in a day or two if nobody objects. Once it's merged I will do some more testing and we can do a quick follow-up PR if needed.

@josef-pkt

Copy link
Copy Markdown
Member

based on a brief look

  • unit tests look "skinny": Is it possible to verify that numbers are "close" to what they should be? Eg. distributed should get results that are close to the non-distributed results. Otherwise, we need at least regression test to prevent future refactoring bugs, including unintended dead code
  • the branch looks far behind master and will need a rebase before merging
  • git history doesn't look so good, 79 commits is a bit large and it seems to have changed files early on like PHReg that are not in the final change set. Some squashing would be very helpful here.
  • there are only a few places where it touches existing models directly, so merging does not look "dangerous"

I guess discussion and changes in this PR might be helpful to understand the development of the code, so I would suggest opening a new PR with a cleaned up history and rebased branch.

@lbybee

lbybee commented Jan 27, 2017

Copy link
Copy Markdown
Contributor Author

@josef-pkt In regards to the tests, there are a number that do comparisons between distributed and non-distributed results, though they are further down in the testing file.

I'm taking care of the commit cleanup now.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.04%) to 88.114% when pulling fd0e2f8 on lbybee:distributed_estimation into 792a3c5 on statsmodels:master.

@lbybee lbybee closed this Jan 27, 2017
This was referenced Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants