简体   繁体   中英

Distinguish the local/global invocation in basinhopping (scipy)

I am using spicy.optimize.basinhopping with a user-defined objective function c_func ported from C++ (using ctypes ), and an initial point x :

scipy.optimize.basinhopping(x, c_func)

If I understand correctly basinhopping, c_func will be called by basinhopping as a black-box function in both its global and local optimization parts. In my situation, the function need to know whether the invocation comes from the local or the global optimization process. How can I achieve it? We can Imagine the c_func is defined as follows:

myClass:: c_func(double){
        if ( invoked by the local optimization) {
                    std::cout<<“Local\n”;
       else 
                    std::cout<<“Global\n”;
       }

[EDITS] I was thinking to use callback functions. But the callback function in the interface of scipy.optimize.basinhopping , or scipy.optimize.minimize are invoked after the function c_func is called.

I'm pretty sure the function is only ever called from the minimizer. Basinhopping gets the function value from the return value of the minimizer. In the source code the function is not even passed the basinhopping class, only the wrapped minimizer is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM