Sorry I didn’t make clear why I didn’t want to comment on the integrate function on the meeting, it might have sound impolite, but it’s because English is not my first language, so I needed some preparation to talk about the subject.

He’s a summary of it (sorry, no TL;DR version available):

I developed this integrate_function to work on the subject of my (now finished) master dissertation, and it seems to have worked great for my need: to get a normalizing factor (not just a normalizing constant!).

When I was NY (for two weeks) last year Bob actually reviewed the code and suggested another version that was more easy to read, but after I arrived in Brazil I realized it was not possible to implement it that way (I need to check exactly why), he also (rightfully) complained about bad function names I chose like “integrate_function” and a bunch of get_whatever.

Another important point is that there is two functions right now: integrate_function and integrate_function_grad (the names will change, I promise, Bob), the second receives not only the function, but also the gradient of the function. Both function only work with constant integration domains, but allow for a var of std::vector an extra parameter to be passed to the function being integrated. The signature is similar to R’s integrate.

Also, the way the auto-diff library nested calls works right now (or at least at that time), the first one integrate_function is probably very slow for anything other than toy models.

About the integration algorithm itself, I think Ben (it was him there at back of the room talking about it, right?) the knows it way better than me.

It would be good to have a common way of specifying such things in the Stan language even if there are different algorithms (like we have for ODEs). The algorithm I was referring to this morning is described at

but see specifically the papers in the References section by David Baily of the Lawrence Berkeley National Laboratory and the C++ code by John Cook in the External Links section, which I believe we used as a starting point.

It is true that this is intended for functions with finite limits, but with the hyperbolic transformations it converts it to a definite integral with infinite limits. If you have an integral from 0 to infinity or -infinity to infinity, you can still do hyperbolic transformations to make it better behaved.

Also, contrary to what I said this morning, it does have the property that you can keep approximating until the error bound gets below a pre-specified threshold (in addition to returning the error bound).

If you could gather up code notes and what you learned from doing it the first time, that’d be great.

OK, I’ll start by changing the naming of the functions to something better and documenting then.

Is there a version of your thesis we could cite on our citations page?

it has not gone public yet on University website (not that it’s super secret, just that the presentation will be next month), but if you want to add right now:

@MastersThesis{marcoinacio,
author = {Marco Henrique de Almeida Inacio },
title = {Comparing two populations using Bayesian Fourier series density estimation},
school = {University of São Paulo and UFSCar},
address = {São Carlos, Brazil},
year = {2017},
}

Marco Inacio. 2017. Comparing two populations using Bayesian Fourier series density estimation. University of São Paulo and UFSCar. Masters Dissertation.

If you could gather up code notes and what you learned from doing
it the first time, that'd be great.

OK, I’ll start by changing the naming of the functions to something
better and documenting then.

I improved and documented the code, it’s available in repository:
feature/issue-210-numerical-integration

I haven’t completely understood yet the context of other projects
related to this one, that is, is anyone working on some other
implementation of univariate numerical integral like this one or is only
on closely related stuff?

Yes, we want to add this functionality to Stan. The bigger project is all the diff eq functionality and the algebraic and differential algebraic equation solvers. We’re writing grant proposals to cover the development. Are you still interested in working on this feature? I don’t think anyone’s working on the integrator yet, but there’s been a lot of discussion of how it’d have to work. Charles and Michael and Ben would be the ones to coordinate with in terms of algorithms.