Skip to content

Custom iteration stopping #105

Open
Open
@jrbourbeau

Description

@jrbourbeau

We could consider allowing callbacks that enables custom, user-defined iteration stopping.

For example, there are cases where users may want to compare unfolded distributions to data distributions and stop unfolding iterations when some condition is met (e.g. a bias-variance tradeoff). I can imagine there are many possible stopping conditions, perhaps even different stopping conditions are appropriate for different analyses. It would be nice to support these situations.

Here's one potential way we could support user-defined stopping conditions:

from pyunfold.callbacks import Callback

# Create custom callback that will stop unfolding iterations when some condition is met
class CustomStoppingCondition(Callback):
    def __init__(self):
        super(Callback, self).__init__()
        pass

    def on_iteration_end(self, iteration, status):
        # Define stopping condition logic here
        stopping_condition_met = ...
        if stopping_condition_met:
            # stop iterating
        else:
            # keep iterating


iteration_stopping = CustomStoppingCondition()
unfolded_result = iterative_unfold(data=data,
                                   data_err=data_err,
                                   response=response,
                                   response_err=response_err,
                                   efficiencies=efficiencies,
                                   efficiencies_err=efficiencies_err,
                                   callbacks=iteration_stopping)

Personally, I think this would fit nicely into the existing callback interface. I'm curious to see what other think about this.

cc @zhampel @mkuusela

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions