Skip to content

Instantly share code, notes, and snippets.

@GongXinyuu
Created March 5, 2021 03:38
Show Gist options
  • Select an option

  • Save GongXinyuu/cbc2ef6f146cbeee7128f0e7af72faea to your computer and use it in GitHub Desktop.

Select an option

Save GongXinyuu/cbc2ef6f146cbeee7128f0e7af72faea to your computer and use it in GitHub Desktop.
bi-hinge
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