neuralogic.core.constructs.function package

Submodules

neuralogic.core.constructs.function.concat module

class ConcatAggregation(name: str, *, axis: int = -1)[source]

Bases: AggregationFunction

Represents a concatenation aggregation function that joins multiple groundings along a specified axis.

axis
get() Any[source]

Returns the Java representation of the function.

Returns:

The Java function object.

Return type:

Any

is_parametrized() bool[source]
class ConcatCombination(name: str, *, axis: int = -1)[source]

Bases: CombinationFunction

Represents a concatenation combination function that joins multiple tensors along a specified axis.

axis
get() Any[source]

Returns the Java representation of the function.

Returns:

The Java function object.

Return type:

Any

is_parametrized() bool[source]

neuralogic.core.constructs.function.enum module

class Aggregation[source]

Bases: object

Collection of aggregation functions. Aggregation functions are used to aggregate multiple inputs, typically from different groundings of the same rule.

AVG: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
CONCAT: ConcatAggregation = <neuralogic.core.constructs.function.concat.ConcatAggregation object>
COUNT: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
MAX: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
MIN: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
SOFTMAX: SoftmaxAggregation = <neuralogic.core.constructs.function.softmax.SoftmaxAggregation object>
SUM: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
class Combination[source]

Bases: object

Collection of combination functions. Combination functions are used to combine multiple inputs into a single output, often as part of a rule body or for combining multiple rules.

AVG: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
CONCAT: ConcatCombination = <neuralogic.core.constructs.function.concat.ConcatCombination object>
COSSIM: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
COUNT: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
CROSSSUM: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
ELPRODUCT: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
MAX: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
MIN: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
PRODUCT: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
SOFTMAX: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
SPARSEMAX: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
SUM: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
class F[source]

Bases: object

Utility class providing a flat namespace for common functions. It includes transformation, combination, and aggregation functions.

avg: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
avg_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
concat: ConcatCombination = <neuralogic.core.constructs.function.concat.ConcatCombination object>
concat_agg: ConcatAggregation = <neuralogic.core.constructs.function.concat.ConcatAggregation object>
cossim: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
count: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
count_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
crossum: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
elproduct: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
exp: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
identity: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
inverse: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
leaky_relu: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
log: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
lukasiewicz: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
max: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
max_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
min: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
min_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
norm: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
product: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
relu: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
reshape: Reshape = <neuralogic.core.constructs.function.reshape.Reshape object>
reverse: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
sigmoid: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
signum: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
slice: Slice = <neuralogic.core.constructs.function.slice.Slice object>
softmax: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
softmax_agg: SoftmaxAggregation = <neuralogic.core.constructs.function.softmax.SoftmaxAggregation object>
softmax_comb: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
sparsemax: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
sparsemax_comb: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
sqrt: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
sum: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
sum_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
tanh: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
transp: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
class Transformation[source]

Bases: object

Collection of transformation functions. Transformation functions are applied element-wise or as join operations (e.g., Softmax, Transpose).

EXP: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
IDENTITY: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
INVERSE: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
LEAKY_RELU: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
LOG: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
LUKASIEWICZ: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
NORM: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
RELU: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
RESHAPE: Reshape = <neuralogic.core.constructs.function.reshape.Reshape object>
REVERSE: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SIGMOID: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SIGNUM: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SLICE: Slice = <neuralogic.core.constructs.function.slice.Slice object>
SOFTMAX: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SPARSEMAX: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SQRT: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
TANH: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
TRANSP: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>

neuralogic.core.constructs.function.function module

class AggregationFunction(name: str, *, namespace: str = '', operator: str | None = None, can_flatten: bool = False)[source]

Bases: Function

Represents an aggregation function used to aggregate multiple groundings of the same rule.

can_flatten
get() Any[source]

Returns the Java representation of the function.

Returns:

The Java function object.

Return type:

Any

name: str
namespace
operator: str | None
class CombinationFunction(name: str, *, namespace: str = 'combination.{name}', operator: str | None = None, can_flatten: bool = False)[source]

Bases: Function

Represents a combination function used to combine multiple relations into a single output.

can_flatten
name: str
namespace
operator: str | None
class Function(name: str, *, namespace: str = '', operator: str | None = None, can_flatten: bool = False)[source]

Bases: object

Base class for all logic functions (transformation, combination, aggregation). Functions are used to transform, combine, or aggregate values in the logic program.

can_flatten
get() Any[source]

Returns the Java representation of the function.

Returns:

The Java function object.

Return type:

Any

is_parametrized() bool[source]
name: str
namespace
operator: str | None
pretty_str() str[source]
process_head(head: Any) Function[source]
rule_head_dependant() bool[source]
wrap(content: str) str[source]
class TransformationFunction(name: str, *, namespace: str = 'transformation.elementwise.{name}', operator: str | None = None, can_flatten: bool = False)[source]

Bases: Function

Represents a transformation function applied to a relation or a container of relations. Transformation functions can be applied element-wise or as join operations.

can_flatten
name: str
namespace
operator: str | None

neuralogic.core.constructs.function.function_container module

class FContainer(nodes: Iterable[Any], function: Function)[source]

Bases: object

A container for multiple logic nodes (relations or other containers) and a function to apply to them.

It allows for nesting and building complex function graphs.

function
static get_flattened_nodes(nodes: Iterable[Any], function: Function) tuple[source]

Flattens the nodes if they are FContainers with the same function.

Parameters:
  • nodes (Iterable[Any]) – The nodes to flatten.

  • function (Function) – The function used for flattening criteria.

Returns:

The flattened nodes.

Return type:

tuple

property name: str
nodes
to_function() Function[source]

Converts the container and its nested structure into a FunctionGraph.

Returns:

The generated FunctionGraph.

Return type:

Function

to_str(parentheses_wrap: bool = False) str[source]

Returns a string representation of the container.

Parameters:

parentheses_wrap (bool) – Whether to wrap the output in parentheses. Default: False.

Returns:

The string representation.

Return type:

str

neuralogic.core.constructs.function.function_graph module

class FunctionGraph(name: str, *, function_graph)[source]

Bases: Function

function_graph
get()[source]

Returns the Java representation of the function.

Returns:

The Java function object.

Return type:

Any

is_parametrized() bool[source]

neuralogic.core.constructs.function.reshape module

class Reshape(name: str, *, shape: tuple[int, int] | int | None = None)[source]

Bases: TransformationFunction

Represents a reshape transformation function that changes the shape of a tensor.

get() Any[source]

Returns the Java representation of the function.

Returns:

The Java function object.

Return type:

Any

is_parametrized() bool[source]
shape
wrap(content: str) str[source]

neuralogic.core.constructs.function.slice module

class Slice(name: str, *, rows: EllipsisType | tuple[int, int] = Ellipsis, cols: EllipsisType | tuple[int, int] = Ellipsis)[source]

Bases: TransformationFunction

Represents a slice transformation function that extracts a sub-tensor from a tensor.

cols
get() Any[source]

Returns the Java representation of the function.

Returns:

The Java function object.

Return type:

Any

is_parametrized() bool[source]
rows
wrap(content: str) str[source]

neuralogic.core.constructs.function.softmax module

class SoftmaxAggregation(name: str, *, agg_terms: Sequence[str] | None = None)[source]

Bases: AggregationFunction

Represents a Softmax aggregation function. It can be parametrized by specific terms (variables) to aggregate over.

agg_terms
get() Any[source]

Returns the Java representation of the function.

Returns:

The Java function object.

Return type:

Any

is_parametrized() bool[source]
process_head(head) SoftmaxAggregation[source]

Processes the rule head to determine the indices of the aggregation terms.

Parameters:

head (Any) – The rule head.

Returns:

A new instance with the determined term indices.

Return type:

SoftmaxAggregation

rule_head_dependant() bool[source]
var_terms

Module contents

class Aggregation[source]

Bases: object

Collection of aggregation functions. Aggregation functions are used to aggregate multiple inputs, typically from different groundings of the same rule.

AVG: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
CONCAT: ConcatAggregation = <neuralogic.core.constructs.function.concat.ConcatAggregation object>
COUNT: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
MAX: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
MIN: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
SOFTMAX: SoftmaxAggregation = <neuralogic.core.constructs.function.softmax.SoftmaxAggregation object>
SUM: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
class Combination[source]

