mononet.keras._kernels#

Private Keras 3 kernels for monotonic primitives (keras.ops only).

Module Contents#

Functions#

activation

Apply the base activation by name.

concave_reflection

Concave reflection defined as -activation(-h).

gate

Resolve and apply a gate token to a raw (unconstrained) parameter.

monotonic_dense

Keras monotonic dense kernel (backend-agnostic via keras.ops).

monotonic_residual

Keras dual-gated monotone residual kernel.

API#

mononet.keras._kernels.activation(name: str, h: Any) Any#

Apply the base activation by name.

Parameters:
  • name – One of relu, elu, selu, softplus.

  • h – Input tensor (any keras-compatible array).

Returns:

Activated tensor with the same shape as h.

Raises:

ValueError – If name is not a supported activation.

mononet.keras._kernels.concave_reflection(name: str, h: Any) Any#

Concave reflection defined as -activation(-h).

Parameters:
  • name – Activation name passed to :func:activation.

  • h – Input tensor.

Returns:

Negated activation of negated input, same shape as h.

mononet.keras._kernels.gate(token: str, raw: Any) Any#

Resolve and apply a gate token to a raw (unconstrained) parameter.

Parameters:
  • token – One of shifted_elu or scaled_elu.

  • raw – Raw (unconstrained) gate parameter tensor.

Returns:

Strictly-positive gate value, same shape as raw.

Raises:

ValueError – If token is not a supported gate token.

mononet.keras._kernels.monotonic_dense(x: Any, weights: Any, bias: Any, mode: str, activation_name: str, convex_fraction: float = 0.5) Any#

Keras monotonic dense kernel (backend-agnostic via keras.ops).

Parameters:
  • x – Input tensor of shape (batch, in_features).

  • weights – Weight matrix of shape (in_features, units).

  • bias – Bias vector of shape (units,).

  • mode – Either switch or absolute.

  • activation_name – Base activation name (relu, elu, selu, softplus).

  • convex_fraction – Fraction of output units that use the convex activation; remainder use the concave reflection. Only used for absolute mode.

Returns:

Output tensor of shape (batch, units).

Raises:

ValueError – If mode is not switch or absolute.

mononet.keras._kernels.monotonic_residual(x: Any, weights: Any, bias: Any, alpha: Any, beta: Any, *, mode: str, activation_name: str, convex_fraction: float = 0.5, alpha_gate: str = 'shifted_elu', beta_gate: str = 'scaled_elu', skip_weight: Any | None = None) Any#

Keras dual-gated monotone residual kernel.

Parameters:
  • x – Input tensor of shape (batch, in_features).

  • weights – Weight matrix of shape (in_features, units).

  • bias – Bias vector of shape (units,).

  • alpha – Unconstrained skip-gate parameter (scalar or broadcastable).

  • beta – Unconstrained dense-gate parameter (scalar or broadcastable).

  • mode

    Either switch or absolute; forwarded to

    func:

    monotonic_dense.

  • activation_name

    Base activation name; forwarded to

    func:

    monotonic_dense.

  • convex_fraction – Convex fraction for absolute mode.

  • alpha_gate – Gate token for the skip path (default shifted_elu).

  • beta_gate – Gate token for the dense path (default scaled_elu).

  • skip_weight – Optional projection log-weight matrix of shape (in_features, units); when provided the skip path is x @ exp(skip_weight).

Returns:

Output tensor of shape (batch, units).