[Scilab-users] The numderivative function
Samuel Gougeon
sgougeon at free.fr
Sat Nov 18 23:41:00 CET 2017
Le 18/11/2017 à 22:38, Samuel Gougeon a écrit :
> Le 18/11/2017 à 22:01, Hermes a écrit :
>> Hi;
>> The numderivative function consumes a lot of time in the calculations.
>> In the following script I show two options for my "odes" function
>> In one of them I use the numderivative function; and the calculation is
>> extended by 9 minutes. And in the other I use the Jacobian determinant of
>> the function, for each variable, obtained in wxMaxima. And the calculation
>> is a few, few, seconds.
>> I am interested in using the function with numderivative, and very similar
>> to how I have developed it, since it allows me to use it for systems of more
>> equations.
>
> Your script makes Scilab 6.0.0 crashing every time it is run => trials
> done only on 5.5.2
>
> * I get *145 s* by default when numderivative() is called as usual
> from its library.
> Without numderivative(), i get *1.97 s*.
> * After
> exec(SCI+"/modules/optimization/macros/numderivative.sci",-1),
> this time decreases down to *45 s *only. This is unlikely proper
> to numderivative(). 5.5.2 looks to miss an optimization. For the
> time being, no way to test this on 6.0.0.
> * Your script calls numderivative() ~57000 times.
> * Profiling numderivative() and its dependencies shows that
> numderivative_evalf() spends a lot of time.
> * Replacing execstr(.., "errcatch") in numderivative_evalf() with
> try/catch, we get***38 s*
> * Then, mainly, vectorizing the function to derivate in order to
> accept x with N columns instead of only 1, and changing
> numderivative() in order to be able to work with this new
> vectorized profile, we get *29 s*.
>
> Improving numderivative() in order to be fully able to work with
> vectorized functions should be possible, but then
>
> * at first sight it will be less easy to keep it able to run with
> functions that are NOT vectorized (=> back-compatibility issue)
> * The jacobian would become an hypermatrix (OK)
> * The hessian would get up to 4 dimensions
>
This is assuming that the architecture of the current numderivative()
implementation is kept.
A complete refactoring would be possible. But used for ode(), IMO this
would not save much of the time spent, since anyway ode() calls the
function for a single point.
Beside the lack of vectorization, the order is not free. For instance,
order=3 needs to call numderivative() twice, for instance with order=2
then with order=1. This limitation is a bit strange.
SG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20171118/25da9c22/attachment.htm>
More information about the users
mailing list