private protected override ISchemaBoundMapper BindCore(IChannel ch, RoleMappedSchema schema) { return(new SingleValueRowMapper(schema, this, Schema.Create(new SchemaImpl(ScoreType, _quantiles)))); }
/// <summary> /// Common method of computing <see cref="_sources"/> from necessary parameters. This function is used in constructors. /// </summary> private static void ComputeSources(bool drop, int[] selectedColumnIndexes, Schema sourceSchema, out int[] sources) { // Compute the mapping, <see cref="_sources"/>, from output column index to input column index. if (drop) { // Drop columns indexed by args.Indices sources = Enumerable.Range(0, sourceSchema.Count).Except(selectedColumnIndexes).ToArray(); } else { // Keep columns indexed by args.Indices sources = selectedColumnIndexes; } // Make sure the output of this transform is meaningful. Contracts.Check(sources.Length > 0, "Choose columns by index has no output column."); }
public SingleValueRowMapper(RoleMappedSchema schema, SchemaBindablePredictorWrapperBase parent, Schema outputSchema) { Contracts.AssertValue(schema); Contracts.AssertValue(parent); Contracts.Assert(schema.Feature.HasValue); Contracts.Assert(outputSchema.Count == 1); _parent = parent; InputRoleMappedSchema = schema; OutputSchema = outputSchema; }
private protected override ISchemaBoundMapper BindCore(IChannel ch, RoleMappedSchema schema) { var outputSchema = Schema.Create(new ScoreMapperSchema(ScoreType, _scoreColumnKind)); return(new SingleValueRowMapper(schema, this, outputSchema)); }
/// <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> /// 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> /// Constructor for <see cref="ApplyToDataCore"/> method. /// </summary> private GenericScorer(IHostEnvironment env, GenericScorer transform, IDataView data) : base(env, data, RegistrationName, transform.Bindable) { _bindings = transform._bindings.ApplyToSchema(env, data.Schema); OutputSchema = _bindings.AsSchema; }
/// <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)); }
/// <summary> /// Constructor given a schema, and mapping pairs of roles to columns in the schema. /// This skips null or empty column names. It will also skip column-names that are not /// found in the schema if <paramref name="opt"/> is true. /// </summary> /// <param name="schema">The schema over which roles are defined</param> /// <param name="roles">The column role to column name mappings</param> /// <param name="opt">Whether to consider the column names specified "optional" or not. If <c>false</c> then any non-empty /// values for the column names that does not appear in <paramref name="schema"/> will result in an exception being thrown, /// but if <c>true</c> such values will be ignored</param> public RoleMappedSchema(Schema schema, IEnumerable <KeyValuePair <ColumnRole, string> > roles, bool opt = false) : this(Contracts.CheckRef(schema, nameof(schema)), MapFromNames(schema, Contracts.CheckRef(roles, nameof(roles)), opt)) { }
/// <summary> /// Constructor given a schema, and mapping pairs of roles to columns in the schema. /// This skips null or empty column-names. It will also skip column-names that are not /// found in the schema if <paramref name="opt"/> is true. /// </summary> /// <param name="schema">The schema over which roles are defined</param> /// <param name="opt">Whether to consider the column names specified "optional" or not. If <c>false</c> then any non-empty /// values for the column names that does not appear in <paramref name="schema"/> will result in an exception being thrown, /// but if <c>true</c> such values will be ignored</param> /// <param name="roles">The column role to column name mappings</param> public RoleMappedSchema(Schema schema, bool opt = false, params KeyValuePair <ColumnRole, string>[] roles) : this(Contracts.CheckRef(schema, nameof(schema)), Contracts.CheckRef(roles, nameof(roles)), opt) { }
private RoleMappedSchema(Schema schema, Dictionary <string, List <Schema.Column> > map) : this(schema, Copy(map)) { }