Dropout
classin packageklyn.math.nn.layers
public class Dropout<T extends AbstractFloat = Float> extends Layer<T>
Dropout

Random element-wise dropout during training, identity during inference. Kept values are multiplied by 1/(1-rate). Each training call advances a layer-local seed; equal seeds reproduce the same sequence of masks. A layer is not safe for concurrent training. Saved masks belong to individual passes, so a second forward call does not overwrite the first backward context.

Example

model = Sequential<Float>([Dense<Float>(64), Dropout<Float>(0.25), Dense<Float>(10)])

Properties
Modifier and Type Member Description
public override readonly property displayName
displayName as String
Summary label.
public override readonly property parameterCount
parameterCount as ULong
No trainable parameters.
public readonly property randomState
randomState as Long
Current random state; restoring it reproduces the next mask.
public readonly property rate
rate as Double
Drop probability in [0, 1).
Constructors
Modifier and Type Member Description
public Dropout
Dropout(rate as Double, seed as Long = 1l)
Configures independent, reproducible dropout without touching global randomness.
Methods
Modifier and Type Member Description
public override backwardTraining
backwardTraining(context as LayerPass<T>, upstream as NDArray<T>) as LayerGradients<T>
Reuses exactly the keep flags of the corresponding forward pass.
public override buildShape
buildShape(inputShape as IList<Long>) as IList<Long>
Preserves any positive sample shape.
public override differentiate
differentiate(inputs as NDArray<T>, upstream as NDArray<T>) as LayerGradients<T>
Differentiates inference, where dropout is the identity.
public override forward
forward(inputs as NDArray<T>) as NDArray<T>
Returns inputs unchanged during inference, with no allocation or random draw.
public override forwardTraining
forwardTraining(inputs as NDArray<T>) as LayerPass<T>
Samples a fresh mask and retains it only in the returned context.
public override parameter
parameter(index as Long) as NDArray<T>
Rejects parameter access.