[ 
https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14521494#comment-14521494
 ] 

Luc Maisonobe commented on MATH-1143:
-------------------------------------

OK. You may have a look at the JacobianMatrices class in the ode package that 
allows integrating the variational equations
if your derivatives are computed with respect to either the initial state or 
some model parameters. But even if you use this,
you will not directly get a DerivativeStructure and you will have to build it 
afterwards.

So I guess you example is almost the helper function you need. Perhaps we could 
rework it as follows:

{code}
UnivariateDifferentiableFunction buildDifferentiable(final UnivariateFunction 
f, final UnivariateVectorFunction gradient) {

  return new UnivariateDifferentiableFunction() {

            public double value(final double x) {
                return f.value(x);
            }

            public DerivativeStructure value(final DerivativeStructure t) {
                if (t.getOrder() > 1) {
                    throw new NumberIsTooLargeException(t.getOrder(), 1, true);
                }
                double     y = f.value(x);
                double[] dy = gradient.value(x);
                double[] packed = new double[dy.length + 1];
                packed[0] = y;
                System.arraycopy(dy, 0, packed, 1, dy.length);
                return new DerivativeStructure(dy.length, 1, packed);
            }

    };
}
{code}

> Helper methods to FiniteDifferencesDifferentiator
> -------------------------------------------------
>
>                 Key: MATH-1143
>                 URL: https://issues.apache.org/jira/browse/MATH-1143
>             Project: Commons Math
>          Issue Type: Improvement
>            Reporter: Alexander Nozik
>            Priority: Trivial
>
> A DerivativeStructure and UnivariateDifferentiableFunction are great tools if 
> one needs to investigate the whole function but are not convenient if one 
> just needs derivative in a given point.
> Perhaps you could add some helper methods to FiniteDifferencesDifferentiator 
> or to utility class like FunctionUtils. Also it would be good to have helper 
> methods to get the derivatives of UnivariateDifferentiableFunction or 
> MultivariateDifferentiableFunction as simple Univariate or Multivariate 
> functions (or vector-functions).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to