HMath.DeepLearning.Core¶
Module index · Numerical conventions
Description
Checked Double activations, losses, and real-coordinate reverse rules. Probabilities must be in [0,1]; impossible events return a domain failure instead of silently clipping probabilities. Logit losses avoid exp overflow. Nondifferentiable hinges use zero at equality; MAE uses signum(0)=0.
On this page¶
| API | Purpose |
|---|---|
| Activation | Scalar activation selector. |
| Sigmoid | Declaration and type contract below. |
| Tanh | Declaration and type contract below. |
| ReLU | Declaration and type contract below. |
| LeakyReLU | Declaration and type contract below. |
| PReLU | Declaration and type contract below. |
| ELU | Declaration and type contract below. |
| SELU | Declaration and type contract below. |
| GELU | Declaration and type contract below. |
| SiLU | Declaration and type contract below. |
| Mish | Declaration and type contract below. |
| Softplus | Declaration and type contract below. |
| Softsign | Declaration and type contract below. |
| HardSigmoid | Declaration and type contract below. |
| HardSwish | Declaration and type contract below. |
| activation | Given Activation selector then finite scalar, evaluate the selected activation. |
| activationDerivative | Evaluate the analytic first derivative with documented kink conventions and stable saturated sigmoid/tanh behavior. |
| activationExpr | Embed the checked activation and analytic custom reverse rule in an automatic differentiation graph. |
| softmax | Exponentiate stable log-softmax values; the output sums to one within floating error. |
| logSoftmax | Normalize a nonempty finite vector in log space after subtracting its maximum. |
| sparsemax | Project a finite vector onto the probability simplex using sorted active-support thresholds. |
| gatedLinearUnit | Multiply values by sigmoid(gates), requiring equal vector lengths. |
| softmaxExpr | First-order softmax reverse rule, including cross-coordinate coupling. |
| logSoftmaxExpr | First-order stable log-softmax rule; gradient rows sum to zero. |
| sparsemaxExpr | Sparsemax's piecewise-linear Jacobian. |
| ctcLossExpr | CTC graph operation on rectangular time-major log probabilities. |
| Reduction | Loss aggregation: Sum adds elementwise losses and Mean divides by their count; vector-level loss exceptions are documented by loss. |
| Sum | Declaration and type contract below. |
| Mean | Declaration and type contract below. |
| Loss | Checked loss selector,including squared/absolute error,cross entropy,KL,hinge,cosine,and parameterized Hubersmooth losses. |
| MeanSquaredError | Declaration and type contract below. |
| MeanAbsoluteError | Declaration and type contract below. |
| Huber | Declaration and type contract below. |
| SmoothL1 | Declaration and type contract below. |
| BinaryCrossEntropy | Declaration and type contract below. |
| CategoricalCrossEntropy | Declaration and type contract below. |
| NegativeLogLikelihood | Declaration and type contract below. |
| KLDivergence | Declaration and type contract below. |
| CosineLoss | Declaration and type contract below. |
| Hinge | Declaration and type contract below. |
| loss | Evaluate the selected checked loss. |
| lossGradient | Analytic derivatives with respect to predictions under the exact loss/reduction convention. |
| lossExpr | Use a constant target with symbolic prediction inputs and the matching analytic reverse rule. |
| binaryCrossEntropyLogits | Stable binary cross entropy from logits and [0,1] targets, including extreme finite logits. |
| categoricalCrossEntropyLogits | Cross entropy from one class-logit vector; nonnegative targets must sum to one. |
| regularization | Return l1sum(abs(w)) + l2/2sum(w*w); both coefficients must be finite and nonnegative. |
| contrastiveLoss | Pairwise Euclidean contrastive loss; similar=True penalizes squared distance and dissimilar pairs use the positive margin. |
| tripletLoss | Return max(0,positiveDistance-negativeDistance+margin) for equal nonempty vector dimensions. |
| focalLoss | Mean binary focal loss with alpha in [0,1], gamma>=0, and exact zero/one targets. |
| diceLoss | Soft segmentation overlap losses on [0,1] values; positive smoothing defines the empty-mask case. |
| iouLoss | Soft segmentation overlap losses on [0,1] values; positive smoothing defines the empty-mask case. |
| ctcLoss | Single sequence, time-major log-probabilities [time,class]. |
| ctcLossGradient | Given blank class index, target labels, then rectangular time-by-class log probabilities, return CTC negative log likelihood and gradient rows. |
Documentation
Activation
data Activation Source #
Scalar activation selector. LeakyReLU/PReLU carry negative-side slope and ELU carries positive alpha; other constructors select the named standard activation.
Constructors
| Sigmoid | |
| Tanh | |
| ReLU | |
| LeakyReLU Double | |
| PReLU Double | |
| ELU Double | |
| SELU | |
| GELU | |
| SiLU | |
| Mish | |
| Softplus | |
| Softsign | |
| HardSigmoid | |
| HardSwish |
Instances
| Show Activation Source # | |
Defined in HMath.DeepLearning.Core Methods showsPrec :: Int -> Activation -> ShowS # show :: Activation -> String # showList :: [Activation] -> ShowS # | |
| Eq Activation Source # | |
Defined in HMath.DeepLearning.Core | |
activation
activation :: Activation -> Double -> Either MathError Double Source #
Given Activation selector then finite scalar, evaluate the selected activation. Parameterized LeakyReLU/PReLU slopes must be finite and ELU alpha positive. Invalid input/parameters or non-finite output returns Left MathError.
activationDerivative
activationDerivative :: Activation -> Double -> Either MathError Double Source #
Evaluate the analytic first derivative with documented kink conventions and stable saturated sigmoid/tanh behavior.
activationExpr
activationExpr :: Activation -> Expr -> Expr Source #
Embed the checked activation and analytic custom reverse rule in an automatic differentiation graph.
softmax
softmax :: [Double] -> Either MathError [Double] Source #
Exponentiate stable log-softmax values; the output sums to one within floating error.
logSoftmax
logSoftmax :: [Double] -> Either MathError [Double] Source #
Normalize a nonempty finite vector in log space after subtracting its maximum.
sparsemax
sparsemax :: [Double] -> Either MathError [Double] Source #
Project a finite vector onto the probability simplex using sorted active-support thresholds.
gatedLinearUnit
gatedLinearUnit :: [Double] -> [Double] -> Either MathError [Double] Source #
Multiply values by sigmoid(gates), requiring equal vector lengths.
softmaxExpr
softmaxExpr :: [Expr] -> [Expr] Source #
First-order softmax reverse rule, including cross-coordinate coupling.
logSoftmaxExpr
logSoftmaxExpr :: [Expr] -> [Expr] Source #
First-order stable log-softmax rule; gradient rows sum to zero.
sparsemaxExpr
sparsemaxExpr :: [Expr] -> [Expr] Source #
Sparsemax's piecewise-linear Jacobian. At a support boundary its inactive coordinate convention chooses zero, giving a defined subgradient.
ctcLossExpr
ctcLossExpr :: Int -> [Int] -> [[Expr]] -> Either MathError Expr Source #
CTC graph operation on rectangular time-major log probabilities. Its custom backward uses forward/backward occupancies, rather than numerical differences.
Reduction
Loss aggregation: Sum adds elementwise losses and Mean divides by their count; vector-level loss exceptions are documented by loss.
Loss
Checked loss selector,including squared/absolute error,cross entropy,KL,hinge,cosine,and parameterized Hubersmooth losses. Targetprediction domain rules belong to loss.
loss
loss :: Loss -> Reduction -> [Double] -> [Double] -> Either MathError Double Source #
Evaluate the selected checked loss. Mean divides elementwise losses by count; CosineLoss is one vector loss.
lossGradient
lossGradient :: Loss -> Reduction -> [Double] -> [Double] -> Either MathError [Double] Source #
Analytic derivatives with respect to predictions under the exact loss/reduction convention.
lossExpr
lossExpr :: Loss -> Reduction -> [Double] -> [Expr] -> Expr Source #
Use a constant target with symbolic prediction inputs and the matching analytic reverse rule.
binaryCrossEntropyLogits
binaryCrossEntropyLogits :: Reduction -> [Double] -> [Double] -> Either MathError Double Source #
Stable binary cross entropy from logits and [0,1] targets, including extreme finite logits.
categoricalCrossEntropyLogits
categoricalCrossEntropyLogits :: [Double] -> [Double] -> Either MathError Double Source #
Cross entropy from one class-logit vector; nonnegative targets must sum to one.
regularization
regularization :: Double -> Double -> [Double] -> Either MathError Double Source #
Return l1*sum(abs(w)) + l2/2*sum(w*w); both coefficients must be finite and nonnegative.
contrastiveLoss
contrastiveLoss :: Double -> Bool -> [Double] -> [Double] -> Either MathError Double Source #
Pairwise Euclidean contrastive loss; similar=True penalizes squared distance and dissimilar pairs use the positive margin.
tripletLoss
tripletLoss :: Double -> [Double] -> [Double] -> [Double] -> Either MathError Double Source #
Return max(0,positiveDistance-negativeDistance+margin) for equal nonempty vector dimensions.
focalLoss
focalLoss :: Double -> Double -> [Double] -> [Double] -> Either MathError Double Source #
Mean binary focal loss with alpha in [0,1], gamma>=0, and exact zero/one targets.
diceLoss
diceLoss :: Double -> [Double] -> [Double] -> Either MathError Double Source #
Soft segmentation overlap losses on [0,1] values; positive smoothing defines the empty-mask case.
iouLoss
iouLoss :: Double -> [Double] -> [Double] -> Either MathError Double Source #
Soft segmentation overlap losses on [0,1] values; positive smoothing defines the empty-mask case.
ctcLoss
ctcLoss :: Int -> [Int] -> [[Double]] -> Either MathError Double Source #
Single sequence, time-major log-probabilities [time,class]. Blank index is explicit; labels exclude blank. The forward/backward dynamic program sums alignments in log space, including adjacent repeated-label restrictions. Gradients are with respect to independent log probabilities, before a log-softmax chain rule. Impossible alignments return DomainError.
ctcLossGradient
ctcLossGradient :: Int -> [Int] -> [[Double]] -> Either MathError (Double, [[Double]]) Source #
Given blank class index, target labels, then rectangular time-by-class log probabilities, return CTC negative log likelihood and gradient rows. Validate class indices, finite/log-probability constraints and alignment feasibility. Empty time permits only empty labels; invalid/impossible inputs return Left MathError.