예제 #1
0
                internal override Delegate CreateScoreGetter(DataViewRow input, out Action disposer)
                {
                    disposer = null;

                    var getters = new ValueGetter <T> [Mappers.Length];

                    for (int i = 0; i < Mappers.Length; i++)
                    {
                        // First get the output row from the pipelines. The input predicate of the predictor
                        // is the output predicate of the pipeline.
                        var mapperColumns = Mappers[i].OutputSchema.Where(col => col.Name == DefaultColumnNames.Score);
                        var inputColumns  = Mappers[i].GetDependenciesForNewColumns(mapperColumns);

                        var pipelineRow = BoundPipelines[i].GetRow(input, inputColumns);

                        // Next we get the output row from the predictors. We activate the score column as output predicate.
                        var predictorRow = Mappers[i].GetRow(pipelineRow, Enumerable.Repeat(Mappers[i].InputSchema[ScoreCols[i]], 1));
                        getters[i] = predictorRow.GetGetter <T>(predictorRow.Schema[ScoreCols[i]]);
                        disposer  += predictorRow.Dispose;
                    }

                    var             comb        = _combiner.GetCombiner();
                    var             buffer      = new T[Mappers.Length];
                    ValueGetter <T> scoreGetter =
                        (ref T dst) =>
                    {
                        for (int i = 0; i < Mappers.Length; i++)
                        {
                            getters[i](ref buffer[i]);
                        }
                        comb(ref dst, buffer, null);
                    };

                    return(scoreGetter);
                }
예제 #2
0
                public override Delegate CreateScoreGetter(IRow input, Func <int, bool> mapperPredicate, out Action disposer)
                {
                    disposer = null;

                    if (!mapperPredicate(0))
                    {
                        return(null);
                    }

                    var getters = new ValueGetter <T> [Mappers.Length];

                    for (int i = 0; i < Mappers.Length; i++)
                    {
                        // First get the output row from the pipelines. The input predicate of the predictor
                        // is the output predicate of the pipeline.
                        var inputPredicate = Mappers[i].GetDependencies(mapperPredicate);
                        var pipelineRow    = BoundPipelines[i].GetRow(input, inputPredicate, out Action disp);
                        disposer += disp;

                        // Next we get the output row from the predictors. We activate the score column as output predicate.
                        var predictorRow = Mappers[i].GetRow(pipelineRow, col => col == ScoreCols[i], out disp);
                        disposer  += disp;
                        getters[i] = predictorRow.GetGetter <T>(ScoreCols[i]);
                    }

                    var             comb        = _combiner.GetCombiner();
                    var             buffer      = new T[Mappers.Length];
                    ValueGetter <T> scoreGetter =
                        (ref T dst) =>
                    {
                        for (int i = 0; i < Mappers.Length; i++)
                        {
                            getters[i](ref buffer[i]);
                        }
                        comb(ref dst, buffer, null);
                    };

                    return(scoreGetter);
                }