Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial BoundPenalty class #266

Open
nikohansen opened this issue Sep 19, 2024 · 0 comments
Open

Serial BoundPenalty class #266

nikohansen opened this issue Sep 19, 2024 · 0 comments

Comments

@nikohansen
Copy link
Contributor

nikohansen commented Sep 19, 2024

To have a wrapper like in #265, a new BoundPenalty2.repair function should immediately update the penalty weights. This introduces a slight noise for (change of) the gradient perpendicular to the boundary, but this may not necessarily be a disadvantage.

Conceptual draft of the usecase of BoundPenalty2:

class WrapperBoundPenalty:
    def __init__(self, fun, bounds, size=222):
        self.fun = fun
        self.bound_penalty = BoundPenalty2(bounds)
        self.transform = self.bound_penalty.repair
        self.fvalues = collections.deque(maxlen=size)
        self.penalties = collections.deque(maxlen=size)
    def __call__(self, x):
        self.fvalues.append(self.fun(self.transform(x)))
        self.penalties.append(self.boundary_penalty.penalty)
        return self.fvalues[-1] + self.penalties[-1]
    @property
    def penalty(self):
        """last penalty"""
        return self.penalties[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant