ltnjax.core ¶
Classes:
| Name | Description |
|---|---|
Connective | Class representing an LTN connective. |
Constant | The class representing constants. |
Function | Class representing LTN functions. |
LTNObject | Class representing a generic LTN object. |
LambdaModel | Simple |
Predicate | Class representing an LTN predicate. |
Quantifier | Class representing an LTN quantifier. |
Variable | Class representing an LTN variable. |
Functions:
| Name | Description |
|---|---|
diag | Diagonalizes |
undiag | Resets the |
Attributes:
| Name | Type | Description |
|---|---|---|
VarLabel | |
Attributes¶
VarLabel module-attribute ¶
VarLabel = str
- API Reference
ltnjaxcore ClassesLTNObject Attributesfree_vars
Classes¶
Connective ¶
Class representing an LTN connective.
Wrapper for connectives that aggregates given LTNObject objects according a given aggregator operation connective_op and also broadcasts variables, see _broadcast_exprs.
Attributes:
| Name | Type | Description |
|---|---|---|
connective_op | Aggregation function. |
Methods:
| Name | Description |
|---|---|
__call__ | Applies the connective using the given |
__init__ | Constructor. |
Source code in src/ltnjax/core.py
Attributes¶
Methods:¶
__call__ ¶
Applies the connective using the given connective_op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| LTNObject | Tuple of LTN objects. | () |
| Any | Further arguments to pass to | {} |
Returns:
| Type | Description |
|---|---|
LTNObject | The resulting LTNObject object that |
LTNObject | combines the given |
Raises:
| Type | Description |
|---|---|
TypeError | If |
ValueError | If number of |
Source code in src/ltnjax/core.py
__init__ ¶
__init__(connective_op: ConnectiveOperator) -> None
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| ConnectiveOperator | Aggregation function. | required |
Constant ¶
Bases: LTNObject
flowchart TD
ltnjax.core.Constant[Constant]
ltnjax.core.LTNObject[LTNObject]
ltnjax.core.LTNObject --> ltnjax.core.Constant
click ltnjax.core.Constant href "" "ltnjax.core.Constant"
click ltnjax.core.LTNObject href "" "ltnjax.core.LTNObject"
The class representing constants.
A constant can be a tensor of any rank.
Attributes:
| Name | Type | Description |
|---|---|---|
value | Value of the constant that is a array of an arbitrary rank. | |
free_vars | list[VarLabel] | The free variables that are contained in the expression. |
trainable | list[VarLabel] | Flag indicating whether the LTN constant is trainable (embedding) or not. |
Methods:
| Name | Description |
|---|---|
__init__ | Constructor. |
__repr__ | Representation function. |
Source code in src/ltnjax/core.py
Methods:¶
__init__ ¶
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Any | An object that is convertible to an array. This includes JAX arrays, NumPy arrays, Python scalars, Python collections like lists and tuples, objects with an | required |
| bool | Flag indicating whether the LTN constant is trainable (embedding) or not. | False |
Source code in src/ltnjax/core.py
Function ¶
Bases: Module
flowchart TD
ltnjax.core.Function[Function]
click ltnjax.core.Function href "" "ltnjax.core.Function"
Class representing LTN functions.
A function that maps \(n\) tensors of any rank to one single tensor of any rank.
Attributes:
| Name | Type | Description |
|---|---|---|
model | A |
Note
modelwill be called with a tensor that has a batch dimension and optionally feature dimensions. The batch dimension is the axis that results from flattening the axes of the free variables. See _flatten_free_dims.
Methods:
| Name | Description |
|---|---|
__call__ | Evaluates the |
__init__ | Constructor. |
Source code in src/ltnjax/core.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
Attributes¶
Methods:¶
__call__ ¶
Evaluates the model of the given inputs and kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| LTNObject | tuple of LTNObject to apply on | () |
| Any | Further arguments to pass to | {} |
Returns:
| Type | Description |
|---|---|
LTNObject |
|
Raises:
| Type | Description |
|---|---|
TypeError | If |
Source code in src/ltnjax/core.py
__init__ ¶
__init__(model: Module | None = None, func: LambdaType | None = None) -> None
Constructor.
Initializes the LTN predicate in two different ways: 1. if model is not None, it initializes the predicate with the given nnx.Module; 2. if model is None, it uses the func as a function to define the LTN predicate. Note that, in this case, the LTN predicate is not learnable. So, the lambda function has to be used only for simple predicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Module | None | (default=None) A | None |
| LambdaType | None | (default=None) A lambda_expression. | None |
Raises:
| Type | Description |
|---|---|
ValueError | If either both |
TypeError | If |
Source code in src/ltnjax/core.py
LTNObject ¶
Bases: Module
flowchart TD
ltnjax.core.LTNObject[LTNObject]
click ltnjax.core.LTNObject href "" "ltnjax.core.LTNObject"
Class representing a generic LTN object.
An LTN object contains the results of an expression with variables free_vars.
In LTNjax, LTN objects are constants, variables, and outputs of predicates, formulas, functions, connectives, and quantifiers.
Internally this contains a tensor value and an ordered list free_vars. If the expression has \(n\) free_vars \(x_1,\dotsc,x_n\), then the first \(n\) axes belong to these variables. The rest is reserved for feature_dims the result. This can \([,\infty)\) many axes. For each setting of the free_vars, the tensor will contain the corresponding result. This gets more clear by looking at the example below.
The class extends nnx.Module since it may contain values.
Attributes:
| Name | Type | Description |
|---|---|---|
value | The result of the expression. If there are \(n\) | |
free_vars | list[VarLabel] | The free variables that are contained in the expression. |
Examples:
We define the variables \(x \in [1, 0]\) and \(y \in [0, 1]\) and the expression \(x * y\).
>>> import ltn
>>> x = ltn.Variable('x', [1., 0.])
>>> y = ltn.Variable('y', [0., 1.])
>>> prod = ltn.Connective(ltn.fuzzy_ops.AndProd(stable=False))
>>> res = prod(x, y)
If we choose x to be 1. (the value at index 0) and y to be 1. (the value at index 1), we get \(1 * 1 = 1\).
If we only choose y to be 1 (the value at index 0), we get the LTN object \(x * 1\). The result still depends on which x we chose. Either \(x=0\) and we get \(x * 1=0\) or \(x=1\) and we get \(x * 1=1\).
>>> print(res.take('y', 1))
LTNObject(value=Array(shape=(2,), dtype=dtype('float32')),\
free_vars=['x'])
>>> print(res.take('y', 1).value)
[1. 0.]
If we choose no variable, then the LTN object will contain all possible results:
>>> print(res)
LTNObject(value=Array(shape=(2, 2), dtype=dtype('float32')),\
free_vars=['x', 'y'])
>>> print(res.value)
[[0. 1.]
[0. 0.]]
Note that LTN objects can also be tensors of any rank:
>>> x = ltn.Variable('x', [[[3.1415926535, 2.7182818284],\
[1.414213562, .6931471805]], [[1., 0.], [0., 1.]]])
>>> print(x)
Variable(value=Array(shape=(2, 2, 2), dtype=dtype('float32')),\
free_vars=['x'], var_label='x')
>>> print(x.value)
[[[3.1415927 2.7182817]
[1.4142135 0.6931472]]
[[1. 0. ]
[0. 1. ]]]
- API Reference
ltnjax
Methods:
| Name | Description |
|---|---|
__init__ | Constructor. |
__repr__ | Representation function. |
shape | Returns the shape of the grounding of the LTN object. |
take | Take elements along the axis that corresponds to |
Source code in src/ltnjax/core.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
Attributes¶
Methods:¶
__init__ ¶
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| ArrayLike | The result of the expression. If there are \(n\) | required |
| list[VarLabel] | List of labels of free variables that are contained in the expression. | required |
| bool | Flag indicating whether the LTN constant is trainable (embedding) or not. | False |
Source code in src/ltnjax/core.py
__repr__ ¶
__repr__() -> str
Representation function.
Called by the repr() built-in function to compute the "official" string representation of an object.
Source code in src/ltnjax/core.py
_copy ¶
_copy() -> LTNObject
Copy function.
Copy the LTN object but point to the same tensor, for gradient tracking.
Returns:
| Type | Description |
|---|---|
LTNObject | Copy of this LTN object instance. |
_get_axis_of_free_var ¶
Axis of free_var.
Given a free variable free_var, returns the axis in attribute value that belongs to this free variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| VarLabel | Label of the free variable, whose axis we want. | required |
Returns:
| Type | Description |
|---|---|
int | Axis that belongs to the free variable |
Raises:
| Type | Description |
|---|---|
ValueError | If |
Source code in src/ltnjax/core.py
_get_dim_of_free_var ¶
Dimension of free_var.
Given a label free_var, returns the corresp. dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| VarLabel | The label of the variable. | required |
Returns:
| Type | Description |
|---|---|
int | The dimension that corresponds to variable |
Note
Do not confuse axis with dimension. The first is the position in the shape of value where the second is the value.
Source code in src/ltnjax/core.py
shape ¶
take ¶
Take elements along the axis that corresponds to free_var.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| VarLabel | The variable we want to fix. | required |
| int | list[int] | This is either an integer or a list of integers from \(\{0, \dotsc, n-1\}\) where \(n\) is the dimension of variable | required |
Returns:
| Type | Description |
|---|---|
LTNObject | The LTN object containing the elements along the axis that |
LTNObject | corresponds to |
Raises:
| Type | Description |
|---|---|
ValueError | If |
Source code in src/ltnjax/core.py
LambdaModel ¶
Bases: Module
flowchart TD
ltnjax.core.LambdaModel[LambdaModel]
click ltnjax.core.LambdaModel href "" "ltnjax.core.LambdaModel"
Simple nnx.Module that implements a lambda function.
Attributes:
| Name | Type | Description |
|---|---|---|
lambda_operator | Lambda expression. |
Methods:
| Name | Description |
|---|---|
__call__ | Calls the lambda function with |
__init__ | Constructor. |
Source code in src/ltnjax/core.py
Attributes¶
Methods:¶
__call__ ¶
Calls the lambda function with inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| ArrayLike | Array. | () |
Returns:
| Type | Description |
|---|---|
Array |
|
__init__ ¶
__init__(lambda_operator: Callable) -> None
Predicate ¶
Bases: Module
flowchart TD
ltnjax.core.Predicate[Predicate]
click ltnjax.core.Predicate href "" "ltnjax.core.Predicate"
Class representing an LTN predicate.
An LTN predicate is grounded as a mathematical function (either pre-defined or learnable) that maps from some n-ary domain of individuals to a real number in [0,1] (fuzzy), which can be interpreted as a truth value.
In LTNtorch, the inputs of a predicate are automatically broadcasted before the computation of the predicate, if necessary. Moreover, the output is organized in a tensor where each dimension is related to one variable given in input.
Attributes:
| Name | Type | Description |
|---|---|---|
model | A |
Note
modelwill be called with a tensor that has a batch dimension and optionally feature dimensions. The batch dimension is the axis that results from flattening the axes of the free variables. See _flatten_free_dims.
Methods:
| Name | Description |
|---|---|
__call__ | Evaluates the |
__init__ | Constructor. |
Source code in src/ltnjax/core.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
Attributes¶
Methods:¶
__call__ ¶
Evaluates the model of the given inputs and kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| LTNObject | tuple of LTNObject to apply on | () |
| Any | Further arguments to pass to | {} |
Returns:
| Type | Description |
|---|---|
LTNObject |
|
Raises:
| Type | Description |
|---|---|
TypeError | If |
Source code in src/ltnjax/core.py
__init__ ¶
Constructor.
Initializes the LTN predicate in two different ways: 1. if model is not None, it initializes the predicate with the given nnx.Module; 2. if model is None, it uses the func as a function to define the LTN predicate. Note that, in this case, the LTN predicate is not learnable. So, the lambda function has to be used only for simple predicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Module | None | (default=None) A | None |
| Callable | None | (default=None) A lambda_expression. | None |
Raises:
| Type | Description |
|---|---|
ValueError | If either both |
TypeError | If |
Source code in src/ltnjax/core.py
Quantifier ¶
Class representing an LTN quantifier.
Wrapper for Quantifiers. This evaluates a given LTN object wff for all variable combinations for that the condition mask is true. Then, the results will be aggregated with the aggregation operator aggreg_op.
Attributes:
| Name | Type | Description |
|---|---|---|
aggreg_op | Aggregation operator. | |
quantifier | (str = "f" | "e" |
Raises:
| Type | Description |
|---|---|
TypeError | If |
ValueError | If |
Note
It is possible that the variable-combinations are empty or that the condition mask will mask every variable-combination. In both cases, a "forall"-statement will always be true while an "exists"-statement will always be false.
- API Reference
ltnjax
Methods:
| Name | Description |
|---|---|
__call__ | Applies the quantification and outputs the resulting LTN object. |
__init__ | Constructor. |
Source code in src/ltnjax/core.py
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 | |
Attributes¶
Methods:¶
__call__ ¶
__call__(
variables: Variable | list[Variable],
wff: LTNObject,
mask: LTNObject | None = None,
**kwargs: Any,
) -> LTNObject
Applies the quantification and outputs the resulting LTN object.
As a side-effect, this removes the diagonal quantification from the given variables. Refer to undiag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Variable | list[Variable] | Variable or list of variables. | required |
| LTNObject | LTN object. | required |
| LTNObject | None | (default=None) Condition operation. | None |
| Any | Further arguments to pass to | {} |
Returns:
| Type | Description |
|---|---|
LTNObject | The resulting LTN object. |
Raises:
| Type | Description |
|---|---|
TypeError |
Source code in src/ltnjax/core.py
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 | |
__init__ ¶
__init__(aggreg_op: ConnectiveOperator, quantifier: str) -> None
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| ConnectiveOperator | Aggregation operator. | required |
| str | (str = "f" | "e" | required |
Source code in src/ltnjax/core.py
_broadcast_wff_and_mask staticmethod ¶
Broadcasts the free variables from mask to wff.
The variables of mask are put in the first axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| LTNObject | LTN object. | required |
| LTNObject | LTN object. | required |
| bool | (default=False) Boolean that decides whether we perform the operation on | False |
Returns:
| Type | Description |
|---|---|
LTNObject | The LTN object |
Source code in src/ltnjax/core.py
_transpose_free_vars staticmethod ¶
_transpose_free_vars(
expr: LTNObject, new_var_order: list[VarLabel], in_place: bool = False
) -> LTNObject
Transposes free variables.
This changes the order of variables in expr.free_vars and the axes of expr.value will be transposed accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| LTNObject | The LTN object whose variables will be transposed. | required |
| list[VarLabel] | List of variables that defines the new order. | required |
| bool | (default=False) Boolean that decides whether we perform the operation on a new copy or on the same LTN objects. | False |
Returns:
| Type | Description |
|---|---|
LTNObject | The transposed LTN object. |
Source code in src/ltnjax/core.py
Variable ¶
Bases: LTNObject
flowchart TD
ltnjax.core.Variable[Variable]
ltnjax.core.LTNObject[LTNObject]
ltnjax.core.LTNObject --> ltnjax.core.Variable
click ltnjax.core.Variable href "" "ltnjax.core.Variable"
click ltnjax.core.LTNObject href "" "ltnjax.core.LTNObject"
Class representing an LTN variable.
A variable \(x\) that can take only a finite number \(n\) of tensors of any rank, that means with or without feature dimensions.
Without feature dimensions: \(x \in \mathcal{R}^n\).
With feature dimensions \(d_1 \times \dotsc \times d_m\): \(x \in \mathcal{R}^(n \times d_1 \times \dotsc \times d_m)\).
Attributes:
| Name | Type | Description |
|---|---|---|
var_label | The name of the variable. | |
value | The array describes a batch of individuals; The first axis describes the number of individuals and the optional remaining axes are the | |
free_vars | list[VarLabel] | The free variables that are contained in the expression. |
trainable | list[VarLabel] | Flag indicating whether the LTN constant is trainable (embedding) or not. |
Raises:
| Type | Description |
|---|---|
ValueError | If |
Note
- The first dimension \(n\) of an LTN variable is associated with the number of individuals in the variable, while the other \(d\) exes are associated with the features of the individuals;
- If the Variable should contain truth values in
[0., 1.]that are updated during training, ensure that they will stay in that interval. This could be done by using sigmoid or tanh operations on the values. Avoid usingjax.numpy.clip(x, 0., 1.)during training as this will yield to gradient issues.
- API Reference
ltnjax
- API Reference
ltnjax
- API Reference
ltnjax
Methods:
| Name | Description |
|---|---|
__init__ | Constructor. |
__repr__ | Representation function. |
Source code in src/ltnjax/core.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
Attributes¶
Methods:¶
__init__ ¶
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| VarLabel | The name of the variable. | required |
| Any | An object that is convertible to an array. This includes JAX arrays, NumPy arrays, Python scalars, Python collections like lists and tuples, objects with an The array describes a batch of individuals; The first axis describes the number of individuals and the optional remaining axes are the | required |
| bool | Flag indicating whether the LTN constant is trainable (embedding) or not. | False |
Source code in src/ltnjax/core.py
Functions:¶
_as_arrays ¶
Converts LTN objects to arrays.
This function takes a list of LTNObject objects and outputs a list of its values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Sequence[LTNObject] | List of LTNObject objects. | required |
Returns:
| Type | Description |
|---|---|
list[Array] | List of values of the given LTNObject. |
Note
We only need to take sequences as they only must read-only.
Source code in src/ltnjax/core.py
_broadcast_exprs ¶
Broadcasts variables of exprs.
This collects the union of free_vars in exprs and broadcasts it to each LTN object in exprs, i.e. at the end each free variable in exprs is contained in each LTN object in exprs together with its own axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| list[LTNObject] | List of LTNObject objects thats variables will be broadcasted. | required |
| bool | (default=False) Boolean that decides whether we perform the operation on a new copy or on the same LTN objects. | False |
Returns:
| Type | Description |
|---|---|
list[LTNObject] | List of LTN objects but with broadcasted free variables. |
Example
exprs[0] has shape (5, 2) and free_vars = ['x'] and exprs[1] has shape (10, 2) and free_vars = ['y']. After broadcasting, both LTN objects will have shape (5, 10, 2) and free_vars = ['x', 'y'].
import ltn import numpy as np x = ltn.core.LTNObject(np.ones((5,2)), 'x') y = ltn.core.LTNObject(np.ones((10,2)), 'y') res = ltn.core._broadcast_exprs([x, y]) print(res[0]) LTNObject( value=Array(shape=(5, 10, 2), dtype=dtype('float32')), free_vars=['x', 'y'] ) print(res[1]) LTNObject( value=Array(shape=(5, 10, 2), dtype=dtype('float32')), free_vars=['x', 'y'] )
- API Reference
ltnjax
Source code in src/ltnjax/core.py
_flatten_free_dims ¶
Flattens free_dims of exprs.
Flattens the \([0,\infty)\) many free dimensions in exprs into one _flat_ axis. free_dims and the feature_dims may be empty. If free_dims is empty, the _flat_-axis will be of size \(1\). That is, for each LTN object in exprs if expr.value has shape (5,10,2,3) and expr.free_vars=['x','y'], we will get an output of shape (50,2,3) with expr.free_vars = ['_flat_x_y'].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| list[LTNObject] | List of LTNObject. | required |
| bool | (default=False) Boolean that decides whether we perform the operation on a new copy or on the same LTN objects. | False |
Returns:
| Type | Description |
|---|---|
list[LTNObject] | List of the flattened LTN objects. The output shape will be the |
list[LTNObject] |
|
Note
- Do not confuse
free_dimswithfeature_dims. Thefree_dimsare these that are associated withfree_vars.
Source code in src/ltnjax/core.py
diag ¶
Diagonalizes variables.
This diagonalizes a list of given Variable objects, i.e. this prepares the variables for the use of Quantifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Variable | Tuple of Variable objects to diagonalize. | () |
Returns:
| Type | Description |
|---|---|
list[Variable] | Tuple of Variable objects, but in diagonalized |
list[Variable] | form. |
Raises:
| Type | Description |
|---|---|
TypeError | If |
ValueError | If a variable in |
Source code in src/ltnjax/core.py
undiag ¶
Resets the LTN broadcasting for the given LTN variables.
In other words, it removes the diagonal quantification setting from the given variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Variable | () |
Returns:
| Type | Description |
|---|---|
list[Variable] | List of the same LTN Variable objects given in |
list[Variable] | input, with the |
Raises:
| Type | Description |
|---|---|
TypeError | If |
- API Reference
ltnjax