ytm._core.info.ClauseInfo#

class ytm._core.info.ClauseInfo#

Bases: object

Clauses returned by BaseTM.get_clauses().

Attributes:
feature_boundsndarray of shape (n_clause_banks, n_clauses, n_raw_patch_feats * 2)

Closed [lower, upper] feature inclusion bounds per clause.

position_boundsndarray of shape (n_clause_banks, n_clauses, 4) or None

Closed [min_row, max_row, min_col, max_col] patch position bounds per clause. None when the input has a single patch.

has_contrandarray of shape (n_clause_banks, n_clauses), dtype int8

1 when the clause is unsatisfiable (contains a contradiction).

clause_lenndarray of shape (n_clause_banks, n_clauses), dtype int

Number of included literals per clause. 0 means the clause is empty and thus a tautology.

clause_weightsndarray of shape (n_classes, n_clauses)

Weight of each clause per class. Non-coalesced: row j holds class j’s own clauses. Coalesced: every row covers the same shared clauses.

configBaseTMConfig

Config of the model the clauses come from.

clause_to_str(class_id: int, clause_id: int, feat_names: list[str] | None = None, include_weight: bool = True, ascii: bool = False) → str#

One clause as text.

Parameters:
class_idint

Class the clause belongs to. Ignored for coalesced model.

clause_idint

Clause ID.

feat_nameslist of str, optional

One name per raw patch feature. Defaults to X0, X1, ....

include_weightbool, default=True

Prefix the returned string with W[...]:, the clause weight/s.

asciibool, default=False

Use ascii & ~ <= >= instead of unicode ∧ ¬ ≤ ≥.

Returns:
str

E.g. "W[+2]: ¬x0 ∧ x1", "W[-1, +2, +3]: (x2 ≥ 6)", "W[+1]: (empty)".

Examples

Binary features, not coalesced, one weight per clause:

>>> info.clause_to_str(1, 1)
'W[-20]: X0 ∧ X1'
>>> info.clause_to_str(1, 0, feat_names=["a", "b", "c"], ascii=True)
'W[-6]: ~a & ~b'
>>> info.clause_to_str(1, 0, include_weight=False)
'¬X0 ∧ ¬X1'
>>> info.clause_to_str(1, 3)
'W[+10]: (empty)'

Thermometer features in [0, 7], coalesced, so one weight per class:

>>> info.clause_to_str(0, 0)
'W[+11, -11]: (X0 ≤ 4)'
>>> info.clause_to_str(0, 2)
'W[-10, +10]: (5 ≤ X0 ≤ 6)'
>>> info.clause_to_str(0, 3)
'W[-10, +10]: (X0 = 7)'
print(feat_names: list[str] | None = None, sort: str = 'w0', top_k: int | None = None, ascii: bool = False, force_no_rich: bool = False) → None#

Print clause banks as tables.

Used rich if available, or fallback to simple text output.

Parameters:
feat_nameslist of str, optional

Feature names. Defaults to X0, X1, ....

sortstr, default=”w0”

Comma-separated sort keys, applied in order for positive and negative polarities. Possible keys:

  • wK: class K |weight|, largest first.

  • len: shortest first.

  • !: contradictions last.

A - prefix reverses a key. For non-coalesced K in wK will be ignored.

top_kint, optional

Show at most this many rows per section.

asciibool, default=False

Use ascii & ~ <= >= ! instead of unicode ∧ ¬ ≤ ≥ ⊥.

force_no_richbool, default=False

Plain text table even when rich is installed.

Examples

Default, largest weight first: >>> info.print()

Shortest clauses first, equal lengths by weight: >>> info.print(sort=”len,w0”)

Contradictions last, then longest first: >>> info.print(sort=”!,-len”)

Coalesced: split into positive and negative sections by class 2’s weight, shortest first: >>> info.print(sort=”len,w2”)

Only the 10 largest weights of each section: >>> info.print(top_k=10)