Operator-Set Aggregators¶
- class bacon.aggregators.math.operator_set.ArithmeticOperatorSet(op_names=None, use_gumbel: bool = True, tau: float = 1.0, eps: float = 1e-06, auto_harden_threshold: float | None = None, output_clamp: float = 10000.0)¶
Arithmetic operator set aggregator with proper weighted operations.
Default operators: [“add”, “sub”, “mul”, “div”]
Operations use proper weights (no normalization to [0,1]):
add: weighted sum \(\sum_i w_i x_i\)
sub: ordered weighted subtraction \(w_0x_0 - w_1x_1 - \cdots\)
mul: weighted product \(\prod_i (w_i x_i)\)
div: weighted division \((w_0x_0) / (w_1x_1 + \varepsilon)\)
- get_default_op_names() list¶
Return the default list of operator names for this aggregator type.
- class bacon.aggregators.math.operator_set.BoolOperatorSet(op_names=None, use_gumbel: bool = True, tau: float = 1.0, eps: float = 1e-06, auto_harden_threshold: float | None = None)¶
Boolean/logical operator set aggregator.
Default operators: [“and”, “or”]
- Operations:
and: minimum of all values (strong AND)
or: maximum of all values (strong OR)
- get_default_op_names() list¶
Return the default list of operator names for this aggregator type.
- class bacon.aggregators.math.operator_set.BoolOperatorSetWithIdentity(op_names=None, use_gumbel: bool = True, tau: float = 1.0, eps: float = 1e-06, auto_harden_threshold: float | None = None)¶
Boolean operator set with explicit passthrough operator.
Default operators: [“and”, “or”, “identity”]
- get_default_op_names() list¶
Return the default list of operator names for this aggregator type.
- class bacon.aggregators.math.operator_set.OperatorSetAggregator(op_names=None, use_gumbel: bool = True, tau: float = 1.0, eps: float = 1e-06, auto_harden_threshold: float | None = None)¶
Base class for per-node operator selection aggregators.
For each internal node in BACON, there is a separate learnable logits vector over operators. During forward pass, softmax/Gumbel-softmax is applied to select operators differentiably.
Subclasses must implement these methods:
get_default_op_names(): return default operator names for this type._apply_op(name, values, a, weights): apply a named operator.
BACON integration points:
binaryTreeLogicNet.__init__callsattach_to_tree(self.num_layers)when available.
binaryTreeLogicNet.forwardcallsstart_forward()when available.- Tree building repeatedly calls
aggregate(values, a, weights), where valuesis a sequence of tensors andweightsis a sequence of per-input weights.
- Tree building repeatedly calls
- aggregate(values, a, weights)¶
Standard BACON aggregator signature. Dispatches to float or tensor implementation based on input type.
- Parameters:
values – Sequence of input values (floats or tensors)
a – Andness parameter (used for logic ops)
weights – Sequence of weights
- aggregate_float(values: Sequence[float], a: float, weights: Sequence[float]) float¶
Float path: convert to tensors and use tensor implementation.
- aggregate_tensor(values: Sequence[Tensor], a: Tensor, weights: Sequence[Tensor] | Tensor) Tensor¶
Tensor path: main aggregation logic.
- attach_to_tree(num_layers: int, initial_op_bias: str = None)¶
Called once BACON knows how many internal nodes (layers) exist. Creates a set of operator logits, one per internal node.
If already attached with correct num_layers, does nothing (preserves existing logits).
- Parameters:
num_layers – Number of internal nodes in the tree
initial_op_bias – If set, initialize logits to favor this operator (e.g., “mul”)
- abstractmethod get_default_op_names() list¶
Return the default list of operator names for this aggregator type.
- harden_operators()¶
Force deterministic argmax operator selection for every node.
- soften_operators()¶
Return to soft/stochastic operator selection behavior.
- start_forward()¶
Called at the start of each forward() of the tree to reset node pointer.