protected override ISchemaBoundMapper BindCore(IChannel ch, RoleMappedSchema schema) { var outputSchema = Schema.Create(new ScoreMapperSchema(ScoreType, _scoreColumnKind)); return(new SingleValueRowMapper(schema, this, outputSchema)); }
protected override ISchemaBoundMapper BindCore(IChannel ch, RoleMappedSchema schema) { return(new SingleValueRowMapper(schema, this, Schema.Create(new SchemaImpl(ScoreType, _quantiles)))); }
public FeatureContributionSchema(IExceptionContext ectx, string columnName, ColumnType columnType, Schema parentSchema, int featureCol) { Contracts.CheckValueOrNull(ectx); Contracts.CheckValue(parentSchema, nameof(parentSchema)); _ectx = ectx; _ectx.CheckNonEmpty(columnName, nameof(columnName)); _parentSchema = parentSchema; _featureCol = featureCol; _featureVectorSize = _parentSchema.GetColumnType(_featureCol).VectorSize; _hasSlotNames = _parentSchema.HasSlotNames(_featureCol, _featureVectorSize); _names = new string[] { columnName }; _types = new ColumnType[] { columnType }; _columnNameMap = new Dictionary <string, int>() { { columnName, 0 } }; }
public SingleValueRowMapper(RoleMappedSchema schema, SchemaBindablePredictorWrapperBase parent, Schema outputSchema) { Contracts.AssertValue(schema); Contracts.AssertValue(parent); Contracts.AssertValue(schema.Feature); Contracts.Assert(outputSchema.ColumnCount == 1); _parent = parent; InputRoleMappedSchema = schema; OutputSchema = outputSchema; }
public static MultiOutputRegressionPerInstanceEvaluator Create(IHostEnvironment env, ModelLoadContext ctx, Schema schema) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(ctx, nameof(ctx)); ctx.CheckAtModel(GetVersionInfo()); return(new MultiOutputRegressionPerInstanceEvaluator(env, ctx, schema)); }
/// <summary> /// Return whether the given column index is hidden in the given schema. /// </summary> public static bool IsHidden(this Schema schema, int col) => schema[col].IsHidden;
public MultiOutputRegressionPerInstanceEvaluator(IHostEnvironment env, Schema schema, string scoreCol, string labelCol) : base(env, schema, scoreCol, labelCol) { CheckInputColumnTypes(schema, out _labelType, out _scoreType, out _labelMetadata, out _scoreMetadata); }
private MultiOutputRegressionPerInstanceEvaluator(IHostEnvironment env, ModelLoadContext ctx, Schema schema) : base(env, ctx, schema) { CheckInputColumnTypes(schema, out _labelType, out _scoreType, out _labelMetadata, out _scoreMetadata); // *** Binary format ** // base }
/// <summary> /// Create a new instance of <see cref="ColumnBindings"/>. /// </summary> /// <param name="input">The input schema that we're adding columns to.</param> /// <param name="addedColumns">The columns being added.</param> public ColumnBindings(Schema input, Schema.Column[] addedColumns) { Contracts.CheckValue(input, nameof(input)); Contracts.CheckValue(addedColumns, nameof(addedColumns)); InputSchema = input; // Construct the indices. var indices = new List <int>(); var namesUsed = new HashSet <string>(); for (int i = 0; i < input.ColumnCount; i++) { namesUsed.Add(input[i].Name); indices.Add(i); } for (int i = 0; i < addedColumns.Length; i++) { string name = addedColumns[i].Name; if (namesUsed.Add(name)) { // New name. Append to the end. indices.Add(~i); } else { // Old name. Find last instance and add after it. for (int j = indices.Count - 1; j >= 0; j--) { var colName = indices[j] >= 0 ? input[indices[j]].Name : addedColumns[~indices[j]].Name; if (colName == name) { indices.Insert(j + 1, ~i); break; } } } } Contracts.Assert(indices.Count == addedColumns.Length + input.ColumnCount); // Create the output schema. var schemaColumns = indices.Select(idx => idx >= 0 ? input[idx] : addedColumns[~idx]); Schema = new Schema(schemaColumns); // Memorize column maps. _colMap = indices.ToArray(); var addedIndices = new int[addedColumns.Length]; for (int i = 0; i < _colMap.Length; i++) { int colIndex = _colMap[i]; if (colIndex < 0) { Contracts.Assert(addedIndices[~colIndex] == 0); addedIndices[~colIndex] = i; } } AddedColumnIndices = addedIndices.AsReadOnly(); }
/// <summary> /// Create the bindings given the env, bindable, input schema, column roles, and column name suffix. /// </summary> private static Bindings Create(IHostEnvironment env, ISchemaBindableMapper bindable, Schema input, IEnumerable <KeyValuePair <RoleMappedSchema.ColumnRole, string> > roles, string suffix, bool user = true) { Contracts.AssertValue(env); Contracts.AssertValue(bindable); Contracts.AssertValue(input); Contracts.AssertValue(roles); Contracts.AssertValueOrNull(suffix); var mapper = bindable.Bind(env, new RoleMappedSchema(input, roles)); // We don't actually depend on this invariant, but if this assert fires it means the bindable // did the wrong thing. Contracts.Assert(mapper.InputRoleMappedSchema.Schema == input); var rowMapper = mapper as ISchemaBoundRowMapper; Contracts.Check(rowMapper != null, "Predictor expected to be a RowMapper!"); return(Create(input, rowMapper, suffix, user)); }
/// <summary> /// The one and only constructor for Bindings. /// </summary> private Bindings(Schema input, ISchemaBoundRowMapper mapper, string suffix, bool user) : base(input, mapper, suffix, user) { Contracts.Assert(DerivedColumnCount == 0); }
/// <summary> /// Constructor for <see cref="ApplyToData"/> method. /// </summary> private GenericScorer(IHostEnvironment env, GenericScorer transform, IDataView data) : base(env, data, RegistrationName, transform.Bindable) { _bindings = transform._bindings.ApplyToSchema(env, data.Schema); Schema = Schema.Create(_bindings); }
/// <summary> /// Deserialize the bindings, given the env, bindable and input schema. /// </summary> public static Bindings Create(ModelLoadContext ctx, IHostEnvironment env, ISchemaBindableMapper bindable, Schema input) { Contracts.AssertValue(ctx); // *** Binary format *** // <base info> string suffix; var roles = LoadBaseInfo(ctx, out suffix); return(Create(env, bindable, input, roles, suffix, user: false)); }