instancespace.stages.pilot
PILOT: Obtaining a two- or three-dimensional projection.
Projecting Instances with Linearly Observable Trends (PILOT) is a dimensionality reduction algorithm which aims to facilitate the identification of relationships between instances and algorithms by unveiling linear trends in the data, increasing from one edge of the space to the opposite.
Inputs for the Pilot stage.
Attributes
- x (NDArray[np.double]): The feature matrix (instances x features) to process.
- y (NDArray[np.double]): The data points for the selected feature.
- feat_labels (list[str]): List feature names.
- pilot_options (PilotOptions): The options for the PILOT stage.
- parallel_options (ParallelOptions):
The parallel options, specifying whether to run in parallel and the
number of cores - used to parallelise the numerical solver's
ntriesrestart loop. - general_options (GeneralOptions): General options (e.g. the RNG seed), not specific to any one stage.
- y_bin (NDArray[np.bool_]):
Binary matrix indicating good algorithm performance per instance,
used only when
pilot_options.adjust_rotationis set.
Create new instance of PilotInput(x, y, feat_labels, pilot_options, parallel_options, general_options, y_bin)
Inputs for applying a fitted PILOT projection.
Outputs for the Pilot stage.
Attributes
- X0 (NDArray[np.double] | None): The start points of the numerical solver, one column for each trial. None if PILOT does not use the numerical solver.
- alpha (NDArray[np.double] | None): The solution vector of each numerical trial, one column for each trial. None if PILOT does not use the numerical solver.
- eoptim (NDArray[np.double] | None): The final value of the error function for each numerical trial. None if PILOT does not use the numerical solver.
- perf (NDArray[np.double] | None): For each numerical trial, the Pearson correlation between the distances in feature space and the distances in the projected space. None if PILOT does not use the numerical solver.
- a (NDArray[np.double]):
The projection matrix (dims x features). PLS subtracts
pilot_x_meanbefore projection. - z (NDArray[np.double]): The projected instances (instances x dims).
- c (NDArray[np.double]):
The matrix that estimates the algorithm performance from
z(algorithms x dims). - b (NDArray[np.double]):
The matrix that estimates the features from
z(features x dims). - error (NDArray[np.double]): The sum of the squared errors between the input data and its estimate.
- r2 (NDArray[np.double]): The coefficient of determination (R^2) of the estimate, one value for each feature and algorithm column.
- pilot_summary (pd.DataFrame):
The projection matrix
a, rounded to four decimals, with feature labels. - pilot_x_mean (NDArray[np.double] | None): Fitted feature mean for PLS; None for an uncentred standard projection.
- viewpoint (PilotViewpointResult | None): The optimized viewpoints for the algorithm groups of a 3D projection. None for a 2D projection.
Create new instance of PilotOutput(X0, alpha, eoptim, perf, a, z, c, b, error, r2, pilot_summary, viewpoint, pilot_x_mean)
Class for PILOT stage.
Initialize the Pilot stage.
The Initialize functon is used to create a Pilot class.
Parameters
- x (NDArray[np.double]): The feature matrix (instances x features) to process.
- y (NDArray[np.double]): The data points for the selected feature.
- feat_labels (list[str]): The feature names.
Returns
- None
Project with the fitted PLS mean; older models retain linear inference.
Run the PILOT dimensionality reduction algorithm.
Parameters
- x (NDArray[double]): The feature matrix (instances x features) to process.
- y (NDArray[double]): The data points for the selected feature.
- feat_labels (list[str]): List feature names.
- options (PilotOptions): The options enabled for the Pilot Class.
- general_options (GeneralOptions): General options for all stages, for example the RNG seed.
- y_bin (NDArray[np.bool_] | None):
Binary matrix (instances x algorithms) indicating good algorithm
performance. Required only when
options.adjust_rotationis set. - parallel_options (ParallelOptions | None):
Whether (and how much) to parallelise the numerical solver's
ntriesrestart loop.None(the default for direct callers that don't pass one) runs the restarts sequentially, same asflag=False.
Returns
- PilotOutput: Outputs from the Pilot stage.
Rotate the 2D projection so poorly-solved instances face theta.
Ported from PyISpace's pilot.adjust_rotation()
(gitlab.com/ita-ml/pyispace). Rotation preserves all pairwise
distances in z, so it only changes the space's visual orientation
- error, R2, and footprint areas are unaffected. The centroid of the
instances flagged by
bad_instancesis rotated to sit atthetadegrees (135 = upper-left quadrant, matching PyISpace's default), so that similar datasets come out consistently oriented across runs.
Parameters
- z (NDArray[np.double]): The 2D projection (instances x 2) to rotate.
- bad_instances (NDArray[np.bool_]):
Boolean mask selecting the instances whose centroid should be
placed at
theta. - theta (float): Target angle, in degrees, for the bad-instance centroid.
Returns
- NDArray[np.double]: The rotated projection, same shape as
z. - NDArray[np.double]: The 2x2 rotation matrix applied.
Solve the projection problem analytically.
Parameters
- x (NDArray[np.double]): The feature matrix (instances x features) to process.
- x_bar (NDArray[np.double]): Combined matrix of X and Y.
- n (int): Number of original features.
- m (int): Total number of features including appended Y.
- cost_weight (float): Scalar performance-reconstruction weight (MATLAB's costWeight). Scales the performance block relative to the feature block before the eigendecomposition; 1.0 weights both blocks equally.
- dims (int): Output projection dimensionality, either 2 or 3.
Returns
- NDArray[np.double]: Matrix A.
- NDArray[np.double]: Matrix B.
- NDArray[np.double]: Matrix C.
- NDArray[np.double]: Matrix Z.
- NDArray[np.double]: The mean squared error between x_bar and its low-dimensional approximation.
- NDArray[np.double]: The coefficient of determination between x_bar and its low-dimensional approximation.
Solve the projection problem via Partial Least Squares.
MATLAB's method='pls' alternative to the
analytic/numeric eigen-decomposition solvers above - a genuinely
different algorithm, not a variant of either. dims matches
MATLAB's own plsregress(X, Y, d) call.
Implements the SIMPLS routine used by MATLAB R2026a's plsregress.
Both inputs are mean-centred but not variance-scaled, matching the
default MATLAB call in PILOT.m.
Parameters
- x (NDArray[np.double]): The feature matrix (instances x features) to process.
- y (NDArray[np.double]): The performance matrix (instances x algorithms).
- x_bar (NDArray[np.double]): Combined matrix of X and Y.
- m (int): Total number of features including appended Y.
- dims (int): Output projection dimensionality, either 2 or 3.
Returns
- NDArray[np.double]: Matrix A (dims x n), the projection matrix: Z = (X - mean(X)) @ A.T.
- NDArray[np.double]: Matrix Z (instances x dims), the projected coordinates.
- NDArray[np.double]: Matrix C (dims x q), the performance-block reconstruction matrix.
- NDArray[np.double]: Matrix B (n x dims), the feature-block reconstruction matrix.
- NDArray[np.double]: The sum of squared reconstruction error between x_bar and its low-dimensional approximation.
- NDArray[np.double]: The per-column coefficient of determination between x_bar and its low-dimensional approximation.
Solve the projection problem numerically.
Parameters
- x (NDArray[np.double]): The feature matrix (instances x features) to process.
- hd (NDArray[np.double]): Condensed pairwise distances between the instances in feature space. The quality of each trial is the Pearson correlation between these distances and the distances in the projected space.
- x0 (NDArray[np.double]): Initial guess for the solution.
- x_bar (NDArray[np.double]): Combined matrix of X and Y.
- n (int): Number of original features.
- m (int): Total number of features including appended Y.
- alpha (NDArray[np.double]): Flattened parameter vector containing both A (dimsn size) and B (mdims size) matrices.
- eoptim (NDArray[np.double]): Optimized error function.
- perf (NDArray[np.double]): Optimized performance matrix.
- opts (PilotOptions): Configuration options for PILOT.
- general_options (GeneralOptions): General options for all stages, for example verbosity.
- parallel_options (ParallelOptions | None):
Whether (and how much) to parallelise the
ntriesrestarts across OS processes (matching MATLAB'sparfor).Noneorflag=Falseruns the restarts sequentially. Ignored - falls back to sequential - when already running inside another process pool's worker (seemultiprocessing.parent_process()check below): SIFTED's GA fitness function calls intopilot()from inside its ownProcessPoolExecutorworkers, and opening a second, nested pool there would reintroduce MATLAB's nested-parfor-inside-GA bug. In practice this never triggers today, since SIFTED always callspilot()withanalytic=True(bypassing this numerical branch entirely) - this check guards against that invariant ever changing silently.
Returns
- int: The index of the trial that has the highest distance correlation.
- NDArray[np.double]: Flattened parameter vector containing both A (dimsn size) and B (mdims size) matrices.
- NDArray[np.double]: Optimized error function.
- NDArray[np.double]: Optimized performance matrix.
Error function used for numerical optimization in the PILOT algorithm.
Parameters
- alpha (NDArray[np.float64]): Flattened parameter vector containing both A (dn size) and B (md size) matrices.
- x_bar (NDArray[np.float64]): Combined matrix of X and Y.
- n (int): Number of original features.
- m (int): Total number of features including appended Y.
- cost_weight (float):
Scalar weight applied to the performance columns' squared error
(MATLAB's
pilotErrorFcncostWeight). 1.0 weights every column equally. - d (int): Output projection dimensionality, either 2 or 3.
Returns
- float: The mean squared error between x_bar and its low-dimensional approximation.