MLCore::RobustPCAOperation
MLCore::RobustPCAOperation
Robust PCA dimensionality reduction via ROSL. More…
#include <RobustPCAOperation.hpp>
Inherits from MLCore::MLDimReductionOperation, MLCore::MLModelOperation
Public Classes
| Name | |
|---|---|
| struct | Impl |
Public Functions
| Name | |
|---|---|
| RobustPCAOperation() | |
| ~RobustPCAOperation() override | |
| RobustPCAOperation(RobustPCAOperation const & ) =delete | |
| RobustPCAOperation & | operator=(RobustPCAOperation const & ) =delete |
| RobustPCAOperation(RobustPCAOperation && ) | |
| RobustPCAOperation & | operator=(RobustPCAOperation && ) |
| virtual std::string | getName() const override Unique human-readable name for this model (e.g., “Random Forest”). |
| virtual std::unique_ptr< MLModelParametersBase > | getDefaultParameters() const override Create a default parameter set for this model. |
| virtual bool | isTrained() const override Whether the model has been trained (supervised) or fit (unsupervised). |
| virtual std::size_t | numFeatures() const override Number of features the model was trained on. |
| virtual bool | fitTransform(arma::mat const & features, MLModelParametersBase const * params, arma::mat & result) override Fit the model to data and transform in a single call. |
| virtual bool | transform(arma::mat const & features, arma::mat & result) override Project new data using the fitted model. |
| virtual std::size_t | outputDimensions() const override Return the number of output dimensions after reduction. |
| virtual std::vector< double > | explainedVarianceRatio() const override Return the explained variance ratio per component (if available). |
| virtual bool | save(std::ostream & out) const override Save the trained model to a stream. |
| virtual bool | load(std::istream & in) override Load a previously saved model from a stream. |
Additional inherited members
Public Functions inherited from MLCore::MLDimReductionOperation
| Name | |
|---|---|
| ~MLDimReductionOperation() override =default | |
| virtual MLTaskType | getTaskType() const override Dimensionality reduction is always its own task type. |
| virtual bool | fit(arma::mat const & features, MLModelParametersBase const * params) override Route fit() to fitTransform() (discarding the result). |
Public Functions inherited from MLCore::MLModelOperation
| Name | |
|---|---|
| virtual | ~MLModelOperation() =default |
| virtual MLTaskType | getTaskType() const =0 The ML task type this operation supports. |
| virtual bool | train(arma::mat const & features, arma::Row< std::size_t > const & labels, MLModelParametersBase const * params) Train the model on labeled data. |
| virtual bool | predict(arma::mat const & features, arma::Row< std::size_t > & predictions) Predict class labels for new observations. |
| virtual bool | predictProbabilities(arma::mat const & features, arma::mat & probabilities) Predict class probabilities for new observations. |
| virtual bool | trainSequences(std::vector< arma::mat > const & featureSequences, std::vector< arma::Row< std::size_t > > const & labelSequences, MLModelParametersBase const * params) Train the model on pre-segmented temporal sequences. |
| virtual bool | predictSequences(std::vector< arma::mat > const & featureSequences, std::vector< arma::Row< std::size_t > > & predictionSequences) Predict labels for pre-segmented temporal sequences. |
| virtual bool | predictSequencesConstrained(std::vector< arma::mat > const & featureSequences, std::vector< arma::Row< std::size_t > > & predictionSequences, std::vector< std::optional< std::size_t > > const & initial_state_constraints) Predict labels with per-sequence initial state constraints. |
| virtual bool | predictSequencesBidirectionalConstrained(std::vector< arma::mat > const & featureSequences, std::vector< arma::Row< std::size_t > > & predictionSequences, std::vector< std::optional< std::size_t > > const & initial_state_constraints, std::vector< std::optional< std::size_t > > const & terminal_state_constraints) Predict labels with both initial and terminal state constraints. |
| virtual bool | predictProbabilitiesPerSequence(std::vector< arma::mat > const & featureSequences, std::vector< arma::mat > & probabilitySequences, std::vector< std::optional< std::size_t > > const & initial_state_constraints, std::vector< std::optional< std::size_t > > const & terminal_state_constraints) Compute per-sequence state probabilities with boundary constraints. |
| virtual bool | isSequenceModel() const Whether this model natively handles temporal sequences. |
| virtual bool | fit(arma::mat const & features, MLModelParametersBase const * params) Fit the model to unlabeled data (unsupervised). |
| virtual bool | assignClusters(arma::mat const & features, arma::Row< std::size_t > & assignments) Assign cluster labels to observations. |
| virtual std::size_t | numClasses() const Number of classes (supervised) or clusters (unsupervised). |
Detailed Description
class MLCore::RobustPCAOperation;Robust PCA dimensionality reduction via ROSL.
Decomposes a matrix X into a low-rank component A and sparse errors E: X = A + E, where A = D * B
The dictionary D (features × rank) and coefficients B (rank × observations) are the key outputs. For dimensionality reduction, SVD is applied to the low-rank component A to extract the top n_components principal directions, which are robust to sparse outliers.
Usage
RobustPCAOperation rpca;
RobustPCAParameters params;
params.n_components = 2;
params.lambda = 0.0; // auto-compute
arma::mat result;
rpca.fitTransform(features, ¶ms, result);
// result is (2 × observations)Supports transform() for projecting new data using the learned basis.
Public Functions Documentation
function RobustPCAOperation
RobustPCAOperation()function ~RobustPCAOperation
~RobustPCAOperation() overridefunction RobustPCAOperation
RobustPCAOperation(
RobustPCAOperation const &
) =deletefunction operator=
RobustPCAOperation & operator=(
RobustPCAOperation const &
) =deletefunction RobustPCAOperation
RobustPCAOperation(
RobustPCAOperation &&
)function operator=
RobustPCAOperation & operator=(
RobustPCAOperation &&
)function getName
virtual std::string getName() const overrideUnique human-readable name for this model (e.g., “Random Forest”).
Reimplements: MLCore::MLModelOperation::getName
Used as the key in MLModelRegistry and displayed in the UI.
function getDefaultParameters
virtual std::unique_ptr< MLModelParametersBase > getDefaultParameters() const overrideCreate a default parameter set for this model.
Reimplements: MLCore::MLModelOperation::getDefaultParameters
Returns a new instance with algorithm-specific defaults. The caller owns the returned pointer.
function isTrained
virtual bool isTrained() const overrideWhether the model has been trained (supervised) or fit (unsupervised).
Reimplements: MLCore::MLModelOperation::isTrained
Returns true after a successful [train()](/api_generated/Classes/classMLCore_1_1MLModelOperation.md#function-train) or [fit()](/api_generated/Classes/classMLCore_1_1MLDimReductionOperation.md#function-fit) call, or after a successful [load()](/api_generated/Classes/classMLCore_1_1RobustPCAOperation.md#function-load).
function numFeatures
virtual std::size_t numFeatures() const overrideNumber of features the model was trained on.
Reimplements: MLCore::MLModelOperation::numFeatures
Returns 0 if the model has not been trained/fit. Used for validating that prediction data has the correct dimensionality.
function fitTransform
virtual bool fitTransform(
arma::mat const & features,
MLModelParametersBase const * params,
arma::mat & result
) overrideFit the model to data and transform in a single call.
Parameters:
- features Input matrix (features × observations) in mlpack convention
- params Algorithm-specific parameters
- result Output: reduced matrix (n_components × observations)
Return: true on success
Precondition:
- features must not be empty (enforcement: runtime_check)
- features must not contain NaN or Inf values (enforcement: none) [IMPORTANT]
- params must be of the correct concrete type for this operation (enforcement: none)
- Features are expected to be z-score normalized (mean≈0, std≈1 per feature) when scale-sensitive comparison across features is desired. Normalization is the caller’s responsibility (via FeatureConverter). Centering is handled internally by each algorithm. (enforcement: none) [IMPORTANT]
Postcondition:
- isTrained() returns true on success
- result has n_components rows and features.n_cols columns
Reimplements: MLCore::MLDimReductionOperation::fitTransform
function transform
virtual bool transform(
arma::mat const & features,
arma::mat & result
) overrideProject new data using the fitted model.
Parameters:
- features Input matrix (features × observations)
- result Output: reduced matrix (n_components × observations)
Return: true on success, false if not fitted or projection unsupported
Precondition:
- isTrained() must be true (enforcement: runtime_check)
- features.n_rows must equal numFeatures() (enforcement: none) [IMPORTANT]
- features must not contain NaN or Inf values (enforcement: none) [IMPORTANT]
- Features must be z-score normalized using the SAME parameters (mean/std) that were used for the training data passed to fitTransform(). Use FeatureConverter::applyZscoreNormalization() with stored parameters. (enforcement: none) [IMPORTANT]
Reimplements: MLCore::MLDimReductionOperation::transform
function outputDimensions
virtual std::size_t outputDimensions() const overrideReturn the number of output dimensions after reduction.
Reimplements: MLCore::MLDimReductionOperation::outputDimensions
function explainedVarianceRatio
virtual std::vector< double > explainedVarianceRatio() const overrideReturn the explained variance ratio per component (if available).
Return: Vector of explained variance ratios (one per component), or empty if not applicable to this algorithm
Reimplements: MLCore::MLDimReductionOperation::explainedVarianceRatio
function save
virtual bool save(
std::ostream & out
) const overrideSave the trained model to a stream.
Parameters:
- out Output stream (binary or text, model-dependent)
Return: true if save succeeded
Reimplements: MLCore::MLModelOperation::save
The default implementation returns false (no persistence support).
function load
virtual bool load(
std::istream & in
) overrideLoad a previously saved model from a stream.
Parameters:
- in Input stream
Return: true if load succeeded
Reimplements: MLCore::MLModelOperation::load
After successful loading, [isTrained()](/api_generated/Classes/classMLCore_1_1RobustPCAOperation.md#function-istrained) should return true. The default implementation returns false (no persistence support).
Updated on 2026-11-13 at 20:25:42 +0000