private protected override IRowMapper CreatePerInstanceRowMapper(RoleMappedSchema schema) { Host.CheckParam(schema.Label.HasValue, nameof(schema), "Could not find the label column"); var scoreCol = schema.GetUniqueColumn(AnnotationUtils.Const.ScoreValueKind.Score); return(new MultiOutputRegressionPerInstanceEvaluator(Host, schema.Schema, scoreCol.Name, schema.Label.Value.Name)); }
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)); }
private protected override IRowMapper CreatePerInstanceRowMapper(RoleMappedSchema schema) { var scoreInfo = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score); int numClusters = scoreInfo.Type.GetVectorSize(); return(new ClusteringPerInstanceEvaluator(Host, schema.Schema, scoreInfo.Name, numClusters)); }
private 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)); }
internal override void InitializeNextPass(Row row, RoleMappedSchema schema) { Host.Assert(!_streaming && PassNum < 2 || PassNum < 1); Host.Assert(schema.Label.HasValue); var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score); _labelGetter = RowCursorUtils.GetLabelGetter(row, schema.Label.Value.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); } } }
internal override void InitializeNextPass(DataViewRow row, RoleMappedSchema schema) { Contracts.Assert(PassNum < 1); Contracts.Assert(schema.Label.HasValue); Contracts.Assert(schema.Group.HasValue); var score = schema.GetUniqueColumn(AnnotationUtils.Const.ScoreValueKind.Score); _labelGetter = RowCursorUtils.GetLabelGetter(row, schema.Label.Value.Index); _scoreGetter = row.GetGetter <Single>(score); _newGroupDel = RowCursorUtils.GetIsNewGroupDelegate(row, schema.Group.Value.Index); if (schema.Weight.HasValue) { _weightGetter = row.GetGetter <Single>(schema.Weight.Value); } if (UnweightedCounters.GroupSummary) { ValueGetter <StringBuilder> groupIdBuilder = RowCursorUtils.GetGetterAsStringBuilder(row, schema.Group.Value.Index); _groupSbUpdate = () => groupIdBuilder(ref _groupSb); } else { _groupSbUpdate = () => { } }; }
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); }
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName) { Host.AssertValue(schema); Host.Assert(!_calculateDbi || schema.Feature?.Type.IsKnownSizeVector == true); 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)); }
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName) { var scoreInfo = schema.GetUniqueColumn(AnnotationUtils.Const.ScoreValueKind.Score); var scoreType = scoreInfo.Type as VectorDataViewType; Host.Assert(scoreType != null && scoreType.Size > 0 && (scoreType.ItemType == NumberDataViewType.Single || scoreType.ItemType == NumberDataViewType.Double)); var slotNames = default(VBuffer <ReadOnlyMemory <char> >); var slotNamesType = schema.Schema[scoreInfo.Index].Annotations.Schema.GetColumnOrNull(AnnotationUtils.Kinds.SlotNames)?.Type as VectorDataViewType; if (slotNamesType != null && slotNamesType.Size == scoreType.Size && slotNamesType.ItemType is TextDataViewType) { schema.Schema[scoreInfo.Index].GetSlotNames(ref slotNames); } return(new Aggregator(Host, LossFunction, schema.Weight != null, scoreType.Size, in slotNames, stratName)); }
private 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[scoreInfo.Index].Metadata.Schema.GetColumnOrNull(MetadataUtils.Kinds.SlotNames)?.Type; if (t != null && t.VectorSize == scoreInfo.Type.VectorSize && t.ItemType.IsText) { schema.Schema[scoreInfo.Index].GetSlotNames(ref slotNames); } return(new Aggregator(Host, LossFunction, schema.Weight != null, scoreInfo.Type.VectorSize, in slotNames, stratName)); }
private protected override IRowMapper CreatePerInstanceRowMapper(RoleMappedSchema schema) { Host.CheckParam(schema.Label.HasValue, nameof(schema), "Must contain a label column"); var scoreInfo = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score); int scoreSize = scoreInfo.Type.VectorSize; var type = schema.Schema[scoreInfo.Index].Metadata.Schema.GetColumnOrNull(MetadataUtils.Kinds.SlotNames)?.Type; 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[scoreInfo.Index].Metadata.GetValue(MetadataUtils.Kinds.SlotNames, ref quantiles); Host.Assert(quantiles.IsDense && quantiles.Length == scoreSize); return(new QuantileRegressionPerInstanceEvaluator(Host, schema.Schema, scoreInfo.Name, schema.Label.Value.Name, scoreSize, quantiles)); }
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.Except("Score column '{0}' has type '{1}' but must be R4", score, t).MarkSensitive(MessageSensitivity.Schema); } Host.Check(schema.Label.HasValue, "Could not find the label column"); t = schema.Label.Value.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.Value.Name, t).MarkSensitive(MessageSensitivity.Schema); } }
private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema) { var score = schema.GetUniqueColumn(AnnotationUtils.Const.ScoreValueKind.Score); var t = score.Type; if (t != NumberDataViewType.Single) { throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "float", t.ToString()); } Host.Check(schema.Label.HasValue, "Could not find the label column"); t = schema.Label.Value.Type; if (t != NumberDataViewType.Single && t.GetKeyCount() != 2) { throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or a KeyType with cardinality 2", t.ToString()); } }
private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema) { var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score); var t = score.Type as VectorType; if (t == null || !t.IsKnownSize || t.ItemType != NumberType.Float) { throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known-size vector of float", t.ToString()); } Host.Check(schema.Label.HasValue, "Could not find the label column"); t = schema.Label.Value.Type as VectorType; if (t == null || !t.IsKnownSize || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8)) { throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "known-size vector of float or double", t.ToString()); } }
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()); } }
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, "float", 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, "float", t.ToString()); } }
internal override void InitializeNextPass(Row row, RoleMappedSchema schema) { Contracts.Assert(PassNum < 1); Contracts.Assert(schema.Label.HasValue); var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score); _labelGetter = RowCursorUtils.GetVecGetterAs <Float>(NumberType.Float, row, schema.Label.Value.Index); _scoreGetter = row.GetGetter <VBuffer <Float> >(score.Index); Contracts.AssertValue(_labelGetter); Contracts.AssertValue(_scoreGetter); if (schema.Weight.HasValue) { _weightGetter = row.GetGetter <Float>(schema.Weight.Value.Index); } }
private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema) { var t = schema.Label.Value.Type; if (t != NumberDataViewType.Single && !(t is KeyDataViewType)) { throw Host.ExceptSchemaMismatch(nameof(RankingMamlEvaluator.Arguments.LabelColumn), "label", schema.Label.Value.Name, "Single or a Key", t.ToString()); } var scoreCol = schema.GetUniqueColumn(AnnotationUtils.Const.ScoreValueKind.Score); if (scoreCol.Type != NumberDataViewType.Single) { throw Host.ExceptSchemaMismatch(nameof(RankingMamlEvaluator.Arguments.ScoreColumn), "score", scoreCol.Name, "Single", t.ToString()); } }
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()); } }
private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema) { var score = schema.GetUniqueColumn(AnnotationUtils.Const.ScoreValueKind.Score); var t = score.Type as VectorDataViewType; if (t == null || t.Size == 0 || (t.ItemType != NumberDataViewType.Single && t.ItemType != NumberDataViewType.Double)) { throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "Vector of Single or Double", t.ToString()); } Host.CheckParam(schema.Label.HasValue, nameof(schema), "Must contain a label column"); var labelType = schema.Label.Value.Type; if (labelType != NumberDataViewType.Single) { throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "Single", t.ToString()); } }
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, "float or KeyType", type.ToString()); } var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score); type = score.Type; if (!(type is VectorType vectorType) || !vectorType.IsKnownSize || vectorType.ItemType != NumberType.Float) { throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known-size vector of float", type.ToString()); } }