function XTable = canonicalizePoints(this, XTable)
% "Canonicalization" is how we handle parameters that are NaN
% due to the action of the ConditionalVariableFcn. To give
% these points a "canonical" location in X-space, we map
% numeric missing values to the minimum of their range, and we
% map categoricals to their first category.
%

%   Copyright 2016-2022 The MathWorks, Inc.


% Only canonicalize points when the model type is GP since RF
% can handle NaN and undefined values
if strcmp(this.PrivOptions.ModelType, 'GaussianProcess') ||...
        strcmp(this.PrivOptions.ModelType, 'MultiGaussianProcess')
    if isempty(this.CanonicalVector)
        VarSpec = this.PrivOptions.VarSpec;
        for v = 1:width(XTable)
            if VarSpec.isCat(v)
                cats = VarSpec.Categories{v};
                val = char(cats(1));
            else
                val = VarSpec.LBs(v);
            end
            this.CanonicalVector{v} = val;
        end
    end
    XTable = fillmissing(XTable, 'constant', this.CanonicalVector);
end
end
