stan-dev / math

The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
756 stars 188 forks source link

A log_add_exp function that returns containers #3127

Open WardBrian opened 1 week ago

WardBrian commented 1 week ago

It would be nice to have a function that works like log_sum_exp but elementwise, so the return was also a container.

I have a similar issue with log_sum_exp where I wanted it to vector[n] a = log_sum_exp(vector[n] b, vector[n] c) across each element, however it doesn't do this type of elementwise sum. Maybe if we had a log_add_exp which I've seen in other languages.

Originally posted by @spinkney in https://github.com/stan-dev/docs/issues/832#issuecomment-2478728469

MichaScant commented 1 week ago

Hi, can I be assigned this issue?

WardBrian commented 1 week ago

Hi @MichaScant -- we don't really use the 'assign' feature of GitHub, but if you want to go ahead and tackle this, feel free!

spinkney commented 1 week ago

@WardBrian we have a log_diff_exp. Should we also add a log_subtract_exp?

WardBrian commented 1 week ago

@spinkney if it would be useful, but probably easiest to have as a separate issue

MichaScant commented 4 days ago

Hello, I am in the middle of building the test file using log_sum_exp_test as an example and noticed you were passing in logSumExp into the test

Screenshot 2024-11-22 at 7 28 25 PM

Would I have to initialize an equivalent logAddExp and how would that occur? Or is there a substitute I can use? Thank you

WardBrian commented 4 days ago

The two arguments there are test group and test name, so you can just write the logAddExp without having to do any more code