[jira] [Commented] (MATH-1143) Helper methods to FiniteDifferencesDifferentiator
[ https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14521051#comment-14521051 ] Alexander Nozik commented on MATH-1143: --- This is exactly what i wat talking about. Also the same thing should be done for MultivariateDifferentiableFunction. Another thing that perhaps is not so easy to do is to create some way to define new derivative structures without using FiniteDifferencesDifferentiator. For example I've got some compex function for which I know its value in any point and all its first order derivatives in any point, but can't provide any analytical expression for it (in my case the function is obtained by integrating some other function). Now I want to work with this function and its derivatives. How can I do that? 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)
[jira] [Commented] (MATH-1143) Helper methods to FiniteDifferencesDifferentiator
[ https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14521339#comment-14521339 ] Luc Maisonobe commented on MATH-1143: - If you have function f(x1, x2, x3) and know both the value and the derivatives, you can directly build the DerivativeStructure as follows: {code} int nbParams = 3; // index 0 will be for x1, index 1 for x2, index 2 for x3 int order = 1; // we will use only value and first order derivative return new DerivativeStructure(nbParams, order, f, dfdx1, dfdx2, dfdx3); {code} As this constructor as a variable number of arguments, this example can be generalized to other numbers of parameters. The order in which the derivatives should be provided is difficult to set up in the general case when both nbParams and order are greater than 1, but it is straightforward in the two limit cases (nbParams = 1, order 1) or (nbParams 1, order = 1). In both cases, you just give the derivatives in the natural order, which is in increasing order when you have one parameter and high order derivatives, and in parameters order when you have only first order derivatives for all parameters. 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)
[jira] [Commented] (MATH-1143) Helper methods to FiniteDifferencesDifferentiator
[ https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14521411#comment-14521411 ] Alexander Nozik commented on MATH-1143: --- I am not sure I understand, how this constructor works. It seems that it defines derivatives in the fixed point. How can I define a function for which I know value and first derivative in any given point? Something like that? {code} UnivariateFunction f = (DerivativeStructure ds) - { double val = someOerationHere(ds.value); double deriv = someDerivativeCalculationHere(ds.value) return new DerivativeStructure(1, 1, val, deriv); }; {code} Anyway, it seems a bit complicated construct. I think it would be better to create some kind of helper class (say DifferentiableFuncitonBuilder), in which on could set function and its derivatives separately. Later one can add some pretty fancy functionality like building function from String representation. 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)
[jira] [Commented] (MATH-1143) Helper methods to FiniteDifferencesDifferentiator
[ https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14521431#comment-14521431 ] Luc Maisonobe commented on MATH-1143: - {quote} I am not sure I understand, how this constructor works. It seems that it defines derivatives in the fixed point. {quote} Yes. A DerivativeStructure instance is just one set of values, just like a double which would hold a value f(x). If you want to have f(x) for several x values, you create as many double as you want, this is the same for DerivativeStructure, you create one instance for each x value. Your example to create a function is almost good. It just misses one point: you don't use the derivatives of ds itself, only its value. This may be fine if you are sure ds is already your canonical variable, but it would not work if your function is the last step of a composition. The DerivativeStructure class has been created to handle the second case, which explains why it seems overkill in simpler cases. In fact, in your case you seem to already do separately the computation of the derivatives with separate code, using your someDerivativeCalculationHere function. This is the kind of things DerivativesStructure could do for you. In fact, as long as you have a way to implement someOperationHere using only Java (i.e. with primitive operations, Math/FastMath/StrictMath functions and even calls to intermediate functions, then you can reimplement it so it directly computes the derivatives at the same time and most importantly at any order, without requiring you to find the expression for the derivatives. This is the essence of automatic differentiation. There is even the Apache Commons Nable project (unfortunately not fully functional) that could do this for you, i.e. you give it a UnivariateFunction and it creates the corresponding UnivariateDifferentiableFunction automatically. What you seem to ask here is for something different: you already have the function and derivatives available, but probably only at the order at which you did code them. Then if you want to put the result in a DerivativeStructure instance, the class simply acts as a container for the values, and serves no other purpose. Then of course it seems complicated for just doing this. 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)
[jira] [Commented] (MATH-1143) Helper methods to FiniteDifferencesDifferentiator
[ https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14521457#comment-14521457 ] Alexander Nozik commented on MATH-1143: --- I do try to use DerivativeStructure in case it is not supposed to cover, but problem is that it is not always possible to present my function in the form of primitive operations composition. In my case the function is produced via numerical integration. For now Commons Math gives only two possibilities: work without derivatives at all or work with DerivativeStructure. So I am trying to do the later and not to reinvent the wheel. 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)
[jira] [Commented] (MATH-1143) Helper methods to FiniteDifferencesDifferentiator
[ https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=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)
[jira] [Commented] (MATH-1143) Helper methods to FiniteDifferencesDifferentiator
[ https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14521576#comment-14521576 ] Alexander Nozik commented on MATH-1143: --- Thank you Luc, I think that's what I needed. 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)
[jira] [Commented] (MATH-1143) Helper methods to FiniteDifferencesDifferentiator
[ https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14520131#comment-14520131 ] Thomas Neidhart commented on MATH-1143: --- Examples: evaluation {code} public static double derivative(UnivariateDifferentiableFunction f, double x, int order) { DerivativeStructure ds = f.value(new DerivativeStructure(1, order, 0, x)); return ds.getPartialDerivative(order); } {code} derivative function {code} public static UnivariateFunction derivative(final UnivariateDifferentiableFunction f, final int order) { return new UnivariateFunction() { @Override public double value(double x) { DerivativeStructure ds = f.value(new DerivativeStructure(1, order, 0, x)); return ds.getPartialDerivative(order); } }; } {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)
[jira] [Commented] (MATH-1143) Helper methods to FiniteDifferencesDifferentiator
[ https://issues.apache.org/jira/browse/MATH-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14520099#comment-14520099 ] Thomas Neidhart commented on MATH-1143: --- What helper methods do you have in mind? For example to get the first / second order derivative of a univariate function? 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)