Hipparchus-Math / hipparchus

An efficient, general-purpose mathematics components library in the Java programming language
Apache License 2.0
142 stars 41 forks source link

Add value(Gradient) method in UnivariateDifferentiableVectorFunction interface #97

Closed BryanCazabonne closed 4 years ago

BryanCazabonne commented 4 years ago

UnivariateDifferentiableVectorFunction interface represents an univariate differentiable vectorial function. Currently it contains only one method.

/**
 * Compute the value for the function.
 * @param x the point for which the function value should be computed
 * @return the value
 * @exception MathIllegalArgumentException if {@code x} does not
 * satisfy the function's constraints (argument out of bound, or unsupported
 * derivative order for example)
 */
DerivativeStructure[] value(DerivativeStructure x) throws MathIllegalArgumentException;

It can be a good enhancement to also add a new method signature using Gradient:

/**
 * Compute the value for the function.
 * @param x the point for which the function value should be computed
 * @return the value
 * @exception MathIllegalArgumentException if {@code x} does not
 * satisfy the function's constraints (argument out of bound, or unsupported
 * derivative order for example)
 */
Gradient[] value(Gradient x) throws MathIllegalArgumentException;

That's just an idea but it can be interesting to also add method signatures using UnivariateDerivative1 and UnivariateDerivative2 classes.

BryanCazabonne commented 4 years ago

If you agree with that proposal, I can perform the change.

maisonobe commented 4 years ago

I thought about it this afternoon, but we cannot do it for 1.7. This is a public interface and we can neither add methods to it nor generalize existing methods in a compatible way. to be more precise, I thought about replacing DerivativeStructure with the new Derivative top level interface added this afternoon. This change would imply all users that implemented it in their own code would need to update their code. It has to wait for 2.0.

BryanCazabonne commented 4 years ago

I made this proposal because I want to be able to use this new method with the HermiteInterpolator (and afterwards in Orekit). I agree that the simplest and cleanest way is to wait for version 2.0.

To make this change for a minor version, there is a working but a bit ugly way. Indeed, it is possible to add a new interface that would extend UnivariateDifferentiableVectorFunction. Something like ExtendedUnivariateDifferentiableVectorFunction (even the name is a bit ugly). This new interface would have the method signature with Gradient. Finally, this new interface would be implemented by the HermiteInterpolator.

/**
 * Extension of {@link UnivariateDifferentiableVectorFunction} for {@link Gradient}.
 *
 */
public interface ExtendedUnivariateDifferentiableVectorFunction
    extends UnivariateDifferentiableVectorFunction {

    /**
     * Compute the value for the function.
     * @param x the point for which the function value should be computed
     * @return the value
     * @exception MathIllegalArgumentException if {@code x} does not
     * satisfy the function's constraints (argument out of bound, or unsupported
     * derivative order for example)
     */
    Gradient[] value(Gradient x) throws MathIllegalArgumentException;

}

And

public class HermiteInterpolator implements ExtendedUnivariateDifferentiableVectorFunction {
  // All the methods
}
BryanCazabonne commented 4 years ago

To be consistent with the other interfaces, we can also add ExtentedUnivariateDifferentiableMatrixFunction and ExtendedUnivariateDifferentiableFunction classes

maisonobe commented 4 years ago

Then let the interface have signature:

  <T extends Derivative> T[] value(T x)
maisonobe commented 4 years ago

Do you intend to implement ExtendedUnivariateDifferentiableVectorFunction for 1.7?

BryanCazabonne commented 4 years ago

I would like. I will do that this morning and provide a pull request at the beginning of the afternoon.