Skip to content

use COD to create sufficient statistic#555

Merged
bgoodri merged 1 commit into
masterfrom
CODOLS
Mar 14, 2022
Merged

use COD to create sufficient statistic#555
bgoodri merged 1 commit into
masterfrom
CODOLS

Conversation

@bgoodri

@bgoodri bgoodri commented Nov 2, 2021

Copy link
Copy Markdown
Contributor

fixes #534

@bgoodri bgoodri requested a review from jgabry November 2, 2021 16:58
@bgoodri

bgoodri commented Nov 2, 2021

Copy link
Copy Markdown
Contributor Author

I can't bring myself to merge this but if @jgabry does, then I'll live with it.

@jgabry

jgabry commented Nov 2, 2021

Copy link
Copy Markdown
Member

I can't bring myself to merge this but if @jgabry does, then I'll live with it.

Can you elaborate? I'm not sure what the pros and cons of this are, so not sure how to evaluate.

@bgoodri

bgoodri commented Nov 2, 2021 via email

Copy link
Copy Markdown
Contributor Author

@jgabry

jgabry commented Nov 2, 2021

Copy link
Copy Markdown
Member

Ok I think I follow most of that. If I understand you correctly, this part

Presumably, there is some way to construct X such that the columns are perfectly collinear but not numerically perfectly collinear enough to go through the code path that implements the new behavior and conversely some way to construct an X that is not perfectly collinear but is sufficiently numerically collinear to go through the branch that the code path that implements the new behavior.

means that this doesn't actually guarantee that Andrew gets the desired behavior when there's perfect collinearity and it also doesn't guarantee that when there's no collinearity we get exactly the same result as before this PR. Is that right? (If that's the case then I think we should probably discuss this more with Andrew because I don't think he's necessarily aware of these subtleties. I definitely wasn't aware until now.)

@jgabry

jgabry commented Nov 2, 2021

Copy link
Copy Markdown
Member

I'm gonna send an email to you and Andrew about this. I'm not entirely comfortable merging this yet (for the reasons you described). That said, I did just test it and it does work well (or at least it runs well) on the test case you included. So this seems good to go if we decide to use it.

@hsbadr

hsbadr commented Dec 23, 2021

Copy link
Copy Markdown
Member

The problem with this kind of change is that it needs to be maintained separately. For example, changes in Stan/Math or RcppEigen may affect the templates for CODOLS, such as the broken csr_matrix_times_vector2 with Stan ~v2.28. While this might be an easy task, I'd rather prefer to completely rely on Stan/Math here (and, BTW, remove csr_matrix_times_vector2 too by replacing it with csr_matrix_times_vector in the Stan code). Any required changes for performance would be better included in Math, probably with a simple interface to disable time-consumin checks, for example.

@bgoodri bgoodri merged commit 5a7715e into master Mar 14, 2022
@bgoodri bgoodri deleted the CODOLS branch March 14, 2022 18:40
@hsbadr

hsbadr commented Mar 15, 2022

Copy link
Copy Markdown
Member

@bgoodri FYI. With the development version of RStan + master branch of RStanARM:

In file included from stan_files/continuous.cc(3):
stan_files/continuous.hpp(6025): error: no instance of overloaded function "model_continuous_namespace::CODOLS" matches the argument list
            argument types are: (Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>, std::ostream *)
          stan::model::assign(OLS, CODOLS(X_, y, pstream__),
                                   ^
../inst/include/CODOLS.hpp(14): note: this candidate was rejected because at least one template argument could not be deduced
  CODOLS(const Eigen::Matrix<T2__, Eigen::Dynamic, Eigen::Dynamic>& X,
  ^
stan_files/continuous.hpp(3665): note: this candidate was rejected because at least one template argument could not be deduced
    CODOLS(const T0__& X_arg__, const T1__& y_arg__, std::ostream* pstream__) ;
    ^

In file included from stan_files/continuous.cc(3):
stan_files/continuous.hpp(6025): error: no instance of overloaded function "stan::model::assign" matches the argument list
            argument types are: (Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>, <error-type>, const char [23])
          stan::model::assign(OLS, CODOLS(X_, y, pstream__),
          ^

#558 compiles successfuly.

@andrjohns

Copy link
Copy Markdown
Contributor

This is a pretty easy fix - the templates just need to be updated for Eigen expressions (and calling to_ref on the inputs and possibly returning via make_holder). Should I make the change or did you want to handle this Ben?

@bgoodri

bgoodri commented Mar 16, 2022 via email

Copy link
Copy Markdown
Contributor Author

@hsbadr

hsbadr commented Mar 16, 2022

Copy link
Copy Markdown
Member

Yes, fixed by b7b2579.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix for perfect collinearity in linear regression

4 participants