LinMeasurementLayerB¶
Role: Trainable Keras layer mapping gun logits to measurement logits with matching width via a two-layer MLP.
Location: Q_Sea_Battle.lin_measurement_layer_b.LinMeasurementLayerB
Constructor¶
| Parameter | Type | Description |
|---|---|---|
| hidden_units | int, constraint: >= 1, shape: scalar | Width of the hidden dense layer. |
| name | Optional[str], constraint: any, shape: scalar | Optional Keras layer name. |
| dtype | Optional[tf.dtypes.DType], constraint: any, shape: scalar | Optional Keras dtype for layer variables and computation. |
| **kwargs | Any, constraint: forwarded to tf.keras.layers.Layer, shape: N/A |
Additional keyword arguments forwarded to Layer. |
Preconditions
hidden_unitsis anintwith constraint:hidden_units >= 1, shape: scalar.
Postconditions
self.hidden_unitsis set toint(hidden_units).self._dense_hiddenisOptional[tf.keras.layers.Dense], initialized toNoneuntilbuild(...)is called.self._dense_outisOptional[tf.keras.layers.Dense], initialized toNoneuntilbuild(...)is called.
Errors
- Raises
ValueErrorifhidden_units < 1.
Example
import tensorflow as tf
from Q_Sea_Battle.lin_measurement_layer_b import LinMeasurementLayerB
layer = LinMeasurementLayerB(hidden_units=64)
x = tf.random.normal([8, 16]) # (B, n2)
y = layer(x) # (B, n2)
Public Methods¶
build¶
- Signature:
build(self, input_shape: Any) -> None
Parameter(s)
input_shape: Any, constraint: convertible totf.TensorShapeand must have statically known last dimension, shape: N/A.
Return value
None, constraint: N/A, shape: scalar.
Behavior
- Creates two sub-layers after inferring
n2frominput_shape[-1]:Dense(hidden_units, relu)followed byDense(n2, linear).
Errors
- Raises
ValueErrorif the final dimension ofinput_shapeis unknown (None).
call¶
- Signature:
call(self, gun_batch: tf.Tensor, training: bool = False, **kwargs: Any) -> tf.Tensor
Parameter(s)
gun_batch: tf.Tensor, dtype: any convertible to layer dtype (defaults tofloat32ifself.dtypeisNone), shape (B, n2); constraint: must be rank-2 when rank is statically known.training: bool, constraint: any, shape: scalar; passed through to sub-layer calls.**kwargs: Any, constraint: unused (present for Keras API compatibility), shape: N/A.
Return value
- tf.Tensor, dtype: matches internal computation dtype (
self.dtypeorfloat32), shape (B, n2); constraint: output width equalsn2inferred at build time.
Errors
- Raises
ValueErrorifgun_batchhas a statically known rank not equal to 2. - Raises
RuntimeErrorif the layer has not been built correctly (i.e., sub-layers are not initialized).
get_config¶
- Signature:
get_config(self) -> Dict[str, Any]
Parameter(s)
- None.
Return value
- Dict[str, Any], constraint: Keras-serializable configuration, shape: N/A; includes key
"hidden_units"with value typeint, shape: scalar.
Data & State¶
hidden_units: int, constraint: >= 1, shape: scalar; number of units in the hidden dense layer._dense_hidden: Optional[tf.keras.layers.Dense], constraint:Nonebeforebuild(...), otherwise aDensewithunits=hidden_unitsandactivation="relu", shape: N/A._dense_out: Optional[tf.keras.layers.Dense], constraint:Nonebeforebuild(...), otherwise aDensewithunits=n2andactivation=None, shape: N/A.n2: int, constraint:n2 = int(input_shape[-1])and must be statically known, shape: scalar; inferred at build time and used as output width.
Planned (design-spec)¶
- Not specified.
Deviations¶
- No design notes provided; no deviations identified.
Notes for Contributors¶
- Rank validation in
call(...)only triggers when the rank is statically known (x.shape.rank is not None); dynamic rank mismatches may not raise at this check. - Sub-layers are created in
build(...); callingcall(...)before the layer is built raisesRuntimeError.
Related¶
- TensorFlow:
tf.keras.layers.Layer - TensorFlow:
tf.keras.layers.Dense
Changelog¶
- Not specified.