Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

non-linear optimization: jacobi_solve question

Petros_Mamales
Beginner
446 Views

I have tried to use the same _JACOBIMATRIX_HANDLE_t to make evaluations of the jacobian at successive iteration points of the optimizer,

but the output matrix (fjac) is not getting updated.

I created an example, that isolates the issue and this does not seem to be possible. Am I correct ?

If yes, is there something I could do to "reset" the handle ? It would seem to me that this would be the desirable behavior, so that repeated initializaions of the handle and buffers are avoided.

TIA for your help,

Petros

ps: I attach the file. It is a watered-down  version of a much bigger project.

Some "tips" to make reading easier :

function evaluator : a wrapper of a member class that delivers the function call. wraps the class object and the method name.

extended_powell : the usual example in class dress.

NumericalJacobian: the class that wraps the mkl functionality

ublas::unbounded_array: similar to std::vector but with guaranteed contiguous memory layout.

ublas::matrix: the obvious.

0 Kudos
14 Replies
Ying_H_Intel
Employee
446 Views

Hi Petros,

i try to run your code and get the result

1       10      0       0
0       -0      2.23607 -2.23607
0       -2      4       0
12.6491 -0      0       -12.6491
0       0       0       0
0       0       0       0
0       0       0       0
0       0       0       0

is that expected?

Regarding the handle, generally, it is for keep parameter and internal buffer, user can't change it manually during iteration process. There is one function djacobix  Alternative interface for ?jacobi function for passing
additional data into the objective function., which can enables user to pass data to fcn.  is that usable?

Best Regards,

Ying

0 Kudos
SergeyKostrov
Valued Contributor II
446 Views
By the way, I tried to compile your test case but it has two dependencies on a Boost library: ... // boost #include "boost/numeric/ublas/storage.hpp" #include "boost/numeric/ublas/matrix.hpp" ...
0 Kudos
Petros_Mamales
Beginner
446 Views

Sergey,

Boost is very standard source of c++ libraries ( not standard as the stl is standard). O/wise, since C does not provide w/vector, matrix classes would have to write more (and more obscure) code. You can find it in www.boost.org. This part of the library is c++ header files so you will not even need to compile/build it. It is in template form so you will need a good c++ compiler, but this should not be a problem for you.

Ying,

No this is not the expected behavior. The first part is correct but in the second, I obtain a zero matrix. What really happens there is I calculate the jacobian for certain x and then recalculate it for an x where only the 0th component has been displaced ( as would happen in a possible solver search) and then it produces a zero matrix.

Hence, the question: can one use the same Jacobi handle multiple times ? or they need to reset it ?

Thank you for your help,

Petros

0 Kudos
SergeyKostrov
Valued Contributor II
446 Views
>>...Boost is very standard source of c++ libraries ( not standard as the stl is standard). O/wise, since C does not provide >>w/vector, matrix classes would have to write more (and more obscure) code. You can find it in www.boost.org. This >>part of the library is c++ header files so you will not even need to compile/build it... Thanks and I know this. Unfortunately, I don't use the Boost and STL is used instead.
0 Kudos
Petros_Mamales
Beginner
446 Views

It is not "instead". A lot of things from boost became stl with time. But the numeric part has not. But as you say you know this.

Then don't I understand something ? Ying seems to have run fine the code I sent.

 

Update : I understand now. You, probably,  say you are not set up for boost. In this case, thank you for trying to answer my question.

0 Kudos
SergeyKostrov
Valued Contributor II
446 Views

Petros, This is simply a note: I don't have Boost library on any computers around me. Sorry about this.

0 Kudos
Petros_Mamales
Beginner
446 Views

In the end of the day, I don't think that my basic question on the reusability of the jacobi handle has been addressed.

Irrespectively of my specific example, in general, can one use the same handle for two consecutive calculations of Jacobi matrix ? ( assuming same dimensions ).

Also, can you disclose if something other than a simple finite difference is happenning in the mkl-provided functionality ? Is the eps the accuracy sought ( for example using automatic differentiation ), or is simply the displacement in the finite differences ?

TIA for your help,

Petros

0 Kudos
mecej4
Honored Contributor III
446 Views

Petros Mamales wrote:
In the end of the day, I don't think that my basic question on the reusability of the jacobi handle has been addressed.

I am afraid that by tying your question to Boost you have created so high a barrier that the number of responses may well remain close to zero. Personally, I am a casual user of C++ and, regardless of how great and free Boost is, I am not going to struggle with downloading and installing a 100 MB source code library just to examine a rather simple issue. If you can rephrase the question in terms of C (or, with less enthusiasm from me, C++ with STL), I may be inclined to examine the problem.

0 Kudos
Petros_Mamales
Beginner
446 Views

Hi Mecej4,

Will do. However, my question expects a yes or no answer. It should not need the code.

MKL  should be able to tell me what the intended usage/behavior is. The code would be necessary, if this was challenged - I am not doing this.

Thank you for your help, Petros

ps: Please, be assured that a) it did take work one my part to strip things down from my project to provide with the example, and b) I would not subject you to a "struggle", if more was needed than download and untar aheader-only library (hence no installation needed).

Unfortunately, neither C nor stl provide with structures for vectors and matrices and providing an example written using boost should have made things easier to read.

Finally, I did ask about oher things ( what the eps mean? does it perform automatic differentiation ? ) for which lack of certain libraries should not prohibit some response ;-)).

At this point it gets easier for me to drop the jacobi capability altogether and suggest that in a future release of MKL you provide with the functionality, if the corresponding function pointer is NULL, that the jacobian is calculated internally ( it is not that users are told what is done, anyway ).

0 Kudos
Ying_H_Intel
Employee
446 Views

Hi Petros,

Regarding the question itself, the answer is no, you can't use same handle for different x. (even they are  successive iteration point).

in your case, when the first interation complete, the handle have include success information,  then when the second start, it return sucess directly without any operation. as a result,  you get 0 where you set pfjac=0. std::fill_n( pfjac_, n*m, _T1(0) ) ;

some discussion,

1. why you need keep the handle itself? 

if your target is to get fjac. and there is another functions djacobi which can give your fjac with different x.  which don't need maitain handle and init and deleted.

djocobi can compute the fjac directly and djacobi_solver compute the fjac with RCI interface, It computes some element of fjac result by x+-esp and iteration . I guess, some elements of fjac are same when x and x+esp.  so you hope to save the steps, right?  If yes, there are still logical problem within the iteration.

2. djacobi_sover  require re-init, and you ask reset. as i understand, the re-init and reset have same functions. why you hope a reset instead re-init? 

Just guess, as you are using C++, the init in construct function,  so reset may usable during computing, right?

Best Regards,

Ying

 

0 Kudos
Petros_Mamales
Beginner
446 Views

Hi Ying,

Thank you very much for your reply. The real reason one wants to be able to re-use the same handle, is that one avoids allocation/deallocation of resources( memory) for every calculation of the Jacobian.IN TR search, for example, one needs to calculate the jacobian a number of times.It makes no sense to allocate/free auxiliary memory each time.

Actually I cannot think of a good reason for the current usage model of the Jacobian handle but so be it. In the end of the day, a lot of effort was wasted to perform some finite differences!

Again, thank you,

Petros

0 Kudos
Ying_H_Intel
Employee
446 Views

Hi Petros,

Thank you alot for the feedback.  right, It makes sense.  Do you like me to submit a feature request to mkl developer team about add one reset function for the memory reused purpose?

Best Regards,
Ying

0 Kudos
Petros_Mamales
Beginner
446 Views

Hi Ying,

As far as I am concerned, this is trhe way it should be.

As I have decided to drop the functionality for my usage, I am, however, rather indifferent for its future.

I would like to make the observation, though, that both the design and the documentation of some newer features of mkl leave quite some to be  desired. Litterally, the usage model of the jacobi handle, as it stands now, requests from the user to turn off and re-turn on their tv set every time they need to change chanel.

All the Best,

Petros

0 Kudos
Ying_H_Intel
Employee
446 Views

Hi Petros,

I create a request DPD200343482. we will track it.  If you have the explict F function,  you can use the djacobi() direclty. 

The RCI Interface is designed for who do not have an option to fit the calculations into the function with the fixed API. but it missed to  consider the situation of iteration.  Thank you again for pointing out the problem.

Best Regads,
Ying

0 Kudos
Reply