ytm.simple.RegressionTM#
- class ytm.simple.RegressionTM(n_clauses: int, T: float, s: float, dim: int | tuple[int, ...], y_range: tuple[float, float], **opt)#
Bases:
BaseTMTM for regression: one real-valued target per sample (Regression TM).
Targets in
y_rangeare scaled to class sum targets in[0, T], and predictions are scaled back. Defaults differ fromBaseTM:negative_clauses=False.- Parameters:
- n_clausesint
Number of clauses.
- Tfloat
Vote threshold. Class sums are clipped to
[0, T].- sfloat
Specificity, at least 1.0.
- dimint or tuple of int
Input shape:
D,(H, W)or(H, W, C). Inputs are binary.- y_rangetuple of (float, float)
Range
(lo, hi)of the targets.- **opt
Other options of
BaseTM.
- 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, clip_class_sums: bool = True)#
Predict the target of each sample: the class sum scaled from
[0, T]back toy_range.- Parameters:
- Xarray-like of bool, shape
(N, *dim)or(N, prod(dim)) Binary inputs.
- clip_class_sumsbool, default=True
Clip class sums to
[0, T]before scaling, so predictions stay withiny_range.
- Xarray-like of bool, shape
- Returns:
- predsndarray of shape (N,)
Predicted targets.
- 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.