示例#1
0
        public ValueMapper <TIn, TOut, TDist> GetMapper <TIn, TOut, TDist>()
        {
            Host.Check(typeof(TIn) == typeof(VBuffer <Single>));
            Host.Check(typeof(TOut) == typeof(Single));
            Host.Check(typeof(TDist) == typeof(Single));

            var combine       = Combiner.GetCombiner();
            var combineProb   = _probabilityCombiner.GetCombiner();
            var maps          = GetMaps();
            var predictions   = new Single[_mappers.Length];
            var probabilities = new Single[_mappers.Length];
            var vBuffers      = new VBuffer <Single> [_mappers.Length];
            ValueMapper <VBuffer <Single>, Single, Single> del =
                (ref VBuffer <Single> src, ref Single score, ref Single prob) =>
            {
                if (InputType.VectorSize > 0)
                {
                    Host.Check(src.Length == InputType.VectorSize);
                }

                var tmp = src;
                Parallel.For(0, maps.Length, i =>
                {
                    var model = Models[i];
                    if (model.SelectedFeatures != null)
                    {
                        EnsembleUtils.SelectFeatures(ref tmp, model.SelectedFeatures, model.Cardinality, ref vBuffers[i]);
                        maps[i](ref vBuffers[i], ref predictions[i], ref probabilities[i]);
                    }
                    else
                    {
                        maps[i](ref tmp, ref predictions[i], ref probabilities[i]);
                    }
                });

                combine(ref score, predictions, _averagedWeights);
                combineProb(ref prob, probabilities, _averagedWeights);
            };

            return((ValueMapper <TIn, TOut, TDist>)(Delegate) del);
        }