Gates
Gate activation functions for feature and rule selection in gated TSK models.
Gate functions map unbounded real-valued gate parameters to normalised
activation values in [0, 1] (or near it). They are used by
highfis.layers.DGALETSKRuleLayer, highfis.layers.DGTSKRuleLayer,
and the gated consequent layers to soft-select relevant features and rules
during training.
Each gate is an ~torch.nn.Module subclass of BaseGate.
The module-level singletons gate1 ... gate4, gate_m are
provided for backward compatibility.
Built-in gate classes
SigmoidGate: sigmoid, \(M(\lambda) = \sigma(\lambda)\).ExpGate: squared-exponential, \(M(\lambda) = 1 - e^{-k\lambda^2}\) (k=1standard,k=10DG-ALETSK enhanced).InvExpGate: inverted-exponential, \(M(\lambda) = e^{-\lambda^2}\) (inverted: open at 0, closes as \(|\lambda| \to \infty\)).SignedExpGate: signed exponential, \(M(\lambda) = \lambda\sqrt{e^{1 - \lambda^2}}\) (odd — consequent-only).MGate: M-gate, \(M(\lambda) = \lambda^2 e^{1 - \lambda^2}\).
Registry and resolver
GATE_FNS: mapping from string name toBaseGatesingleton.resolve_gate_fn: resolve a name, callable, orNoneto a gate;Nonedefaults toExpGatewithk=10.
References
Xue, G., Wang, J., Yuan, B., and Dai, C. (2023). DG-ALETSK: A High-Dimensional Fuzzy Approach With Simultaneous Feature Selection and Rule Extraction. IEEE Transactions on Fuzzy Systems, 31(11), 3866-3880. https://doi.org/10.1109/TFUZZ.2023.3270445
Xue, G., Wang, J., Zhang, B., Yuan, B., and Dai, C. (2023). Double groups of gates based Takagi-Sugeno-Kang (DG-TSK) fuzzy system for simultaneous feature selection and rule extraction. Fuzzy Sets and Systems, 469, 108627. https://doi.org/10.1016/j.fss.2023.108627
BaseGate
Bases: nn.Module
Abstract base for gate activation modules.
Subclasses must implement :meth:forward and may override
:meth:init_params_ to provide a paper-recommended initialisation
strategy for their gate parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
is_nonneg |
bool
|
|
forward
Compute gate activation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Tensor
|
Input gate parameter tensor. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Gate activation values. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Subclasses must override this method. |
Source code in highfis/gates.py
init_params_
Initialise param in-place using the paper-recommended strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
nn.Parameter
|
Gate parameter tensor to initialise. |
required |
ExpGate
Bases: BaseGate
Squared-exponential gate activation.
DG-TSK eq (17) / DG-ALETSK eq (16). The enhanced gate used in
DG-ALETSK is ExpGate(k=10). Initialised near zero
(Uniform(0.001, 0.01)), giving M ≈ 0 (nearly closed)
at the start of training.
Mathematical definition
Attributes:
| Name | Type | Description |
|---|---|---|
k |
float
|
Scale parameter. |
Initialise ExpGate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
float
|
Scale parameter (default |
1.0
|
Source code in highfis/gates.py
forward
Compute squared-exponential gate activation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Tensor
|
Input gate parameter tensor. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Gate activation values in [0, 1). |
Source code in highfis/gates.py
init_params_
Initialise param near zero so gates start nearly closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
nn.Parameter
|
Gate parameter tensor to initialise. |
required |
InvExpGate
Bases: BaseGate
Inverted-exponential gate activation.
DG-TSK eq (18) / DG-ALETSK eq (17). Initialised at large values (Normal(3.0, 0.2)), giving M = e⁻⁹ ≈ 1e-4 (nearly closed) at the start of training.
Mathematical definition
Warning
This gate has inverted semantics — M=1 at λ=0 (fully open) and M → 0 as |λ| → ∞ (closed). Parameters must be initialised at large values so gates start closed.
forward
Compute inverted-exponential gate activation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Tensor
|
Input gate parameter tensor. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Gate activation values in (0, 1]. |
init_params_
Initialise param near 3.0 so gates start nearly closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
nn.Parameter
|
Gate parameter tensor to initialise. |
required |
MGate
Bases: BaseGate
M-gate activation.
Introduced in Xue et al., Fuzzy Sets and Systems, 2023, eq (20).
It is an even function with range [0, 1] and two maxima at λ = ±1,
forming an M-shape. Its derivative near zero is larger than those of
SigmoidGate, ExpGate, and InvExpGate,
which speeds up early learning. Initialised to small values
(Uniform(0.01, 0.1)), giving M ∈ [0.0003, 0.027] (nearly closed;
even function so sign does not matter).
Mathematical definition
forward
Compute M-gate activation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Tensor
|
Input gate parameter tensor. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Gate activation values in [0, 1]. |
init_params_
Initialise param to small values so gates start nearly closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
nn.Parameter
|
Gate parameter tensor to initialise. |
required |
SigmoidGate
Bases: BaseGate
Sigmoid gate activation.
DG-TSK eq (16) / DG-ALETSK eq (15). Initialised near -5 (Uniform(-5.5, -4.5)), giving M ≈ 0.007 (nearly closed) at the start of training.
Mathematical definition
forward
Compute sigmoid gate activation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Tensor
|
Input gate parameter tensor. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Gate activation values in (0, 1). |
init_params_
Initialise param near -5 so gates start nearly closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
nn.Parameter
|
Gate parameter tensor to initialise. |
required |
SignedExpGate
Bases: BaseGate
Signed exponential gate activation.
DG-TSK eq (19) / DG-ALETSK eq (18). Initialised to small positive values (Uniform(0.005, 0.015)) to avoid negating rule outputs at the start of training.
Mathematical definition
Warning
This is an odd function with range (-1, 1] that can return negative values, making it unsuitable for antecedent feature selection (\(\mu^{M(\lambda)} > 1\) when \(M(\lambda) < 0\), violating fuzzy set theory). Use only in consequent layers where ±1 both represent an open gate.
forward
Compute signed exponential gate activation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Tensor
|
Input gate parameter tensor. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Gate activation values in (-1, 1]. |
Source code in highfis/gates.py
init_params_
Initialise param to small positive values (gates nearly closed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
nn.Parameter
|
Gate parameter tensor to initialise. |
required |
resolve_gate_fn
Resolve a gate name or callable to a gate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate_fn
|
str | Callable[[Tensor], Tensor] | None
|
A string key
from |
required |
Returns:
| Type | Description |
|---|---|
BaseGate | Callable[[Tensor], Tensor]
|
BaseGate | Callable[[Tensor], Tensor]: A |
BaseGate | Callable[[Tensor], Tensor]
|
singleton for known string keys, an |
BaseGate | Callable[[Tensor], Tensor]
|
for |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |