Source code for neuralogic.core.constructs.function.function

[docs] class Function: __slots__ = ("name",) def __init__(self, name: str): self.name: str = name.lower() def __str__(self): return self.name
[docs] def wrap(self, content: str) -> str: return f"{self.name}({content})"
[docs] def pretty_str(self) -> str: return str(self).capitalize()
def __call__(self, *args, **kwargs): if len(args) == 0 or args[0] is None: return self raise NotImplementedError
[docs] def is_parametrized(self) -> bool: return False
[docs] def get(self): raise NotImplementedError
[docs] def rule_head_dependant(self) -> bool: return False
[docs] def process_head(self, head) -> "Function": pass
[docs] class Transformation(Function): # Element wise SIGMOID: "Transformation" TANH: "Transformation" SIGNUM: "Transformation" RELU: "Transformation" LEAKY_RELU: "Transformation" LUKASIEWICZ: "Transformation" EXP: "Transformation" SQRT: "Transformation" INVERSE: "Transformation" REVERSE: "Transformation" LOG: "Transformation" # Transformation IDENTITY: "Transformation" TRANSP: "Transformation" SOFTMAX: "Transformation" SPARSEMAX: "Transformation" NORM: "Transformation" SLICE: "Transformation" RESHAPE: "Transformation" def __call__(self, *args, **kwargs): from neuralogic.core.constructs import relation if len(args) == 0 or args[0] is None: return self arg = args[0] if isinstance(arg, relation.BaseRelation): return arg.attach_activation_function(self) raise NotImplementedError
[docs] class Combination(Function): # Aggregation AVG: "Combination" MAX: "Combination" MIN: "Combination" SUM: "Combination" COUNT: "Combination" # Combination PRODUCT: "Combination" ELPRODUCT: "Combination" SOFTMAX: "Combination" SPARSEMAX: "Combination" CROSSSUM: "Combination" CONCAT: "Combination" COSSIM: "Combination"
[docs] class Aggregation(Function): AVG: "Aggregation" MAX: "Aggregation" MIN: "Aggregation" SUM: "Aggregation" COUNT: "Aggregation" CONCAT: "Aggregation" SOFTMAX: "Aggregation"