I have multiple algorithms for computing the matrix exponential. A general algorithm, and then some specialized ones that target specific kinds of matrices.
Should the algorithms be saved in different files? Right now, I have two files: one with the pade approximation from Eigen 3.0, and another one with code for symmetric, nilpotent, and 2x2 matrices. Should they each be stored in separate files? Should each algorithms have its own unit tests, or is testing the final expm() function sufficient?
I'm also unclear on when to write a template function, and when to overload it for fvar<T> and var. Doing the latter makes sense to me, if we handwrite the gradient (in the fvar version), else would it be redundant?
What are the function names going to be?
template <typename T>
void matrix_exp_compute_2x2(const Matrix<T, Dynamic, Dynamic>& A,
Matrix<T, Dynamic, Dynamic>& B)
You want to make the var version efficient. Again, you'll
want to follow the other examples of matrix derivatives.
Yes, every instantiation of every function needs to
be tested.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.
How easy it to check nilpotency?
Then how did you implement in rev and fwd? Those reqire
gradients to be coded. Otherwise, you only need the templated
version in prim.
Why are you including a mutable matrix B as an argument rather than
just returning a matrix?
The reason to test it separately is that otherwise your tests
for expm() need to know the branching logic internally to perform
adequate testing. Daniel will probably have an opinion on this, too.
> > To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.
My general advice is to get a version working first, even if
it's just one templated implementation in prim/mat and then
tests in prim/mat, prim/rev, and prim/fwd.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.
--
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+unsubscribe@googlegroups.com.
(and then create a new issue for optimizing)?
(and then create a new issue for optimizing)?
On Thu, Sep 8, 2016 at 8:38 AM, Charles Margossian <charles.ma...@gmail.com> wrote:
My general advice is to get a version working first, even if
it's just one templated implementation in prim/mat and then
tests in prim/mat, prim/rev, and prim/fwd.Should I make a pull request once I have the simple version in place?
On Wed, Sep 7, 2016 at 7:55 PM, Bob Carpenter <ca...@alias-i.com> wrote:
We definitely don't want to perform a general eigendecomposition
to test whether we can apply a more efficient matrix exponential
algorithm. Is there a fast way to just find the largest eigenvalue?
If not, you'd want to break the nilpotent case out. I have no
idea what it's used for and if you don't have an application in
mind, I'd just recommend skipping it for now.
- Bob
> On Sep 7, 2016, at 6:04 PM, Avraham Adler <avraha...@gmail.com> wrote:
>
> On Wednesday, September 7, 2016 at 11:55:09 AM UTC-4, Charles Margossian wrote:
>> How easy it to check nilpotency?
>>
>>
>> Not sure how to best do this. The check I wrote involves an embedded for loop and uses ==. I might hold off doing the nilpotent specialization for now. I know matlab handles it, but I'm not aware of any concrete applications (at least not in pharmacometrics). It's not hard per se -- I have a working prototype --, but computing a Taylor series with matrices probably requires more careful coding, at least to be optimized.
>
>
> Excuse the ignoramus intrusion, but per https://en.wikipedia.org/wiki/Nilpotent_matrix#Characterization, iff the only eigenvalue of a square matrix is 0 it is nilpotent. Would it be computationally more expensive to calculate the eigenvectors?
>
> Avi
>
> --
> 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.
--
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.
--
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.
It also makes sense to do this testing at the lowest level possible so if you have a higher function that choose among approximations you'll only be testing that it's branching correctly rather than testing the complete set of algorithms.
> > 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.
>
> --
> 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.
>
>
> --
> 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.
--
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.
--
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.
--
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.
-1, since we're voting :-)
The top-level function *must* test [snip] that the branches return the right results.
>> > > To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.
>> > > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > 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+unsubscribe@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > 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+unsubscribe@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> 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+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> 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+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> 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+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> 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+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.
Just a programming point here that slightly contradicts what
Daniel was saying
Internal functions should *not* check their input conditions.
So you don't want the symmetric handler to check for symmetry
or the 2x2 handler to check sizes. That's the job of the calling
function and should be tested from there. It helps ensure the
error reports are correct (they come from the function the user
called, not some internal function they've never heard of)
and removes redundancy in tests.
You can test that internal errors arise from the wrong inputs,
but I wouldn't bother.
There are two drawbacks to testing internal functions:
* when the internal functions change without changing the external
API, then the tests need to change even though it doesn't
change external public behavior
* requiring tests for internal functions discourages developers
from breaking natural functional units into tests
This would all be mitigated somewhat if the testing framework
were faster. Right now, with a lot of functions not just
including what they use, a change in a low-level functions requires
a 45 minute unit test run on my end,
Sadly, it appears that the determinant and trace being 0 is necessary but not sufficient condition for nilpotency. The only necessary and sufficient condition I've come across is having all eigenvalues 0.
I'm curious Charles, how are you testing?
We're going to require the low-level tests because
Daniel wants them.
I'm just trying to explain why we need the high-level
tests and why the low-level functions don't need to
come with bounds checks.
- Bob
> On Sep 8, 2016, at 2:30 PM, Krzysztof Sakrejda <krzysztof...@gmail.com> wrote:
>
> Ok, thanks for the exposition, it sounds like the top-level tests come first and the low-level tests are nice if we can manage to get them. Once I finish the test classes for the refactor branch this week I'll try to put some of this down in the Wiki so you don't have to redo the explanation it every time :)
>
> On Thu, Sep 8, 2016 at 2:05 PM Bob Carpenter <ca...@alias-i.com> wrote:
>
> > On Sep 8, 2016, at 11:28 AM, Krzysztof Sakrejda <krzysztof...@gmail.com> wrote:
> >
> > ...
>
> > * requiring tests for internal functions discourages developers
> > from breaking natural functional units into tests
> >
> >
> > I don't get what "breaking natural functional units into tests" means.
>
> Not surprising---it was a typo. I meant breaking the natural
> functional units into subroutines.
>
>
> > This would all be mitigated somewhat if the testing framework
> > were faster. Right now, with a lot of functions not just
> > including what they use, a change in a low-level functions requires
> > a 45 minute unit test run on my end,
> >
> > Shouldn't we just be testing that the low-level function passes tests? If the low-level function passes tests but higher-level functions fail because of it then the low-level function wasn't tested properly (or it was called for arguments outside its range)
>
> We want to test the higher-level functions thoroughly so that
> if their implementation changes, they are still being thoroughly
> tested.
>
> - 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+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.
The only necessary and sufficient condition I've come across is having all eigenvalues 0.
I'm curious Charles, how are you testing?
The only necessary and sufficient condition I've come across is having all eigenvalues 0.
I'm curious Charles, how are you testing?For an NxN matrix A, I computed A *= A, until I either got a zero matrix or I had done the operation (N - 1) times. Not optimal, but easy to code.