コード例 #1
0
        protected override IRowMapper CreatePerInstanceRowMapper(RoleMappedSchema schema)
        {
            var scoreInfo   = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            int numClusters = scoreInfo.Type.VectorSize;

            return(new ClusteringPerInstanceEvaluator(Host, schema.Schema, scoreInfo.Name, numClusters));
        }
コード例 #2
0
        private protected override IRowMapper CreatePerInstanceRowMapper(RoleMappedSchema schema)
        {
            Contracts.CheckParam(schema.Label.HasValue, nameof(schema), "Could not find the label column");
            var scoreInfo = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

            return(new RegressionPerInstanceEvaluator(Host, schema.Schema, scoreInfo.Name, schema.Label.Value.Name));
        }
コード例 #3
0
            public override void InitializeNextPass(IRow row, RoleMappedSchema schema)
            {
                Contracts.Assert(PassNum < 1);
                Contracts.AssertValue(schema.Label);
                Contracts.AssertValue(schema.Group);

                var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

                _labelGetter = RowCursorUtils.GetLabelGetter(row, schema.Label.Index);
                _scoreGetter = row.GetGetter <Single>(score.Index);
                _newGroupDel = RowCursorUtils.GetIsNewGroupDelegate(row, schema.Group.Index);
                if (schema.Weight != null)
                {
                    _weightGetter = row.GetGetter <Single>(schema.Weight.Index);
                }

                if (UnweightedCounters.GroupSummary)
                {
                    ValueGetter <StringBuilder> groupIdBuilder = RowCursorUtils.GetGetterAsStringBuilder(row, schema.Group.Index);
                    _groupSbUpdate = () => groupIdBuilder(ref _groupSb);
                }
                else
                {
                    _groupSbUpdate = () => { }
                };
            }
コード例 #4
0
        protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
        {
            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

            Host.Assert(score.Type.VectorSize > 0);
            return(new Aggregator(Host, LossFunction, score.Type.VectorSize, schema.Weight != null, stratName));
        }
コード例 #5
0
            public override void InitializeNextPass(Row row, RoleMappedSchema schema)
            {
                Host.Assert(!_streaming && PassNum < 2 || PassNum < 1);
                Host.AssertValue(schema.Label);

                var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

                _labelGetter = RowCursorUtils.GetLabelGetter(row, schema.Label.Index);
                _scoreGetter = row.GetGetter <float>(score.Index);
                Host.AssertValue(_labelGetter);
                Host.AssertValue(_scoreGetter);

                if (IsMainPass())
                {
                    Host.Assert(_topExamples.Count == 0);
                    if (_nameIndex < 0)
                    {
                        int rowCounter = 0;
                        _nameGetter = (ref ReadOnlyMemory <char> dst) => dst = (rowCounter++).ToString().AsMemory();
                    }
                    else
                    {
                        _nameGetter = row.GetGetter <ReadOnlyMemory <char> >(_nameIndex);
                    }
                }
            }
コード例 #6
0
        /// <summary>
        /// Used in the Evaluate() method, to get the predicate for cursoring over the data.
        /// The base class implementation activates the score column, the label column if it exists, the weight column if it exists
        /// and the stratification columns.
        /// Override if other input columns need to be activated.
        /// </summary>
        protected virtual Func <int, bool> GetActiveColsCore(RoleMappedSchema schema)
        {
            var score  = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            var label  = schema.Label == null ? -1 : schema.Label.Index;
            var weight = schema.Weight == null ? -1 : schema.Weight.Index;

            return(i => i == score.Index || i == label || i == weight);
        }
コード例 #7
0
        private protected virtual Func <int, bool> GetActiveColsCore(RoleMappedSchema schema)
        {
            var score  = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            int label  = schema.Label?.Index ?? -1;
            int weight = schema.Weight?.Index ?? -1;

            return(i => i == score.Index || i == label || i == weight);
        }
コード例 #8
0
        protected override IRowMapper CreatePerInstanceRowMapper(RoleMappedSchema schema)
        {
            Host.CheckParam(schema.Label != null, nameof(schema), "Could not find the label column");
            var scoreInfo = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

            Host.AssertValue(scoreInfo);

            return(new MultiOutputRegressionPerInstanceEvaluator(Host, schema.Schema, scoreInfo.Name, schema.Label.Name));
        }
コード例 #9
0
        protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
        {
            Host.AssertValue(schema);
            Host.Assert(!_calculateDbi || (schema.Feature != null && schema.Feature.Type.IsKnownSizeVector));
            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

            Host.Assert(score.Type.VectorSize > 0);
            int numClusters = score.Type.VectorSize;

            return(new Aggregator(Host, schema.Feature, numClusters, _calculateDbi, schema.Weight != null, stratName));
        }