Bases: object

Collection of combination functions. Combination functions are used to combine multiple inputs into a single output, often as part of a rule body or for combining multiple rules.

AVG: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
CONCAT: ConcatCombination = <neuralogic.core.constructs.function.concat.ConcatCombination object>
COSSIM: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
COUNT: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
CROSSSUM: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
ELPRODUCT: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
MAX: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
MIN: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
PRODUCT: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
SOFTMAX: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
SPARSEMAX: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
SUM: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
class F[source]

Bases: object

Utility class providing a flat namespace for common functions. It includes transformation, combination, and aggregation functions.

avg: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
avg_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
concat: ConcatCombination = <neuralogic.core.constructs.function.concat.ConcatCombination object>
concat_agg: ConcatAggregation = <neuralogic.core.constructs.function.concat.ConcatAggregation object>
cossim: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
count: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
count_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
crossum: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
elproduct: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
exp: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
identity: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
inverse: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
leaky_relu: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
log: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
lukasiewicz: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
max: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
max_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
min: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
min_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
norm: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
product: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
relu: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
reshape: Reshape = <neuralogic.core.constructs.function.reshape.Reshape object>
reverse: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
sigmoid: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
signum: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
slice: Slice = <neuralogic.core.constructs.function.slice.Slice object>
softmax: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
softmax_agg: SoftmaxAggregation = <neuralogic.core.constructs.function.softmax.SoftmaxAggregation object>
softmax_comb: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
sparsemax: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
sparsemax_comb: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
sqrt: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
sum: CombinationFunction = <neuralogic.core.constructs.function.function.CombinationFunction object>
sum_agg: AggregationFunction = <neuralogic.core.constructs.function.function.AggregationFunction object>
tanh: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
transp: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
class FContainer(nodes: Iterable[Any], function: Function)[source]

Bases: object

A container for multiple logic nodes (relations or other containers) and a function to apply to them.

It allows for nesting and building complex function graphs.

function
static get_flattened_nodes(nodes: Iterable[Any], function: Function) tuple[source]

Flattens the nodes if they are FContainers with the same function.

Parameters:
  • nodes (Iterable[Any]) – The nodes to flatten.

  • function (Function) – The function used for flattening criteria.

Returns:

The flattened nodes.

Return type:

tuple

property name: str
nodes
to_function() Function[source]

Converts the container and its nested structure into a FunctionGraph.

Returns:

The generated FunctionGraph.

Return type:

Function

to_str(parentheses_wrap: bool = False) str[source]

Returns a string representation of the container.

Parameters:

parentheses_wrap (bool) – Whether to wrap the output in parentheses. Default: False.

Returns:

The string representation.

Return type:

str

class Function(name: str, *, namespace: str = '', operator: str | None = None, can_flatten: bool = False)[source]

Bases: object

Base class for all logic functions (transformation, combination, aggregation). Functions are used to transform, combine, or aggregate values in the logic program.

can_flatten
get() Any[source]

Returns the Java representation of the function.

Returns:

The Java function object.

Return type:

Any

is_parametrized() bool[source]
name: str
namespace
operator: str | None
pretty_str() str[source]
process_head(head: Any) Function[source]
rule_head_dependant() bool[source]
wrap(content: str) str[source]
class Transformation[source]

Bases: object

Collection of transformation functions. Transformation functions are applied element-wise or as join operations (e.g., Softmax, Transpose).

EXP: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
IDENTITY: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
INVERSE: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
LEAKY_RELU: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
LOG: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
LUKASIEWICZ: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
NORM: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
RELU: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
RESHAPE: Reshape = <neuralogic.core.constructs.function.reshape.Reshape object>
REVERSE: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SIGMOID: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SIGNUM: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SLICE: Slice = <neuralogic.core.constructs.function.slice.Slice object>
SOFTMAX: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SPARSEMAX: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
SQRT: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
TANH: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>
TRANSP: TransformationFunction = <neuralogic.core.constructs.function.function.TransformationFunction object>