ytm.simple.BinaryTM#
- class ytm.simple.BinaryTM(n_clauses: int, T: float | tuple[float, float], s: float, dim: int | tuple[int, ...], **opt)#
Bases:
BaseTMTM for binary classification: one output, each sample is 0 or 1.
Clauses keep their polarity (
allow_polarity_change=False), as in the original TM where half the clauses vote for and half against the output. SeeBaseTMfor the parameters.- calc_class_sums(clause_outputs: ndarray, clip: bool) ndarray#
Weighted vote of the active clauses per class.
clause_outputshas shape (N, n_banks, n_clauses).
- clause_outputs(X: ndarray) ndarray#
Clause outputs, the OR over patches. Returns shape (N, n_banks, n_clauses), bool.
- feedback(class_id: int, X: ndarray, co: ndarray, dropped: ndarray, target: int, prob: float) None#
Give feedback for one class.
- Parameters:
- class_idint
Class to give feedback for.
- Xndarray of shape (n_clauses, n_literals), bool
Literals of the patch each clause is contrasted against.
- condarray of shape (n_clauses,), bool
Clause outputs.
- droppedndarray of shape (n_clauses,), bool
Clauses dropped for this epoch.
- targetint
+1 to push the class sum up to
T_max, -1 to push it down toT_min.- probfloat
Probability of selecting each clause for feedback.
- fit(X: ndarray, Y: ndarray, shuffle: bool = True, clause_drop_p: float = 0.0) None#
Train for one epoch.
- Parameters:
- Xarray-like of bool, shape
(N, *dim)or(N, prod(dim)) Binary inputs.
- Yarray-like
Targets, see the subclass.
- shufflebool, default=True
Visit the samples in a random order.
- clause_drop_pfloat, default=0.0
Probability of dropping each clause for this epoch (Drop Clause). Dropped clauses output 0 and get no feedback.
- Xarray-like of bool, shape
- predict(X: ndarray)#
Predict each sample: 1 where the class sum is above
decision_threshold, else 0.- Returns:
- predsndarray of shape (N,), uint32
Predicted output, 0 or 1.
- class_sumsndarray of shape (N, 1)
Weighted vote sum.
- t1a(bank: int, clause_filter: ndarray, X: ndarray) None#
Type Ia feedback: reinforce include for true literals, exclude for false literals.