UNPKG

scalar-autograd

Version:

Scalar-based reverse-mode automatic differentiation in TypeScript.

52 lines (51 loc) 2.31 kB
import { Value } from "./Value"; export declare class Losses { /** * Computes mean squared error (MSE) loss between outputs and targets. * @param outputs Array of Value predictions. * @param targets Array of Value targets. * @returns Mean squared error as a Value. */ static mse(outputs: Value[], targets: Value[]): Value; /** * Computes mean absolute error (MAE) loss between outputs and targets. * @param outputs Array of Value predictions. * @param targets Array of Value targets. * @returns Mean absolute error as a Value. */ static mae(outputs: Value[], targets: Value[]): Value; static EPS: number; /** * Computes binary cross-entropy loss between predicted outputs and targets (after sigmoid). * @param outputs Array of Value predictions (expected in (0,1)). * @param targets Array of Value targets (typically 0 or 1). * @returns Binary cross-entropy loss as a Value. */ static binaryCrossEntropy(outputs: Value[], targets: Value[]): Value; /** * Computes categorical cross-entropy loss between outputs (logits) and integer target classes. * @param outputs Array of Value logits for each class. * @param targets Array of integer class indices (0-based, one per sample). * @returns Categorical cross-entropy loss as a Value. */ static categoricalCrossEntropy(outputs: Value[], targets: number[]): Value; /** * Computes Huber loss between outputs and targets. * Combines quadratic loss for small residuals and linear loss for large residuals. * @param outputs Array of Value predictions. * @param targets Array of Value targets. * @param delta Threshold at which to switch from quadratic to linear (default: 1.0). * @returns Huber loss as a Value. */ static huber(outputs: Value[], targets: Value[], delta?: number): Value; /** * Computes Tukey loss between outputs and targets. * This robust loss function saturates for large residuals. * * @param outputs Array of Value predictions. * @param targets Array of Value targets. * @param c Threshold constant (typically 4.685). * @returns Tukey loss as a Value. */ static tukey(outputs: Value[], targets: Value[], c?: number): Value; }