yobx.sklearn.covariance.empirical_covariance#

yobx.sklearn.covariance.empirical_covariance.sklearn_empirical_covariance(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: EmpiricalCovariance, X: str, name: str = 'empirical_covariance') str[source]#

Converts a sklearn.covariance.EmpiricalCovariance into ONNX.

The converter maps to mahalanobis(), returning the squared Mahalanobis distance from the fitted distribution for each observation:

d^2(x) = (x - \mu)^\top \, \Sigma^{-1} \, (x - \mu)
        = \sum_j \bigl[(x - \mu) \Sigma^{-1}\bigr]_j \cdot (x - \mu)_j

where \mu is location_ and \Sigma^{-1} is precision_.

Full graph structure:

X (N, F)
  │
  └─ Sub(location_) ──► X_centered (N, F)
       │
       ├─ MatMul(precision_) ──► X_prec (N, F)
       │                              │
       └──────────────────── Mul ──► X_prec_centered (N, F)
                                      │
                           ReduceSum(axis=1) ──► mahal_sq (N,)  [output]
Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes defined by scikit-learn

  • outputs – desired output names; outputs[0] receives the squared Mahalanobis distances

  • estimator – a fitted EmpiricalCovariance

  • X – input tensor name

  • name – prefix for added node names

Returns:

output tensor name