private protected TrainCatalogBase(IHostEnvironment env, string registrationName) { Contracts.CheckValue(env, nameof(env)); env.CheckNonEmpty(registrationName, nameof(registrationName)); Environment = env; }
internal bool TryFindColumn(string name, out Column column) { Contracts.CheckValue(name, nameof(name)); column = _columns.FirstOrDefault(x => x.Name == name); return(column.IsValid); }
public SchemaShape(IEnumerable <Column> columns) { Contracts.CheckValue(columns, nameof(columns)); _columns = columns.ToArray(); Contracts.CheckParam(columns.All(c => c.IsValid), nameof(columns), "Some items are not initialized properly."); }
/// <summary> /// Predict a target using the random binary classification model <see cref="RandomTrainer"/>. /// </summary> /// <remarks> /// This trainer can be used as a baseline for other more sophisticated mdels. /// </remarks> /// <param name="catalog">The <see cref="BinaryClassificationCatalog"/>.</param> /// <example> /// <format type="text/markdown"> /// <![CDATA[ /// [!code-csharp[FastTree](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/RandomTrainerSample.cs)] /// ]]></format> /// </example> public static RandomTrainer Random(this BinaryClassificationCatalog.BinaryClassificationTrainers catalog) { Contracts.CheckValue(catalog, nameof(catalog)); return(new RandomTrainer(CatalogUtils.GetEnvironment(catalog), new RandomTrainer.Options())); }
internal IEnumerable <ComponentInfo> GetAllComponents(Type interfaceType) { Contracts.CheckValue(interfaceType, nameof(interfaceType)); return(_components.Where(x => x.InterfaceType == interfaceType).OrderBy(x => x.Name)); }
protected LoadableClassAttributeBase(string summary, Type instType, Type loaderType, Type argType, Type[] sigTypes, string userName, params string[] loadNames) { Contracts.CheckValueOrNull(summary); Contracts.CheckValue(instType, nameof(instType)); Contracts.CheckValue(loaderType, nameof(loaderType)); Contracts.CheckNonEmpty(sigTypes, nameof(sigTypes)); if (Utils.Size(loadNames) == 0) { loadNames = new string[] { userName } } ; if (loadNames.Any(s => string.IsNullOrWhiteSpace(s))) { throw Contracts.ExceptEmpty(nameof(loadNames), "LoadableClass loadName parameter can't be empty"); } var sigType = sigTypes[0]; Contracts.CheckValue(sigType, nameof(sigTypes)); Type[] types; Contracts.CheckParam(sigType.BaseType == typeof(System.MulticastDelegate), nameof(sigTypes), "LoadableClass signature type must be a delegate type"); var meth = sigType.GetMethod("Invoke"); Contracts.CheckParam(meth != null, nameof(sigTypes), "LoadableClass signature type must be a delegate type"); Contracts.CheckParam(meth.ReturnType == typeof(void), nameof(sigTypes), "LoadableClass signature type must be a delegate type with void return"); var parms = meth.GetParameters(); int itypeBase = 0; if (argType != null) { types = new Type[1 + parms.Length]; types[itypeBase++] = argType; } else if (parms.Length > 0) { types = new Type[parms.Length]; } else { types = Type.EmptyTypes; } for (int itype = 0; itype < parms.Length; itype++) { var parm = parms[itype]; if ((parm.Attributes & (ParameterAttributes.Out | ParameterAttributes.Retval)) != 0) { throw Contracts.Except("Invalid signature parameter attributes"); } types[itypeBase + itype] = parm.ParameterType; } for (int i = 1; i < sigTypes.Length; i++) { sigType = sigTypes[i]; Contracts.CheckValue(sigType, nameof(sigTypes)); Contracts.Check(sigType.BaseType == typeof(System.MulticastDelegate), "LoadableClass signature type must be a delegate type"); meth = sigType.GetMethod("Invoke"); Contracts.CheckParam(meth != null, nameof(sigTypes), "LoadableClass signature type must be a delegate type"); Contracts.CheckParam(meth.ReturnType == typeof(void), nameof(sigTypes), "LoadableClass signature type must be a delegate type with void return"); parms = meth.GetParameters(); Contracts.CheckParam(parms.Length + itypeBase == types.Length, nameof(sigTypes), "LoadableClass signatures must have the same number of parameters"); for (int itype = 0; itype < parms.Length; itype++) { var parm = parms[itype]; if ((parm.Attributes & (ParameterAttributes.Out | ParameterAttributes.Retval)) != 0) { throw Contracts.ExceptParam(nameof(sigTypes), "Invalid signature parameter attributes"); } Contracts.CheckParam(types[itypeBase + itype] == parm.ParameterType, nameof(sigTypes), "LoadableClass signatures must have the same set of parameters"); } } InstanceType = instType; LoaderType = loaderType; ArgType = argType; SigTypes = sigTypes; CtorTypes = types; Summary = summary; UserName = userName; LoadNames = loadNames; } }