コード例 #1
0
        internal static OvaPredictor Create(IHost host, bool useProb, TScalarPredictor[] predictors)
        {
            ImplBase impl;

            using (var ch = host.Start("Creating OVA predictor"))
            {
                IValueMapperDist ivmd = null;
                if (useProb &&
                    ((ivmd = predictors[0] as IValueMapperDist) == null ||
                     ivmd.OutputType != NumberType.Float ||
                     ivmd.DistType != NumberType.Float))
                {
                    ch.Warning($"{nameof(Ova.Arguments.UseProbabilities)} specified with {nameof(Ova.Arguments.PredictorType)} that can't produce probabilities.");
                    ivmd = null;
                }

                if (ivmd != null)
                {
                    var dists = new IValueMapperDist[predictors.Length];
                    for (int i = 0; i < predictors.Length; ++i)
                    {
                        dists[i] = (IValueMapperDist)predictors[i];
                    }
                    impl = new ImplDist(dists);
                }
                else
                {
                    impl = new ImplRaw(predictors);
                }
            }

            return(new OvaPredictor(host, impl));
        }
コード例 #2
0
        internal static OptimizedOVAPredictor Create(IHost host, bool useProb, TScalarPredictor[] predictors)
        {
            ImplBase impl;

            using (var ch = host.Start("Creating OVA predictor"))
            {
                IValueMapperDist ivmd = null;
                if (useProb &&
                    ((ivmd = predictors[0] as IValueMapperDist) == null ||
                     ivmd.OutputType != NumberDataViewType.Single ||
                     ivmd.DistType != NumberDataViewType.Single))
                {
                    ch.Warning("useProbabilities specified with basePredictor that can't produce probabilities.");
                    ivmd = null;
                }

                if (ivmd != null)
                {
                    var dists = new IValueMapperDist[predictors.Length];
                    for (int i = 0; i < predictors.Length; ++i)
                    {
                        dists[i] = (IValueMapperDist)predictors[i];
                    }
                    impl = new ImplDist(dists);
                }
                else
                {
                    impl = new ImplRaw(predictors);
                }
            }

            return(new OptimizedOVAPredictor(host, impl));
        }
コード例 #3
0
        internal static MultiToRankerPredictor Create <TLabel>(IHost host, VBuffer <TLabel> classes,
                                                               TScalarPredictor[] predictors, IPredictor reclassPredictor, bool singleColumn, bool labelKey)
        {
            IImplBase impl;

            using (var ch = host.Start("Creating MultiToRanker predictor"))
                impl = new ImplRaw <TLabel>(classes, predictors, reclassPredictor, singleColumn, labelKey);
            return(new MultiToRankerPredictor(host, impl));
        }
コード例 #4
0
        internal static OneVersusAllModelParameters Create(IHost host, OutputFormula outputFormula, TScalarPredictor[] predictors)
        {
            ImplBase impl;

            using (var ch = host.Start("Creating OVA predictor"))
            {
                if (outputFormula == OutputFormula.Softmax)
                {
                    impl = new ImplSoftmax(predictors);
                    return(new OneVersusAllModelParameters(host, impl));
                }

                // Caller of this function asks for probability output. We check if input predictor can produce probability.
                // If that predictor can't produce probability, ivmd will be null.
                IValueMapperDist ivmd = null;
                if (outputFormula == OutputFormula.ProbabilityNormalization &&
                    ((ivmd = predictors[0] as IValueMapperDist) == null ||
                     ivmd.OutputType != NumberDataViewType.Single ||
                     ivmd.DistType != NumberDataViewType.Single))
                {
                    ch.Warning($"{nameof(OneVersusAllTrainer.Options.UseProbabilities)} specified with {nameof(OneVersusAllTrainer.Options.PredictorType)} that can't produce probabilities.");
                    ivmd = null;
                }

                // If ivmd is null, either the user didn't ask for probability or the provided predictors can't produce probability.
                if (ivmd != null)
                {
                    var dists = new IValueMapperDist[predictors.Length];
                    for (int i = 0; i < predictors.Length; ++i)
                    {
                        dists[i] = (IValueMapperDist)predictors[i];
                    }
                    impl = new ImplDist(dists);
                }
                else
                {
                    impl = new ImplRaw(predictors);
                }
            }

            return(new OneVersusAllModelParameters(host, impl));
        }