private BindingsImpl(DataViewSchema input, ISchemaBoundRowMapper mapper, string suffix, string scoreColumnKind, bool user, int scoreColIndex, DataViewType predColType, string predictedLabelColumnName = DefaultColumnNames.PredictedLabel) : base(input, mapper, suffix, user, predictedLabelColumnName) { Contracts.AssertNonEmpty(scoreColumnKind); Contracts.Assert(DerivedColumnCount == 1); ScoreColumnIndex = scoreColIndex; ScoreColumnKind = scoreColumnKind; PredColType = predColType; _getScoreColumnKind = GetScoreColumnKind; _getScoreValueKind = GetScoreValueKind; // REVIEW: This logic is very specific to multiclass, which is deeply // regrettable, but the class structure as designed and the status of this schema // bearing object makes pushing the logic into the multiclass scorer almost impossible. if (predColType is KeyDataViewType predColKeyType && predColKeyType.Count > 0) { var scoreColMetadata = mapper.OutputSchema[scoreColIndex].Annotations; var trainLabelColumn = scoreColMetadata.Schema.GetColumnOrNull(AnnotationUtils.Kinds.TrainingLabelValues); if (trainLabelColumn?.Type is VectorDataViewType trainLabelColVecType && (ulong)trainLabelColVecType.Size == predColKeyType.Count) { Contracts.Assert(trainLabelColVecType.Size > 0); _predColMetadata = Utils.MarshalInvoke(_keyValueMetadataFromMetadataMethodInfo, trainLabelColVecType.RawType, scoreColMetadata, trainLabelColumn.Value); } } }
private static AnnotationInfo GetAnnotationInfo <T>(string kind, DataViewSchema.Annotations annotations) { T value = default; annotations.GetValue(kind, ref value); return(new AnnotationInfo <T>(kind, value, annotations.Schema[kind].Type)); }
internal static DataViewRow AnnotationsAsRow(DataViewSchema.Annotations annotations) { Contracts.CheckValue(annotations, nameof(annotations)); return(new AnnotationRow(annotations)); }
public AnnotationRow(DataViewSchema.Annotations annotations) { Contracts.AssertValue(annotations); _annotations = annotations; }
private static DataViewSchema.Annotations KeyValueMetadataFromMetadata <T>(DataViewSchema.Annotations meta, DataViewSchema.Column metaCol) { Contracts.AssertValue(meta); Contracts.Assert(metaCol.Type.RawType == typeof(T)); var builder = new DataViewSchema.Annotations.Builder(); builder.Add(AnnotationUtils.Kinds.KeyValues, metaCol.Type, meta.GetGetter <T>(metaCol)); return(builder.ToAnnotations()); }