コード例 #10
0
        protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
        {
            var scoreInfo = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            var t         = scoreInfo.Type;

            Host.Assert(t.VectorSize > 0 && (t.ItemType == NumberType.R4 || t.ItemType == NumberType.R8));
            var slotNames = default(VBuffer <ReadOnlyMemory <char> >);

            t = schema.Schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.SlotNames, scoreInfo.Index);
            if (t != null && t.VectorSize == scoreInfo.Type.VectorSize && t.ItemType.IsText)
            {
                schema.Schema.GetMetadata(MetadataUtils.Kinds.SlotNames, scoreInfo.Index, ref slotNames);
            }
            return(new Aggregator(Host, LossFunction, schema.Weight != null, scoreInfo.Type.VectorSize, in slotNames, stratName));
        }
コード例 #11
0
        protected override IRowMapper CreatePerInstanceRowMapper(RoleMappedSchema schema)
        {
            Host.CheckParam(schema.Label != null, nameof(schema), "Schema must contain a label column");
            var scoreInfo = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            int scoreSize = scoreInfo.Type.VectorSize;
            var type      = schema.Schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.SlotNames, scoreInfo.Index);

            Host.Check(type != null && type.IsKnownSizeVector && type.ItemType.IsText, "Quantile regression score column must have slot names");
            var quantiles = default(VBuffer <ReadOnlyMemory <char> >);

            schema.Schema.GetMetadata(MetadataUtils.Kinds.SlotNames, scoreInfo.Index, ref quantiles);
            Host.Assert(quantiles.IsDense && quantiles.Length == scoreSize);

            return(new QuantileRegressionPerInstanceEvaluator(Host, schema.Schema, scoreInfo.Name, schema.Label.Name, scoreSize, quantiles.Values));
        }
コード例 #12
0
        private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            var t     = score.Type;

            if (t.VectorSize == 0 || t.ItemType != NumberType.Float)
            {
                throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known size vector of R4", t.ToString());
            }
            Host.Check(schema.Label.HasValue, "Could not find the label column");
            t = schema.Label.Value.Type;
            if (!t.IsKnownSizeVector || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
            {
                throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "known size vector of R4 or R8", t.ToString());
            }
        }
コード例 #13
0
        protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            var t     = score.Type;

            if (t != NumberType.Float)
            {
                throw Host.Except("Score column '{0}' has type '{1}' but must be R4", score, t).MarkSensitive(MessageSensitivity.Schema);
            }
            Host.Check(schema.Label != null, "Could not find the label column");
            t = schema.Label.Type;
            if (t != NumberType.Float && t.KeyCount != 2)
            {
                throw Host.Except("Label column '{0}' has type '{1}' but must be R4 or a 2-value key", schema.Label.Name, t).MarkSensitive(MessageSensitivity.Schema);
            }
        }
コード例 #14
0
        protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            var t     = score.Type;

            if (t.VectorSize == 0 || t.ItemType != NumberType.Float)
            {
                throw Host.Except("Score column '{0}' has type '{1}' but must be a known length vector of type R4", score.Name, t);
            }
            Host.Check(schema.Label != null, "Could not find the label column");
            t = schema.Label.Type;
            if (!t.IsKnownSizeVector || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
            {
                throw Host.Except("Label column '{0}' has type '{1}' but must be a known-size vector of R4 or R8", schema.Label.Name, t);
            }
        }
コード例 #15
0
        private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            var t     = score.Type;

            if (t != NumberType.Float)
            {
                throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "R4", t.ToString());
            }
            Host.CheckParam(schema.Label.HasValue, nameof(schema), "Could not find the label column");
            t = schema.Label.Value.Type;
            if (t != NumberType.R4)
            {
                throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "R4", t.ToString());
            }
        }
コード例 #16
0
        private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            var t     = score.Type;

            if (t.VectorSize == 0 || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
            {
                throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of type R4 or R8", t.ToString());
            }
            Host.CheckParam(schema.Label.HasValue, nameof(schema), "Must contain a label column");
            t = schema.Label.Value.Type;
            if (t != NumberType.R4)
            {
                throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "R4", t.ToString());
            }
        }
コード例 #17
0
        protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
            var t     = score.Type;

            if (t.IsVector || t.ItemType != NumberType.Float)
            {
                throw Host.Except("Score column '{0}' has type '{1}' but must be R4", score, t);
            }
            Host.Check(schema.Label != null, "Could not find the label column");
            t = schema.Label.Type;
            if (t != NumberType.R4)
            {
                throw Host.Except("Label column '{0}' has type '{1}' but must be R4", schema.Label.Name, t);
            }
        }
