Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.ionworks.com/llms.txt

Use this file to discover all available pages before exploring further.

Objective functions define how the discrepancy between model predictions and experimental data is quantified during parameter fitting.

Cost Function Formulations

Residual Form (Array)

The residual vector represents the difference between model predictions and data: r(x)=ymodel(x)ydatar(x) = y_{\text{model}}(x) - y_{\text{data}} where xx represents the parameter vector.

Canonical Form (Scalar)

The canonical cost function aggregates the residuals into a single scalar value: Φ(x)r(x)r(x)=iNri(x)2\Phi(x) \propto r(x)^\top r(x) = \sum_i^N r_i(x)^2 This sum-of-squares formulation is fundamental to least-squares optimization.

Common Cost Functions

The basic sum of squared residuals:ΦSSE(x)=iNri2=rr\Phi_{\text{SSE}}(x) = \sum_i^N r_i^2 = r^\top rThis can be represented in both array and scalar forms, making it compatible with all optimization algorithms.

Maximum Likelihood Estimation (MLE)

Under the assumption of independent, identically distributed Gaussian errors, the MLE cost function is: rMLE(x)=ymodelydatar_{\text{MLE}}(x) = y_{\text{model}} - y_{\text{data}} ΦMLE(x)=iNri2=rr\Phi_{\text{MLE}}(x) = \sum_i^N r_i^2 = r^\top r This is equivalent to the sum squared error formulation, providing a probabilistic interpretation of least-squares fitting.

Usage in ionworkspipeline

import ionworkspipeline as iwp

# Default: Sum Squared Error
objective = iwp.objectives.FittingObjective(
    options={"model": model, "data": data},
    cost=iwp.costs.SumSquaredError()
)

# Mean Squared Error
objective = iwp.objectives.FittingObjective(
    options={"model": model, "data": data},
    cost=iwp.costs.MeanSquaredError()
)

# Root Mean Squared Error (scalar-only)
objective = iwp.objectives.FittingObjective(
    options={"model": model, "data": data},
    cost=iwp.costs.RMSE()
)
For most optimization algorithms, the 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.