コード例 #1
0
        /// <summary>
        /// Safely retrieves the number of classes that the Bayes point machine classifier is used for.
        /// </summary>
        /// <typeparam name="TInstanceSource">The type of the instance source.</typeparam>
        /// <typeparam name="TInstance">The type of an instance.</typeparam>
        /// <typeparam name="TLabelSource">The type of the label source.</typeparam>
        /// <typeparam name="TLabel">The type of a label.</typeparam>
        /// <param name="mapping">The mapping.</param>
        /// <param name="instanceSource">An optional instance source.</param>
        /// <param name="labelSource">An optional label source.</param>
        /// <returns>The number of classes that the Bayes point machine classifier is used for.</returns>
        /// <exception cref="MappingException">Thrown if there are less than three classes.</exception>
        public static int GetClassCountSafe <TInstanceSource, TInstance, TLabelSource, TLabel>(
            this IBayesPointMachineClassifierMapping <TInstanceSource, TInstance, TLabelSource, TLabel> mapping,
            TInstanceSource instanceSource = default(TInstanceSource),
            TLabelSource labelSource       = default(TLabelSource))
        {
            int classCount = mapping.GetClassCount(instanceSource, labelSource);

            if (classCount < 2)
            {
                throw new MappingException("There must be at least two classes.");
            }

            return(classCount);
        }