private static Action <TermTransform.TermMap> Wrap <T>(ToKeyFitResult <T> .OnFit onFit) { if (onFit == null) { return(null); } // The type T asociated with the delegate will be the actual value type once #863 goes in. // However, until such time as #863 goes in, it would be too awkward to attempt to extract the metadata. // For now construct the useless object then pass it into the delegate. return(map => onFit(new ToKeyFitResult <T>(map))); }
/// <summary> /// Converts the categorical value into an indicator array by building a dictionary of categories based on the data and using the id in the dictionary as the index in the array. /// </summary> /// <param name="input">Incoming data.</param> /// <param name="outputKind">Specify the output type of indicator array: Multiarray, array or binary encoded data.</param> /// <param name="order">How the Id for each value would be assigined: by occurrence or by value.</param> /// <param name="maxItems">Maximum number of ids to keep during data scanning.</param> /// <param name="onFit">Called upon fitting with the learnt enumeration on the dataset.</param> public static Vector <float> OneHotEncoding(this Vector <string> input, OneHotVectorOutputKind outputKind = DefOut, KeyValueOrder order = DefSort, int maxItems = DefMax, ToKeyFitResult <ReadOnlyMemory <char> > .OnFit onFit = null) { Contracts.CheckValue(input, nameof(input)); return(new ImplVector <string>(input, new Config(outputKind, order, maxItems, Wrap(onFit)))); }