Piecewise evaluation helper.

If your evaluation (fitness) function is made up of a number of separate parts that each contribute to the overall SSE, you can call each part via an instance of me and iterate over my instance to run the fastest parts first. With the xSSE option enabled for DifferentialEvolution, that may avoid the need for the slower parts to run as much during challenges.

The sole constructor argument k identifies the position of a hashable argument to __call__ (starting with 0 for the first arg following func) that serves as an ID for the function part, uniquely identifies one flavor of a call to it for the overall evaluation.

For example, consider an evaluation function that involves calling the same callable f three times with a different integer ID as the first argument followed by an array of parameter values. You would set k to 0, since the first argument is the unique ID.

Method __init__ Undocumented
Method __call__ Call my instance with one part func of the overall fitness function with its args and any kw.
Method __iter__ I iterate over my IDs, in ascending order of the average time it took their function parts to run.

Inherited from Picklable:

Method __getstate__ Undocumented
Method __setstate__ Undocumented
def __init__(self, k):
Undocumented
def __call__(self, func, *args, **kw):

Call my instance with one part func of the overall fitness function with its args and any kw.

The func must return a Deferred result, and one of its arguments must be a unique identifying ID for the part it plays.

Updates my average for elapsed time of the call, using the arg at my ID index k as a dict key.

def __iter__(self):

I iterate over my IDs, in ascending order of the average time it took their function parts to run.

Does a sort of IDs by average time each time I iterate, which seems inefficient but really isn't. Sorting is very fast, and __call__ is probably being run more often than __iter__, so caching wouldn't make sense.

My times and Ns dicts can update while I'm iterating with no problems. I will keep using the ascending order I computed before I started yielding IDs.

API Documentation for ade, generated by pydoctor at 2022-11-17 13:13:22.