neuralogic.core.constructs packageο
Subpackagesο
- neuralogic.core.constructs.function package
- Submodules
- neuralogic.core.constructs.function.concat module
- neuralogic.core.constructs.function.enum module
AggregationCombinationFF.avgF.avg_aggF.concatF.concat_aggF.cossimF.countF.count_aggF.crossumF.elproductF.expF.identityF.inverseF.leaky_reluF.logF.lukasiewiczF.maxF.max_aggF.minF.min_aggF.normF.productF.reluF.reshapeF.reverseF.sigmoidF.signumF.sliceF.softmaxF.softmax_aggF.softmax_combF.sparsemaxF.sparsemax_combF.sqrtF.sumF.sum_aggF.tanhF.transp
TransformationTransformation.EXPTransformation.IDENTITYTransformation.INVERSETransformation.LEAKY_RELUTransformation.LOGTransformation.LUKASIEWICZTransformation.NORMTransformation.RELUTransformation.RESHAPETransformation.REVERSETransformation.SIGMOIDTransformation.SIGNUMTransformation.SLICETransformation.SOFTMAXTransformation.SPARSEMAXTransformation.SQRTTransformation.TANHTransformation.TRANSP
- neuralogic.core.constructs.function.function module
- neuralogic.core.constructs.function.function_container module
- neuralogic.core.constructs.function.function_graph module
- neuralogic.core.constructs.function.reshape module
- neuralogic.core.constructs.function.slice module
- neuralogic.core.constructs.function.softmax module
- Module contents
AggregationCombinationFF.avgF.avg_aggF.concatF.concat_aggF.cossimF.countF.count_aggF.crossumF.elproductF.expF.identityF.inverseF.leaky_reluF.logF.lukasiewiczF.maxF.max_aggF.minF.min_aggF.normF.productF.reluF.reshapeF.reverseF.sigmoidF.signumF.sliceF.softmaxF.softmax_aggF.softmax_combF.sparsemaxF.sparsemax_combF.sqrtF.sumF.sum_aggF.tanhF.transp
FContainerFunctionTransformationTransformation.EXPTransformation.IDENTITYTransformation.INVERSETransformation.LEAKY_RELUTransformation.LOGTransformation.LUKASIEWICZTransformation.NORMTransformation.RELUTransformation.RESHAPETransformation.REVERSETransformation.SIGMOIDTransformation.SIGNUMTransformation.SLICETransformation.SOFTMAXTransformation.SPARSEMAXTransformation.SQRTTransformation.TANHTransformation.TRANSP
Submodulesο
neuralogic.core.constructs.factories moduleο
- class AtomFactory[source]ο
Bases:
objectFactory for creating atoms (relations) in the logic program. It supports dot notation for predicate names and provides access to special and hidden factories.
- get(name: str) BaseRelation[source]ο
Creates a relation with the given name and 0 arity.
- Parameters:
name (str) β The name of the predicate.
- Returns:
The created relation.
- Return type:
- class ConstantFactory[source]ο
Bases:
objectFactory for creating constants. Constants are automatically converted to lowercase unless specified otherwise.
- class HiddenPredicateFactory[source]ο
Bases:
objectFactory for creating hidden predicates. Hidden predicates are not part of the output unless explicitly requested.
- get(name: str) BaseRelation[source]ο
- property special: SpecialPredicateFactoryο
- class SpecialPredicateFactory(hidden: bool = False)[source]ο
Bases:
objectFactory for creating special predicates, such as βalldiffβ, βneqβ, βeqβ, etc. Special predicates are handled differently by the backend engine.
- add(a: Any, b: Any, c: Any) BaseRelation[source]ο
- add_eval(a: Any, b: Any) BaseRelation[source]ο
- alldiff(*args: Any) BaseRelation[source]ο
- anypred() BaseRelation[source]ο
- div_eval(a: Any, b: Any) BaseRelation[source]ο
- eq(a: Any, b: Any) BaseRelation[source]ο
- geq(a: Any, b: Any) BaseRelation[source]ο
- get(name: str) BaseRelation[source]ο
Creates a special relation with the given name and 0 arity.
- Parameters:
name (str) β The name of the special predicate.
- Returns:
The created special relation.
- Return type:
- gt(a: Any, b: Any) BaseRelation[source]ο
- leq(a: Any, b: Any) BaseRelation[source]ο
- lt(a: Any, b: Any) BaseRelation[source]ο
- max_eval(a: Any, b: Any) BaseRelation[source]ο
- maxcard(*args: Any) BaseRelation[source]ο
- min_eval(a: Any, b: Any) BaseRelation[source]ο
- mod(a: Any, b: Any, c: Any) BaseRelation[source]ο
- mod_eval(a: Any, b: Any) BaseRelation[source]ο
- mul_eval(a: Any, b: Any) BaseRelation[source]ο
- neq(a: Any, b: Any) BaseRelation[source]ο
- next(a: Any, b: Any) BaseRelation[source]ο
- sub(a: Any, b: Any, c: Any) BaseRelation[source]ο
- sub_eval(a: Any, b: Any) BaseRelation[source]ο
- truepred() BaseRelation[source]ο
neuralogic.core.constructs.java_objects moduleο
- class JavaFactory(settings: SettingsProxy | None = None)[source]ο
Bases:
objectFactory for converting high-level Python logic constructs (Atoms, Rules, etc.) into their corresponding Java objects. It maintains internal factories for predicates, constants, and weights.
- atom_to_clause(atom: Any) Any[source]ο
Converts a single atom to a Java Clause.
- Parameters:
atom (Any) β The atom to convert.
- Returns:
The Java Clause object.
- Return type:
Any
- get_conjunction(relations: Iterable[Any], variable_factory: Any, default_weight: Any = None, is_example: bool = False) Any[source]ο
- get_generic_relation(relation_class: Any, relation: Any, variable_factory: Any, default_weight: Any = None, is_example: bool = False) Any[source]ο
Generic method to convert a Python relation to a Java relation object.
- Parameters:
relation_class (Any) β The Java class of the relation (e.g., BodyAtom, ValuedFact).
relation (Any) β The Python relation object.
variable_factory (Any) β The Java variable factory.
default_weight (Any, optional) β A default weight if the relation is unweighted. Default: None.
is_example (bool) β Whether the relation is part of an example. Default: False.
- Returns:
The Java relation object.
- Return type:
Any
- get_lifted_example(example: Any, learnable_facts: bool = False) tuple[Any, Any][source]ο
Converts a Python example to a Java LiftedExample.
- Parameters:
example (Any) β The example to convert.
learnable_facts (bool) β Whether facts in the example should be learnable. Default: False.
- Returns:
A tuple containing the Java label conjunction and the Java LiftedExample.
- Return type:
tuple[Any, Any]
- get_query(query: Any) tuple[Any, list[Any] | None][source]ο
Converts a Python query to a Java representation.
- Parameters:
query (Any) β The query to convert. Can be a Rule, list of relations, or a single relation.
- Returns:
A tuple containing the Java head relation and a list of Java body relations.
- Return type:
tuple[Any, list[Any] | None]
- get_rule(rule: Any) Any[source]ο
Converts a Python Rule to a Java WeightedRule.
- Parameters:
rule (Any) β The Python rule to convert.
- Returns:
The Java WeightedRule object.
- Return type:
Any
- get_term(term: Any, variable_factory: Any) Any[source]ο
Converts a Python term (Variable, Constant, str, int, float) to a Java term.
- Parameters:
term (Any) β The term to convert.
variable_factory (Any) β The Java variable factory to use for variables.
- Returns:
The Java term object.
- Return type:
Any
- class ValueFactory[source]ο
Bases:
objectFactory for converting between Python values (scalars, lists, numpy arrays) and Java Value objects. It handles ScalarValue, VectorValue, and MatrixValue.
- static from_java(value: Any) float | list | ndarray[source]ο
Converts a Java Value object to a Python representation (float, list, or numpy array).
- Parameters:
value (Any) β The Java Value object to convert.
- Returns:
The Python representation of the value.
- Return type:
float | list | np.ndarray
- get_value(weight: Any) tuple[bool, Any][source]ο
Converts a Python weight to a Java Value object.
- Parameters:
weight (Any) β The weight to convert. Can be a scalar, tuple (for dimensions), list, or numpy array.
- Returns:
A tuple containing a boolean (True if initialized, False if just dimensions) and the Java Value object.
- Return type:
tuple[bool, Any]
neuralogic.core.constructs.metadata moduleο
- class Metadata(learnable: bool | None = None, transformation: TransformationFunction | CombinationFunction | None = None, combination: CombinationFunction | None = None, aggregation: AggregationFunction | None = None, duplicate_grounding: bool | None = None)[source]ο
Bases:
objectRepresents metadata for a logic construct (e.g., rule, predicate).
Metadata can specify properties like learnability, transformation functions, aggregation functions, and combination functions.
- aggregationο
- combinationο
- combine(other: Metadata) Metadata[source]ο
Combines this metadata with another Metadata object. Values from the other object take precedence.
- copy() Metadata[source]ο
Returns a shallow copy of the metadata.
- Returns:
The copy of the metadata.
- Return type:
- duplicate_groundingο
- static from_iterable(iterable: Iterable[Any]) Metadata[source]ο
Creates a Metadata object from an iterable of functions or values.
- Parameters:
iterable (Iterable) β The iterable containing metadata entries.
- Returns:
The created Metadata object.
- Return type:
- learnableο
- transformationο
neuralogic.core.constructs.predicate moduleο
neuralogic.core.constructs.relation moduleο
- class BaseRelation(predicate: Predicate, terms: Any = None, function: TransformationFunction | CombinationFunction | None = None, negated: bool = False)[source]ο
Bases:
objectRepresents a relation with a predicate, terms, and an optional activation function.
- property T: BaseRelationο
- attach_activation_function(function: TransformationFunction | CombinationFunction) BaseRelation[source]ο
Attaches an activation or combination function to the relation.
- Parameters:
function (Union[TransformationFunction, CombinationFunction]) β The function to attach.
- Returns:
A new relation with the attached function.
- Return type:
- functionο
- negatedο
- predicateο
- termsο
- class WeightedRelation(weight: Any, predicate: Predicate, fixed: bool = False, terms: Any = None, function: TransformationFunction | CombinationFunction | None = None)[source]ο
Bases:
BaseRelationRepresents a relation with an associated weight (learnable or fixed).
- property T: WeightedRelationο
- attach_activation_function(function: Transformation | Combination) WeightedRelation[source]ο
Attaches an activation or combination function to the relation.
- Parameters:
function (Union[TransformationFunction, CombinationFunction]) β The function to attach.
- Returns:
A new relation with the attached function.
- Return type:
- fixed() WeightedRelation[source]ο
Returns a copy of the relation with the weight fixed.
- Returns:
The weighted relation with a fixed weight.
- Return type:
- is_fixedο
- to_str(end=False)[source]ο
Returns a string representation of the relation.
- Parameters:
end (bool) β Whether to append a dot at the end. Default: False.
- Returns:
The string representation.
- Return type:
str
- weightο
- weight_nameο
neuralogic.core.constructs.rule moduleο
- class Rule(head: BaseRelation, body: RuleBody | Iterable[BodyItem] | BodyItem)[source]ο
Bases:
objectRepresents a rule in the model, consisting of a head and a body.
- body: list[BodyItem] | FContainerο
- headο
- class RuleBody(lit1: BaseRelation, lit2: BaseRelation)[source]ο
Bases:
objectRepresents the body of a rule, which is a collection of literals.
- literals: list['BaseRelation' | FContainer]ο