DataViewRow ISchemaBoundRowMapper.GetRow(DataViewRow input, IEnumerable <DataViewSchema.Column> activeColumns)
        {
            var latentSum          = new AlignedArray(_pred.FieldCount * _pred.FieldCount * _pred.LatentDimAligned, 16);
            var featureBuffer      = new VBuffer <float>();
            var featureFieldBuffer = new int[_pred.FeatureCount];
            var featureIndexBuffer = new int[_pred.FeatureCount];
            var featureValueBuffer = new float[_pred.FeatureCount];
            var inputGetters       = new ValueGetter <VBuffer <float> > [_pred.FieldCount];

            var activeIndices = activeColumns.Select(c => c.Index).ToArray();
            var active0       = activeIndices.Contains(0);
            var active1       = activeIndices.Contains(1);

            if (active0 || active1)
            {
                for (int f = 0; f < _pred.FieldCount; f++)
                {
                    inputGetters[f] = input.GetGetter <VBuffer <float> >(input.Schema[_inputColumnIndexes[f]]);
                }
            }

            var getters = new Delegate[2];

            if (active0)
            {
                ValueGetter <float> responseGetter = (ref float value) =>
                {
                    value = _pred.CalculateResponse(inputGetters, featureBuffer, featureFieldBuffer, featureIndexBuffer, featureValueBuffer, latentSum);
                };
                getters[0] = responseGetter;
            }
            if (active1)
            {
                ValueGetter <float> probGetter = (ref float value) =>
                {
                    value = _pred.CalculateResponse(inputGetters, featureBuffer, featureFieldBuffer, featureIndexBuffer, featureValueBuffer, latentSum);
                    value = MathUtils.SigmoidSlow(value);
                };
                getters[1] = probGetter;
            }

            return(new SimpleRow(OutputSchema, input, getters));
        }
Exemple #2
0
        public DataViewRow GetRow(DataViewRow input, Func <int, bool> predicate)
        {
            var latentSum          = new AlignedArray(_pred.FieldCount * _pred.FieldCount * _pred.LatentDimAligned, 16);
            var featureBuffer      = new VBuffer <float>();
            var featureFieldBuffer = new int[_pred.FeatureCount];
            var featureIndexBuffer = new int[_pred.FeatureCount];
            var featureValueBuffer = new float[_pred.FeatureCount];
            var inputGetters       = new ValueGetter <VBuffer <float> > [_pred.FieldCount];

            if (predicate(0) || predicate(1))
            {
                for (int f = 0; f < _pred.FieldCount; f++)
                {
                    inputGetters[f] = input.GetGetter <VBuffer <float> >(_inputColumnIndexes[f]);
                }
            }

            var getters = new Delegate[2];

            if (predicate(0))
            {
                ValueGetter <float> responseGetter = (ref float value) =>
                {
                    value = _pred.CalculateResponse(inputGetters, featureBuffer, featureFieldBuffer, featureIndexBuffer, featureValueBuffer, latentSum);
                };
                getters[0] = responseGetter;
            }
            if (predicate(1))
            {
                ValueGetter <float> probGetter = (ref float value) =>
                {
                    value = _pred.CalculateResponse(inputGetters, featureBuffer, featureFieldBuffer, featureIndexBuffer, featureValueBuffer, latentSum);
                    value = MathUtils.SigmoidSlow(value);
                };
                getters[1] = probGetter;
            }

            return(new SimpleRow(OutputSchema, input, getters));
        }