Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance of division/reciprocal/sqrt in multivariate, high-order auto diff #256

Closed
Serrof opened this issue May 9, 2023 · 1 comment

Comments

@Serrof
Copy link
Contributor

Serrof commented May 9, 2023

DerivativeStructure implements intrinsic functions like division itself by composing from the left with univariate Taylor expansions, similarly to what is described here basically. This means in general that the "complexity" is at best N times the one of multiplication, where N is the order. However, exploiting recursive formulas between the derivatives allows to alleviate this dependency on N (see Neidinger), getting a "multiplication-like" algorithm. Although they are for the so-called normalized derivatives (with the factorials, as opposed to the standard ones used in Hipparchus), they could be adapted. A particular case, easily adaptable, is when the multiplication operator itself can be leveraged upon for the inversion: division (plus reciprocal) and square root.

Here is it for the division, reusing the syntax from DSCompiler:

    public void divide(final double[] lhs, final int lhsOffset,
                       final double[] rhs, final int rhsOffset,
                       final double[] result, final int resultOffset) {
        for (int i = 0; i < multIndirection.length; ++i) {
            result[resultOffset + i] = lhs[lhsOffset + i];
            for (int j = 0; j < multIndirection[i].length - 1; j++) {
                final MultiplicationMapper mapping = multIndirection[i][j];
                result[resultOffset + i] -= mapping.getCoeff() *
                        (result[resultOffset + mapping.lhsIndex] *
                        rhs[rhsOffset + mapping.rhsIndex]);
            }
            result[resultOffset + i] /= rhs[lhsOffset] * multIndirection[i][0].getCoeff();
        }
    }

Remark: using normalized derivatives to represent the expansion could also speed up computations as hinted in the same paper by Neidinger.

@Serrof
Copy link
Contributor Author

Serrof commented May 11, 2023

For the previous code to work for sure, the prerequisite is that the multiplication mapping has monomials sorted in increasing total order. However from reading the docstring of DSCompiler, I'm not 100% sure about it. Could you confirm it's the case @maisonobe?

@Serrof Serrof changed the title Performance of operations in automatic differentiation Performance of division/reciprocal in automatic differentiation May 23, 2023
Serrof added a commit to Serrof/hipparchus that referenced this issue May 23, 2023
@Serrof Serrof changed the title Performance of division/reciprocal in automatic differentiation Performance of division/reciprocal in multivariate, high-order automatic differentiation May 23, 2023
Serrof added a commit to Serrof/hipparchus that referenced this issue May 24, 2023
Serrof added a commit to Serrof/hipparchus that referenced this issue May 27, 2023
@Serrof Serrof changed the title Performance of division/reciprocal in multivariate, high-order automatic differentiation Performance of division/reciprocal/sqrt in multivariate, high-order auto diff May 27, 2023
Serrof added a commit to Serrof/hipparchus that referenced this issue May 27, 2023
Serrof added a commit to Serrof/hipparchus that referenced this issue Jun 3, 2023
…UnivariateDerivative2 + fixed bug in cbrt for the latter
maisonobe added a commit that referenced this issue Jun 18, 2023
Fixed issue #256 (faster division/reciprocal/sqrt for multivariate auto-diff)
@Serrof Serrof closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant