Updated Automatic Differentiation API wiki page

36 views
Skip to first unread message

Daniel Lee

unread,
Apr 14, 2015, 12:12:34 AM4/14/15
to stan...@googlegroups.com
Any / all comments and help welcome. I lost steam 3/4 of the way thorough, so it might be weaker towards the end.



Daniel

Aki Vehtari

unread,
Apr 14, 2015, 3:00:08 AM4/14/15
to stan...@googlegroups.com
I read it and I thought it was clear. I fixed some typos.

Aki

Bob Carpenter

unread,
Apr 14, 2015, 3:18:59 AM4/14/15
to stan...@googlegroups.com
I'm confused about what won't work with these instructions.
I don't think we should be putting up instructions that don't work!
I also don't think we should be encouraging people to check out
develop. Advanced users can sort that out for themselves or we
can mention it at the end. Too many choices up front gets confusing.

There's no installation --- it's header only, so there's only
a download. We really want to stress this.

The minimal example should compute a derivative. Something
like:

<...whatever we need to include...>

struct foo {
template <typename T>
T operator(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x) {
using std::exp;
return x[0] * x[1] + exp(x[0]);
}
};

int main() {
Eigen::VectorXd x;
x << 2, 3;
Eigen::VectorXd grad_fx;
double fx = 0;
foo f;
gradient(f, x, fx, grad_fx);
std::cout << "x=" << x
<< " f(x) = " << fx
<< " d/dx f(x) = " << grad_fx
<< std::endl;
return 0;
}


Or do the same thing with vars directly, which might be
simpler for most users:

int main() {
using stan::agrad::var;
var a = 2;
var b = 3;
var fab = a * b + exp(a);
stan::agrad::grad(fx.vi_);
std::cout << "f(a,b) = " << fx.val()
<< "; d/da f(a,b) = " << a.adj()
<< "; d/db f(a,b) = " << b.adj();
stan::agrad::recover_memory();
}

then work up to the std::vector<> based grad() function
in var.hpp, and then the full-on functional.

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

Daniel Lee

unread,
Apr 14, 2015, 9:10:43 AM4/14/15
to stan...@googlegroups.com


On Apr 14, 2015 3:19 AM, "Bob Carpenter" <ca...@alias-i.com> wrote:
>
> I'm confused about what won't work with these instructions.

There were folder-level includes for the tagged version. That got in after the latest release. So the includes at the top of each file aren't valid yet. It will be for the next tagged release.

> I don't think we should be putting up instructions that don't work!

Agreed. I didn't want to write instructions to the current tagged version. I could put a note at the top.

> I also don't think we should be encouraging people to check out
> develop. 

I'm happy to remove that once we tag a new version.

> Advanced users can sort that out for themselves or we
> can mention it at the end.  Too many choices up front gets confusing.
>
> There's no installation --- it's header only, so there's only
> a download.  We really want to stress this.

Yes.

That's where I lost stream. I had intended to build up to the functional.

Reply all
Reply to author
Forward
0 new messages