2nd order derivatives, working yet?

73 views
Skip to first unread message

Joshua N Pritikin

unread,
Dec 18, 2014, 3:11:13 PM12/18/14
to stan-...@googlegroups.com
I was excited to see that "Feature/issue 676 generalize
operandsandpartials." was recently merged.

I re-generated the C++ code for a simple model (attached) and reduced it
to a minimum test case (also attached). I still get compiler errors
expanding the templates. The first one is,

In file included from /opt/cmdstan/stan/src/stan/io/reader.hpp:5:0,
from /opt/cmdstan/stan/src/stan/model/model_header.hpp:22,
from mvn.cpp:1:
/opt/cmdstan/stan/src/stan/prob/transform.hpp: In instantiation of ‘Eigen::Matrix<LhsScalar, -1, -1, 0> stan::prob::cov_matrix_constrain(const Eigen::Matrix<Scalar, -1, 1>&, typename stan::math::index_type<Eigen::Matrix<Scalar, -1, 1> >::type) [with T = stan::agrad::fvar<stan::agrad::var>; typename stan::math::index_type<Eigen::Matrix<Scalar, -1, 1> >::type = long int]’:
/opt/cmdstan/stan/src/stan/io/reader.hpp:1064:50: required from ‘stan::io::reader<T>::matrix_t stan::io::reader<T>::cov_matrix_constrain(std::size_t) [with T = stan::agrad::fvar<stan::agrad::var>; stan::io::reader<T>::matrix_t = Eigen::Matrix<stan::agrad::fvar<stan::agrad::var>, -1, -1, 0, -1, -1>; std::size_t = long unsigned int]’
mvn.cpp:75:19: required from ‘T__ mvn_model_namespace::mvn_model::log_prob(std::__debug::vector<T2>&, std::__debug::vector<int>&, std::ostream*) const [with bool propto__ = true; bool jacobian__ = true; T__ = stan::agrad::fvar<stan::agrad::var>; std::ostream = std::basic_ostream<char>]’
mvn.cpp:105:78: required from ‘T_ mvn_model_namespace::mvn_model::log_prob(Eigen::Matrix<T, -1, 1>&, std::ostream*) const [with bool propto = true; bool jacobian = true; T_ = stan::agrad::fvar<stan::agrad::var>; std::ostream = std::basic_ostream<char>]’
mvn.cpp:122:53: required from ‘T model_functional<M>::operator()(Eigen::Matrix<T, -1, 1>&) const [with T = stan::agrad::fvar<stan::agrad::var>; M = mvn_model_namespace::mvn_model]’
/opt/cmdstan/stan/src/stan/agrad/autodiff.hpp:207:39: required from ‘void stan::agrad::hessian(const F&, const Eigen::Matrix<double, -1, 1>&, double&, Eigen::Matrix<double, -1, 1>&, Eigen::Matrix<double, -1, -1>&) [with F = model_functional<mvn_model_namespace::mvn_model>]’
mvn.cpp:150:58: required from here
/opt/cmdstan/stan/src/stan/prob/transform.hpp:1784:49: error: call of overloaded ‘multiply_lower_tri_self_transpose(Eigen::Matrix<stan::agrad::fvar<stan::agrad::var>, -1, -1, 0, -1, -1>&)’ is ambiguous
return multiply_lower_tri_self_transpose(L);
^
/opt/cmdstan/stan/src/stan/prob/transform.hpp:1784:49: note: candidates are:
In file included from /opt/cmdstan/stan/src/stan/math/matrix.hpp:64:0,
from /opt/cmdstan/stan/src/stan/io/dump.hpp:17,
from /opt/cmdstan/stan/src/stan/model/model_header.hpp:21,
from mvn.cpp:1:
/opt/cmdstan/stan/src/stan/math/matrix/multiply_lower_tri_self_transpose.hpp:18:5: note: stan::math::matrix_d stan::math::multiply_lower_tri_self_transpose(const matrix_d&)
multiply_lower_tri_self_transpose(const matrix_d& L) {
^
In file included from /opt/cmdstan/stan/src/stan/agrad/rev/matrix.hpp:24:0,
from /opt/cmdstan/stan/src/stan/model/model_header.hpp:18,
from mvn.cpp:1:
/opt/cmdstan/stan/src/stan/agrad/rev/matrix/multiply_lower_tri_self_transpose.hpp:19:5: note: stan::agrad::matrix_v stan::agrad::multiply_lower_tri_self_transpose(const matrix_v&)
multiply_lower_tri_self_transpose(const matrix_v& L) {
^

etc...

Shall I file this as an issue? What's the next step?

--
Joshua N. Pritikin
Department of Psychology
University of Virginia
485 McCormick Rd, Gilmer Hall Room 102
Charlottesville, VA 22904
http://people.virginia.edu/~jnp3bc
mvn.cpp
mk
mvn.stan

Bob Carpenter

unread,
Dec 18, 2014, 3:18:33 PM12/18/14
to stan-...@googlegroups.com
Yes, please file it as an issue, and add a 2.6.0 milestone.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> <mvn.cpp><mk.txt><mvn.stan>

Joshua N Pritikin

unread,
Dec 18, 2014, 3:29:48 PM12/18/14
to stan-...@googlegroups.com
On Thu, Dec 18, 2014 at 03:17:19PM -0500, Bob Carpenter wrote:
> Yes, please file it as an issue, and add a 2.6.0 milestone.

It looks like you need to add the milestone. I don't have permission.

https://github.com/stan-dev/stan/issues/1175

Daniel Lee

unread,
Dec 18, 2014, 3:30:35 PM12/18/14
to stan-...@googlegroups.com
I updated the issue with the 2.6.0 milestone.

Rob Trangucci

unread,
Dec 19, 2014, 1:00:22 PM12/19/14
to stan-...@googlegroups.com
Josh, 

Have you updated your cmdstan to the latest hosted on github? If I try to compile the C++ file you included, I get the same compiler errors that you do, however, cmdstan doesn't generate cpp files with main functions anymore, whereas your mvn.cpp has a main function. 

Download the newest cmdstan from github and try to recompile your model using the newer distribution. I was able to compile your model just fine using the newest cmdstan and stan from github.

Rob

Daniel Lee

unread,
Dec 26, 2014, 9:28:40 AM12/26/14
to stan-...@googlegroups.com
Hi Joshua,

Hopefully you saw the comment on the github issue. We intentionally did not include forward mode autodiff in Stan's general model header: src/stan/model/model_header.hpp.

For the time being, you should include headers before including the model header:
#include <stan/agrad/fvar.hpp>
#include <stan/agrad/fvar/matrix.hpp>

Including those before including the model header will bring in the forward mode template specializations that are needed for your program.



Daniel


--
Reply all
Reply to author
Forward
0 new messages