コード例 #18
0
        private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            var t = schema.Label.Value.Type;

            if (t != NumberType.Float && !(t is KeyType))
            {
                throw Host.ExceptSchemaMismatch(nameof(RankerMamlEvaluator.Arguments.LabelColumn),
                                                "label", schema.Label.Value.Name, "R4 or a key", t.ToString());
            }
            var scoreCol = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

            if (scoreCol.Type != NumberType.Float)
            {
                throw Host.ExceptSchemaMismatch(nameof(RankerMamlEvaluator.Arguments.ScoreColumn),
                                                "score", scoreCol.Name, "R4", t.ToString());
            }
        }
コード例 #19
0
            public override void InitializeNextPass(IRow row, RoleMappedSchema schema)
            {
                Contracts.Assert(PassNum < 1);
                Contracts.AssertValue(schema.Label);

                var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

                _labelGetter = RowCursorUtils.GetVecGetterAs <Float>(NumberType.Float, row, schema.Label.Index);
                _scoreGetter = row.GetGetter <VBuffer <Float> >(score.Index);
                Contracts.AssertValue(_labelGetter);
                Contracts.AssertValue(_scoreGetter);

                if (schema.Weight != null)
                {
                    _weightGetter = row.GetGetter <Float>(schema.Weight.Index);
                }
            }
コード例 #20
0
        protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            var t = schema.Label.Type;

            if (t != NumberType.Float && !t.IsKey)
            {
                throw Host.ExceptUserArg(nameof(RankerMamlEvaluator.Arguments.LabelColumn), "Label column '{0}' has type '{1}' but must be R4 or a key",
                                         schema.Label.Name, t);
            }
            var scoreInfo = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

            if (scoreInfo.Type != NumberType.Float)
            {
                throw Host.ExceptUserArg(nameof(RankerMamlEvaluator.Arguments.ScoreColumn), "Score column '{0}' has type '{1}' but must be R4",
                                         scoreInfo.Name, t);
            }
        }
コード例 #21
0
        private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            ColumnType type = schema.Label?.Type;

            if (type != null && type != NumberType.Float && !(type is KeyType keyType && keyType.Count > 0))
            {
                throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name,
                                                "R4 or key of known cardinality", type.ToString());
            }

            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

            type = score.Type;
            if (!type.IsKnownSizeVector || type.ItemType != NumberType.Float)
            {
                throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "R4 vector of known size", type.ToString());
            }
        }
コード例 #22
0
            public override void InitializeNextPass(IRow row, RoleMappedSchema schema)
            {
                AssertValid(assertGetters: false);

                Host.AssertValue(row);
                Host.AssertValue(schema);

                if (_calculateDbi)
                {
                    Host.AssertValue(schema.Feature);
                    _featGetter = row.GetGetter <VBuffer <Single> >(schema.Feature.Index);
                }
                var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

                Host.Assert(score.Type.VectorSize == _scoresArr.Length);
                _scoreGetter = row.GetGetter <VBuffer <Single> >(score.Index);

                if (PassNum == 0)
                {
                    if (schema.Label != null)
                    {
                        _labelGetter = RowCursorUtils.GetLabelGetter(row, schema.Label.Index);
                    }
                    else
                    {
                        _labelGetter = (ref Single value) => value = Single.NaN;
                    }
                    if (schema.Weight != null)
                    {
                        _weightGetter = row.GetGetter <Single>(schema.Weight.Index);
                    }
                }
                else
                {
                    Host.Assert(PassNum == 1 && _calculateDbi);
                    UnweightedCounters.InitializeSecondPass(_clusterCentroids);
                    if (WeightedCounters != null)
                    {
                        WeightedCounters.InitializeSecondPass(_clusterCentroids);
                    }
                }
                AssertValid(assertGetters: true);
            }
コード例 #23
0
        protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
        {
            ColumnType type;

            if (schema.Label != null && (type = schema.Label.Type) != NumberType.Float && type.KeyCount == 0)
            {
                throw Host.Except("Clustering evaluator: label column '{0}' type must be {1} or Key of known cardinality." +
                                  " Provide a correct label column, or none: it is optional.",
                                  schema.Label.Name, NumberType.Float);
            }

            var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);

            type = score.Type;
            if (!type.IsKnownSizeVector || type.ItemType != NumberType.Float)
            {
                throw Host.Except("Scores column '{0}' type must be a float vector of known size", score.Name);
            }
        }