Created
March 5, 2021 03:38
-
-
Save GongXinyuu/cbc2ef6f146cbeee7128f0e7af72faea to your computer and use it in GitHub Desktop.
bi-hinge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BiHingeLinearTransform: | |
| """ | |
| f(x) = max(0, (x - max_thres) * s) + max(0, (min_thres - x) * s) | |
| """ | |
| def __init__(self, scaling, min_thres, max_thres): | |
| self.scaling = scaling | |
| assert min_thres <= max_thres | |
| self.min_thres = min_thres | |
| self.max_thres = max_thres | |
| @classmethod | |
| def from_config(cls, config: Dict[str, Any]) -> "HingeLinearTransform": | |
| return cls(config.get("scaling", 1.0), config["min_thres"], config["max_thres"]) | |
| def __call__(self, cost): | |
| return max(0, (cost - self.max_thres) * self.scaling) + max( | |
| 0, (self.min_thres - cost) * self.scaling | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment