Пример #1
0
        protected override Delegate GetPredictedLabelGetter(IRow output, out Delegate scoreGetter)
        {
            Contracts.AssertValue(output);
            Contracts.Assert(output.Schema == Bindings.RowMapper.Schema);
            Contracts.Assert(output.IsColumnActive(Bindings.ScoreColumnIndex));

            ValueGetter <VBuffer <Float> > mapperScoreGetter = output.GetGetter <VBuffer <Float> >(Bindings.ScoreColumnIndex);

            long            cachedPosition = -1;
            VBuffer <Float> score          = default(VBuffer <Float>);
            int             scoreLength    = Bindings.PredColType.KeyCount;

            ValueGetter <uint> predFn =
                (ref uint dst) =>
            {
                EnsureCachedPosition(ref cachedPosition, ref score, output, mapperScoreGetter);
                Contracts.Check(score.Length == scoreLength);
                int index = VectorUtils.ArgMin(ref score);
                if (index < 0)
                {
                    dst = 0;
                }
                else
                {
                    dst = (uint)index + 1;
                }
            };
            ValueGetter <VBuffer <Float> > scoreFn =
                (ref VBuffer <Float> dst) =>
            {
                EnsureCachedPosition(ref cachedPosition, ref score, output, mapperScoreGetter);
                Contracts.Check(score.Length == scoreLength);
                score.CopyTo(ref dst);
            };

            scoreGetter = scoreFn;
            return(predFn);
        }