The canonical cost function aggregates the residuals into a single scalar value:Φ(x)∝r(x)⊤r(x)=i∑Nri(x)2This sum-of-squares formulation is fundamental to least-squares optimization.
The basic sum of squared residuals:ΦSSE(x)=i∑Nri2=r⊤rThis can be represented in both array and scalar forms, making it compatible with all optimization algorithms.
Normalized by the number of data points:ΦMSE(x)=N1i∑Nri2
The square root of MSE:ΦRMSE(x)=N1i∑Nri2
RMSE cannot be represented in a residual array form because there is no mapping from residuals to the canonical scalar form. This limits its compatibility with some optimization algorithms.
The Wasserstein distance (also known as earth mover’s distance) measures the distance between two probability distributions. Intuitively, it is the minimum amount of “work” required to transform one distribution into the other.For one-dimensional samples, it is computed by sorting both arrays and comparing them point-wise:ΦW(x)=N1i∑N∣y~model,i(x)−y~data,i∣where y~ denotes the sorted samples.Use Wasserstein when you care about matching the distribution of values (for example, a histogram of cell capacities or impedance magnitudes) rather than point-wise agreement in time. Because the inputs are sorted before comparison, the result is invariant to the ordering of the model and data arrays.Weighted point-cloud mode. When one variable supplies positions and another supplies weights — for example matching a dQ/dV curve where peaks should align in voltage — pass both position_variable and weight_variable to iws.costs.Wasserstein. The cost then computes a single weighted Wasserstein-1 distance per objective:ΦW,weighted(x)=W1(pmodel,pdata,wmodel,wdata)where positions p come from position_variable and the (sign-stripped, renormalised) weights w come from weight_variable. Both must be set together. See Pipelines → Data Fitting → Objective Functions for a configuration example.
Under the assumption of independent, identically distributed Gaussian errors, the MLE cost function is:rMLE(x)=ymodel−ydataΦMLE(x)=i∑Nri2=r⊤rThis is equivalent to the sum squared error formulation, providing a probabilistic interpretation of least-squares fitting.
For most optimization algorithms, the default sum-squared-error formulation provides the best compatibility and performance. Use MSE or RMSE when you need interpretable, scale-independent metrics.
The cost functions and usage examples above are not exhaustive. See the API reference for full details on costs and objectives.