Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/ai-and-statistics/matlab-engineer-tabular-features

matlab-engineer-tabular-features

Unverified

Use when engineering or selecting the best features for single-response classification or regression in MATLAB, whatever the data's modality — for non-tabular data it routes extraction to a domain skill, then selects, assesses, and delivers on the resulting table. Not for multi-response problems, model training, or raw data acquisition.

FileKindSize
SKILL.mdskill md18.9 KB
manifest.yamlconfig570 B
references/assess.mdmarkdown16.7 KB
references/deliver.mdmarkdown13.0 KB
references/domain-routing.mdmarkdown18.1 KB
references/feature-pool.mdmarkdown10.9 KB
references/intake.mdmarkdown16.9 KB
references/internal-helpers.mdmarkdown12.2 KB
references/provider-protocol.mdmarkdown12.3 KB
references/report.mdmarkdown9.7 KB
references/reproduce-pool.mdmarkdown7.1 KB
references/select.mdmarkdown7.1 KB
scripts/BordaVoter.mother2.3 KB
scripts/ConsensusVoter.mother2.5 KB
scripts/MajorityVoter.mother2.0 KB
scripts/RRFVoter.mother1.9 KB
scripts/assessGenerationStability.mother11.9 KB
scripts/assessKFold.mother20.6 KB
scripts/assessSelectionStability.mother9.8 KB
scripts/baselineComparison.mother18.9 KB
scripts/buildRecipe.mother8.2 KB
scripts/chooseNumBins.mother5.0 KB
scripts/chooseStandardization.mother4.5 KB
scripts/computeNSelect.mother2.9 KB
scripts/createConsensusVoter.mother2.2 KB
scripts/describeFeatures.mother5.1 KB
scripts/expandBlockMap.pbinary440 B
scripts/featureSetQuality.mother12.3 KB
scripts/generateFeatureReport.mother67.2 KB
scripts/generateFeatureReportPdf.mother64.9 KB
scripts/generateFeatures.mother14.6 KB
scripts/hasReportGenerator.mother630 B
scripts/isDomainRecipe.mother1.4 KB
scripts/isStringEmpty.mother577 B
scripts/lambdaSequence.pbinary637 B
scripts/lassoFeatureRanking.pbinary971 B
scripts/macroF1Score.mother931 B
scripts/mrmrFeatureRanking.pbinary239 B
scripts/mutualInformationPanel.pbinary1.1 KB
scripts/ncaFeatureRanking.pbinary464 B
scripts/nogueiraStability.mother3.8 KB
scripts/oobFeatureRanking.pbinary414 B
scripts/plotSelectionConsensus.mother2.7 KB
scripts/plotSelectionDecision.mother6.3 KB
scripts/plotSelectionStability.mother10.2 KB
scripts/plotValidationBaseline.mother6.1 KB
scripts/printSummary.mother18.3 KB
scripts/profileForSplit.mother6.2 KB
scripts/rankAgreement.mother1.3 KB
scripts/rankFeatures.mother6.2 KB
scripts/reserveHoldoutForUser.mother5.5 KB
scripts/runConsensusSelection.mother9.4 KB
scripts/sampleSkewness.mother600 B
scripts/saveResults.mother2.1 KB
scripts/scoreFeaturePanel.pbinary1.6 KB
scripts/screenPredictors.mother13.3 KB
scripts/selectFeatures.mother2.3 KB
scripts/splitStrategy.mother5.4 KB
scripts/stratifiedDownsampleRows.mother2.2 KB
scripts/stratifiedSubsampleIndices.mother3.4 KB
scripts/transformFeatures.mother6.1 KB
scripts/validateRecipe.mother12.3 KB
scripts/writeInferenceScript.mother10.5 KB

scripts/validateRecipe.m

View on GitHub
function validateRecipe(Recipe, FeatureTable, RawInput, Options)
%validateRecipe Confirm a captured domain recipe reproduces its own pool.
%
%   validateRecipe(Recipe, FeatureTable, RawInput) checks that a captured domain
%   recipe faithfully describes and reproduces the feature pool it was captured
%   from -- on a small sample of rows, value-for-value. It is the semantic gate
%   the structural checks in transformFeatures/describeFeatures cannot provide:
%   those confirm a recipe is well-shaped and name-consistent, but a hand-captured
%   handle that computes the WRONG values (a dropped step, a wrong parameter), or
%   a Describe that lists the wrong features, still passes them. Comparing against
%   the pool actually used for selection is the only check with ground truth.
%
%   The gate runs in TWO MODES, matching the two moments a domain recipe is
%   captured (see domain-routing.md / deliver.md):
%
%   1. Capture / execution mode -- validateRecipe(Recipe, FeatureTable, RawInput).
%      Called right after the pool is built, BEFORE selection. The recipe drives
%      generation, selection, and assessment, all of which need the full pool, so
%      it must carry Kind, Apply, Describe, Provider. Checked against ground truth:
%        - Apply     reproduces every pool feature's VALUES.
%        - Describe  lists exactly the pool's features -- no un-described real
%                    feature, no phantom described one.
%      ApplySelected is NOT expected yet: it is an inference-only path and cannot
%      be built well until the selected set is known (see mode 2).
%
%   2. Deliver mode -- validateRecipe(..., SelectedNames=Names). Called at deliver
%      time with the chosen features. The recipe must ALSO carry an ApplySelected
%      handle targeted at exactly those names, checked to return exactly the
%      SelectedNames columns with the same values Apply would -- the selected-only
%      inference path the emitted script uses.
%
%   Kind and Provider are presence-only (Kind is the type tag; Provider is free
%   text used in report prose, with nothing to verify against the pool).
%
%   Intended for the DOMAIN path only: an SMLT FeatureTransformer needs no check
%   (its transform/describe methods are tested code that reproduce columns by
%   construction), so this returns immediately for one.
%
%   On any problem it throws a hard error naming the offending artifact, because a
%   recipe that cannot reproduce or describe its own pool would ship a broken
%   deliverable. The caller is expected to re-request that artifact from the domain
%   skill and re-validate. Error ids:
%     - validateRecipe:missingArtifact       a required field is absent
%     - validateRecipe:poolMismatch          Apply reproduces wrong/missing values
%     - validateRecipe:describeMismatch       Describe lists the wrong features
%     - validateRecipe:applySelectedMismatch  ApplySelected (deliver mode) disagrees
%                                             with the pool or over-returns columns
%
%   RawInput must be row-aligned with FeatureTable (one raw row per pool row). It
%   is the raw data in whatever form Apply consumes -- a table, a numeric matrix,
%   a cell array, etc. -- and is NOT constrained to a table: the gate only
%   row-indexes it (height + RawInput(Rows,:)), which every row-indexable array
%   supports. Apply's one hard contract is that it RETURNS a table (checked by
%   callHandle); its input type is the extractor's business.
%   Pass Options.CheckIdx = the HELD-OUT (test) row indices: replaying Apply on
%   training rows can legitimately disagree with the pool when the extraction used
%   response-based out-of-fold encoding (train rows hold out-of-fold values, Apply
%   replays the full map), which would be a false mismatch. Held-out rows are
%   transformed the same way at capture and inference, so they compare cleanly.
%
%   Inputs:
%     Recipe       - a domain recipe struct (Kind=="domain" with an Apply handle);
%                    anything else needs no check and returns
%     FeatureTable - the materialized pool the recipe was captured from
%                    (predictors + response), one row per observation
%     RawInput     - the raw data Apply consumes (any row-indexable form: table,
%                    matrix, cell array, ...), row-aligned with FeatureTable
%     Options.SelectedNames (1,:) string = []  the chosen features; supplying them
%                                               switches on deliver mode (require +
%                                               validate ApplySelected against them)
%     Options.ResponseVar   (1,1) string = ""   response column, excluded from the
%                                               feature set if present
%     Options.CheckIdx      (1,:) double = []   rows to check; default is an
%                                               evenly-spaced sample across all rows
%     Options.NumSampleRows (1,1) double = 32   sample-size cap (kept small)
%     Options.RelTol        (1,1) double = 1e-9 relative tolerance for numeric cols

% Copyright 2026 The MathWorks, Inc.

    arguments
        Recipe
        FeatureTable table
        RawInput
        Options.SelectedNames (1,:) string = string.empty
        Options.ResponseVar (1,1) string = ""
        Options.CheckIdx (1,:) double = []
        Options.NumSampleRows (1,1) double = 32
        Options.RelTol (1,1) double = 1e-9
    end

    DeliverMode = ~isempty(Options.SelectedNames);

    % Only a hand-captured domain recipe carries the faithfulness risk this gate
    % addresses; an SMLT transformer reproduces columns by construction.
    if ~isDomainRecipe(Recipe)
        return;
    end

    % Required fields depend on the mode (Kind is already assured by isDomainRecipe
    % above; Provider is presence-only free text). Capture/execution mode needs the
    % full-pool artifacts; deliver mode additionally needs ApplySelected, which is
    % only buildable once the selected set is known.
    Required = ["Apply", "Describe", "Provider"];
    if DeliverMode
        Required(end+1) = "ApplySelected";
    end
    AbsentFields = Required(arrayfun(@(F) ~isfield(Recipe, F), Required));
    if ~isempty(AbsentFields)
        error("validateRecipe:missingArtifact", ...
            "The domain recipe is missing required field(s): %s.", ...
            strjoin(AbsentFields, ", "));
    end
    if ~isa(Recipe.Apply, "function_handle")
        error("validateRecipe:missingArtifact", "Apply must be a function handle.");
    end
    if DeliverMode && ~isa(Recipe.ApplySelected, "function_handle")
        error("validateRecipe:missingArtifact", ...
            "ApplySelected must be a function handle.");
    end

    if height(RawInput) ~= height(FeatureTable)
        error("validateRecipe:rowMisalignment", ...
            ['RawInput has %d rows but the pool has %d; Apply maps raw rows to ' ...
            'pool rows one-for-one, so they must align.'], ...
            height(RawInput), height(FeatureTable));
    end

    % Ground truth: the pool's feature columns (everything bar the response).
    FeatureNames = string(FeatureTable.Properties.VariableNames);
    FeatureNames = FeatureNames(FeatureNames ~= Options.ResponseVar);

    Rows = sampleRows(height(FeatureTable), Options.CheckIdx, Options.NumSampleRows);
    RawSample = RawInput(Rows, :);
    PoolSample = FeatureTable(Rows, :);

    % 1. Apply -- reproduces every pool feature's values.
    Full = callHandle(Recipe.Apply, {RawSample}, "Apply");
    [Missing, Diverged] = compareColumns(Full, PoolSample, FeatureNames, Options.RelTol);
    if ~isempty(Missing) || ~isempty(Diverged)
        error("validateRecipe:poolMismatch", ...
            ['Apply does not reproduce the captured pool: %s. Re-capture Apply ' ...
            'from the domain skill.'], missDivMsg(Missing, Diverged));
    end

    % 2. Describe -- lists exactly the pool's features.
    Described = string(Recipe.Describe.Feature(:)).';
    Undescribed = setdiff(FeatureNames, Described, "stable");   % real, not listed
    Phantom = setdiff(Described, FeatureNames, "stable");       % listed, not real
    if ~isempty(Undescribed) || ~isempty(Phantom)
        error("validateRecipe:describeMismatch", ...
            ['Describe does not match the pool%s%s. Re-capture Describe from ' ...
            'the domain skill.'], ...
            listPart(" -- missing feature(s): ", Undescribed), ...
            listPart(" -- feature(s) not in pool: ", Phantom));
    end

    % Capture mode stops here -- ApplySelected is validated only in deliver mode.
    if ~DeliverMode
        return;
    end

    % 3. ApplySelected (deliver mode) -- the selected-only inference path. The set
    % is now known, so check it directly: asked for exactly SelectedNames, it must
    % return exactly those columns (no over-return -- a handle that ignores its
    % argument and dumps the whole pool defeats the point) with the same values
    % Apply gives. SelectedNames must be actual pool features.
    Selected = Options.SelectedNames;
    NotInPool = setdiff(Selected, FeatureNames, "stable");
    if ~isempty(NotInPool)
        error("validateRecipe:applySelectedMismatch", ...
            'SelectedNames contains non-pool feature(s): %s.', ...
            strjoin(NotInPool, ", "));
    end
    Sel = callHandle(Recipe.ApplySelected, {RawSample, Selected}, "ApplySelected");
    Returned = string(Sel.Properties.VariableNames);
    if ~isempty(setdiff(Returned, Selected, "stable"))
        error("validateRecipe:applySelectedMismatch", ...
            ['ApplySelected returned columns beyond the %d requested (%d back). ' ...
            'It must return only the selected columns; re-request it from the ' ...
            'domain skill.'], numel(Selected), numel(Returned));
    end
    [Missing, Diverged] = compareColumns(Sel, PoolSample, Selected, Options.RelTol);
    if ~isempty(Missing) || ~isempty(Diverged)
        error("validateRecipe:applySelectedMismatch", ...
            ['ApplySelected disagrees with the pool: %s. It must return the same ' ...
            'values Apply does for the selected columns; re-request it from the ' ...
            'domain skill.'], missDivMsg(Missing, Diverged));
    end
end


function Out = callHandle(Handle, ArgList, Name)
%callHandle Invoke a recipe handle and require a table result.
    Out = Handle(ArgList{:});
    if ~istable(Out)
        error("validateRecipe:domainNotTable", ...
            "The domain recipe's %s function must return a table.", Name);
    end
end


function [Missing, Diverged] = compareColumns(Actual, PoolSample, Names, RelTol)
%compareColumns Which requested names are absent from / diverge from the pool.
    Have = string(Actual.Properties.VariableNames);
    Missing = setdiff(Names, Have, "stable");
    Diverged = string.empty;
    for Name = setdiff(Names, Missing, "stable")
        if ~columnsMatch(PoolSample.(Name), Actual.(Name), RelTol)
            Diverged(end+1) = Name; %#ok<AGROW>
        end
    end
end


function Rows = sampleRows(N, CheckIdx, Cap)
%sampleRows Up to Cap rows to check: the caller's set (capped), or an evenly-
%   spaced sweep across all N rows when none is given.
    if ~isempty(CheckIdx)
        Pool = unique(CheckIdx(:).', "stable");
    else
        Pool = 1:N;
    end
    if numel(Pool) > Cap
        Pick = round(linspace(1, numel(Pool), Cap));
        Pool = Pool(unique(Pick, "stable"));
    end
    Rows = Pool;
end


function Tf = columnsMatch(Expected, Actual, RelTol)
%columnsMatch Compare one pool column against its reproduction: tolerant on
%   floats, exact otherwise.
    if numel(Expected) ~= numel(Actual)
        Tf = false;
        return;
    end
    if isnumeric(Expected) && isnumeric(Actual)
        E = double(Expected(:));
        A = double(Actual(:));
        Scale = max(1, abs(E));
        Both = ~isnan(E) & ~isnan(A);
        Tf = all(isnan(E) == isnan(A)) ...
            && all(abs(E(Both) - A(Both)) <= RelTol .* Scale(Both));
    else
        Tf = isequal(Expected, Actual);
    end
end


function Msg = missDivMsg(Missing, Diverged)
%missDivMsg One-line account of missing and value-diverged columns.
    Msg = strtrim(listPart("missing ", Missing) + listPart(" wrong-valued ", Diverged));
    if Msg == ""
        Msg = "no columns";
    end
end


function Part = listPart(Label, Names)
%listPart "<Label>a, b" for a non-empty name list, else "".
    if isempty(Names)
        Part = "";
    else
        Part = Label + strjoin(Names, ", ");
    end
end
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 466kUpdated Claude CodeCodexVerifiedInstall
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 466kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 319kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 319kUpdated Claude CodeCodexVerifiedInstall