Closed JHartzer closed 1 year ago
@JHartzer thank you for the observation! I looked here and I have found the numdifftools
package. I will make some tests and if it works as expected I will migrate to it 😃 As you said, I think that this will improve the clarity of what is being done.
Hi @JHartzer! Thank you for the suggestion 😃 I have integrated numdifftools
for the gradient calculation. Now you can use it with something like yours example:
>>> import numpy as np
>>> import pyswarming.behaviors as pb
>>> f = lambda x: np.sqrt(x[0]+x[1]+x[2])
>>> pb.geofencing(np.array([1,2,3]), f)
array([-0.53146485, -0.53146485, -0.53146485])
The module
auto_differentiation.py
seems to add significant complexity to the package without much benefit since it is only used for the gradient calculation. At the moment, it doesn't seem clear that to use thegeofencing
function with more complex functions, those functions must be imported fromauto_differentiation
e.g.from pyswarming.auto_differentiation import sin, cos, erf
instead of using the existing math or numpy functions. A user (such as myself) might attempt the following and be confused by the resultWould it make more sense to utilize numeric gradient calculation to improve the clarity of what is being done and allow users to create even more complex functions using other libraries? I think that would produce results with all the accuracy needed for the behaviors without needlessly increasing complexity and limiting users in the construction of their geofencing functions.