internal ColumnInfoBase(ModelLoadContext ctx, string input, string output, bool normKindSerialized) { Contracts.AssertValue(ctx); Contracts.CheckNonWhiteSpace(input, nameof(input)); Contracts.CheckNonWhiteSpace(output, nameof(output)); Input = input; Output = output; // *** Binary format *** // byte: SubtractMean // byte: NormKind // Float: Scale SubtractMean = ctx.Reader.ReadBoolByte(); byte normKindVal = ctx.Reader.ReadByte(); Contracts.CheckDecode(Enum.IsDefined(typeof(LpNormalizingEstimatorBase.NormalizerKind), normKindVal)); NormKind = (LpNormalizingEstimatorBase.NormalizerKind)normKindVal; // Note: In early versions, a bool option (useStd) to whether to normalize by StdDev rather than // L2 norm was used. normKind was added in version=verVectorNormalizerSupported. // normKind was defined in a way such that the serialized boolean (0: use StdDev, 1: use L2) is // still valid. Contracts.CheckDecode(normKindSerialized || (NormKind == LpNormalizingEstimatorBase.NormalizerKind.L2Norm || NormKind == LpNormalizingEstimatorBase.NormalizerKind.StdDev)); Scale = ctx.Reader.ReadFloat(); Contracts.CheckDecode(0 < Scale && Scale < float.PositiveInfinity); }
internal ColumnInfoBase(string input, string output, bool substractMean, LpNormalizingEstimatorBase.NormalizerKind normalizerKind, float scale) { Contracts.CheckNonWhiteSpace(input, nameof(input)); Contracts.CheckNonWhiteSpace(output, nameof(output)); Input = input; Output = output; SubtractMean = substractMean; Contracts.CheckUserArg(0 < scale && scale < float.PositiveInfinity, nameof(scale), "scale must be a positive finite value"); Scale = scale; NormKind = normalizerKind; }
/// <include file='doc.xml' path='doc/members/member[@name="LpNormalize"]/*'/> /// <param name="input">The column to apply to.</param> /// <param name="normKind">Type of norm to use to normalize each sample.</param> /// <param name="subMean">Subtract mean from each value before normalizing.</param> public static Vector <float> LpNormalize(this Vector <float> input, LpNormalizingEstimatorBase.NormalizerKind normKind = LpNormalizingEstimatorBase.Defaults.NormKind, bool subMean = LpNormalizingEstimatorBase.Defaults.LpSubstractMean) => new OutPipelineColumn(input, normKind, subMean);
public Reconciler(LpNormalizingEstimatorBase.NormalizerKind normKind, bool subMean) { _normKind = normKind; _subMean = subMean; }
public OutPipelineColumn(Vector <float> input, LpNormalizingEstimatorBase.NormalizerKind normKind, bool subMean) : base(new Reconciler(normKind, subMean), input) { Input = input; }
/// <summary> /// Describes how the transformer handles one LpNorm column pair. /// </summary> /// <param name="input">Name of input column.</param> /// <param name="output">Name of output column.</param> /// <param name="substractMean">Subtract mean from each value before normalizing.</param> /// <param name="normalizerKind">The norm to use to normalize each sample.</param> public LpNormColumnInfo(string input, string output, bool substractMean = LpNormalizingEstimatorBase.Defaults.LpSubstractMean, LpNormalizingEstimatorBase.NormalizerKind normalizerKind = LpNormalizingEstimatorBase.Defaults.NormKind) : base(input, output, substractMean, normalizerKind, 1) { }
/// <summary> /// Takes column filled with a vector of floats and computes L-p norm of it. /// </summary> /// <param name="catalog">The transform's catalog.</param> /// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param> /// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param> /// <param name="normKind">Type of norm to use to normalize each sample.</param> /// <param name="subMean">Subtract mean from each value before normalizing.</param> /// <example> /// <format type="text/markdown"> /// <![CDATA[ /// [!code-csharp[LpNormalize](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/ProjectionTransforms.cs?range=1-6,12-112)] /// ]]> /// </format> /// </example> public static LpNormalizingEstimator LpNormalize(this TransformsCatalog.ProjectionTransforms catalog, string outputColumnName, string inputColumnName = null, LpNormalizingEstimatorBase.NormalizerKind normKind = LpNormalizingEstimatorBase.Defaults.NormKind, bool subMean = LpNormalizingEstimatorBase.Defaults.LpSubstractMean) => new LpNormalizingEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, inputColumnName, normKind, subMean);
/// <summary> /// Describes how the transformer handles one LpNorm column pair. /// </summary> /// <param name="name">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param> /// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="name"/> will be used as source.</param> /// <param name="substractMean">Subtract mean from each value before normalizing.</param> /// <param name="normalizerKind">The norm to use to normalize each sample.</param> public LpNormColumnInfo(string name, string inputColumnName = null, bool substractMean = LpNormalizingEstimatorBase.Defaults.LpSubstractMean, LpNormalizingEstimatorBase.NormalizerKind normalizerKind = LpNormalizingEstimatorBase.Defaults.NormKind) : base(name, inputColumnName ?? name, substractMean, normalizerKind, 1) { }