yobx.sklearn.manifold.isomap#

yobx.sklearn.manifold.isomap.sklearn_isomap(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: Isomap, X: str, name: str = 'isomap') str[source]#

Converts a sklearn.manifold.Isomap into ONNX.

The out-of-sample embedding follows the algorithm in sklearn.manifold.Isomap.transform():

  1. Find the k nearest training neighbours for each query point using the same distance metric as during fitting (default: Euclidean).

  2. Approximate geodesic distances from every query point to all training points by combining the exact neighbour distances with the pre-computed training-graph shortest-path matrix (dist_matrix_):

    G_X[i, j] = min over neighbor nb of
                  (eucl_dist(X[i], X_train[nb]) + dist_matrix_[nb, j])
    
  3. Convert geodesic distances to kernel values: K = -0.5 * G_X ** 2.

  4. Centre the kernel matrix using the statistics stored in the fitted KernelCenterer:

    K_centered = K - K_fit_rows_ - K.mean(axis=1, keepdims=True) + K_fit_all_
    
  5. Project onto the scaled eigenvectors of the training kernel:

    result = K_centered @ (eigenvectors_ / sqrt(eigenvalues_))
    

The full ONNX graph (standard-ONNX path) is:

X (N, F)
  │
  └── pairwise Euclidean distances ──────────────────► dists (N, M)
                                                              │
                                  TopK(k, largest=0) ─────────┤
                                                          │   │
                                      nb_dists (N, k)    │   │
                                      nb_idx   (N, k)    │   │
                                               │         │   │
 dist_matrix_ (M, M) ──Gather(nb_idx_flat)────┘         │
          │                 │                            │
          │   Reshape(-1,k,M) + Unsqueeze(nb_dists,2) ──┘
          │                 │
          │             Add → ReduceMin(axis=1) ──► G_X (N, M)
          │
          G_X²  × (−0.5) ──► K (N, M)
          │
      K − K_fit_rows_ − K.mean(axis=1) + K_fit_all_ ──► K_c (N, M)
          │
      MatMul(scaled_alphas) ──► output (N, n_components)
Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes defined by scikit-learn

  • estimator – a fitted Isomap

  • outputs – desired output names

  • X – input tensor name

  • name – prefix name for the added nodes

Returns:

output tensor name