|
4 | 4 |
|
5 | 5 | using Microsoft.ML.Data; |
6 | 6 |
|
7 | | -namespace Microsoft.ML |
8 | | -{ |
9 | | - // REVIEW: Would be nice if the registration under SignatureTrainer were automatic |
10 | | - // given registration for one of the "sub-class" signatures. |
| 7 | +namespace Microsoft.ML; |
11 | 8 |
|
12 | | - /// <summary> |
13 | | - /// Loadable class signatures for trainers. Typically each trainer should register with |
14 | | - /// both SignatureTrainer and SignatureXxxTrainer where Xxx is the prediction kind. |
15 | | - /// </summary> |
16 | | - [BestFriend] |
17 | | - internal delegate void SignatureTrainer(); |
| 9 | +// REVIEW: Would be nice if the registration under SignatureTrainer were automatic |
| 10 | +// given registration for one of the "sub-class" signatures. |
18 | 11 |
|
19 | | - [BestFriend] |
20 | | - internal delegate void SignatureBinaryClassifierTrainer(); |
21 | | - [BestFriend] |
22 | | - internal delegate void SignatureMulticlassClassifierTrainer(); |
23 | | - [BestFriend] |
24 | | - internal delegate void SignatureRegressorTrainer(); |
25 | | - [BestFriend] |
26 | | - internal delegate void SignatureMultiOutputRegressorTrainer(); |
27 | | - [BestFriend] |
28 | | - internal delegate void SignatureRankerTrainer(); |
29 | | - [BestFriend] |
30 | | - internal delegate void SignatureAnomalyDetectorTrainer(); |
31 | | - [BestFriend] |
32 | | - internal delegate void SignatureClusteringTrainer(); |
33 | | - [BestFriend] |
34 | | - internal delegate void SignatureSequenceTrainer(); |
35 | | - [BestFriend] |
36 | | - internal delegate void SignatureMatrixRecommendingTrainer(); |
| 12 | +/// <summary> |
| 13 | +/// Loadable class signatures for trainers. Typically each trainer should register with |
| 14 | +/// both SignatureTrainer and SignatureXxxTrainer where Xxx is the prediction kind. |
| 15 | +/// </summary> |
| 16 | +[BestFriend] |
| 17 | +internal delegate void SignatureTrainer(); |
37 | 18 |
|
| 19 | +[BestFriend] |
| 20 | +internal delegate void SignatureBinaryClassifierTrainer(); |
| 21 | +[BestFriend] |
| 22 | +internal delegate void SignatureMulticlassClassifierTrainer(); |
| 23 | +[BestFriend] |
| 24 | +internal delegate void SignatureRegressorTrainer(); |
| 25 | +[BestFriend] |
| 26 | +internal delegate void SignatureMultiOutputRegressorTrainer(); |
| 27 | +[BestFriend] |
| 28 | +internal delegate void SignatureRankerTrainer(); |
| 29 | +[BestFriend] |
| 30 | +internal delegate void SignatureAnomalyDetectorTrainer(); |
| 31 | +[BestFriend] |
| 32 | +internal delegate void SignatureClusteringTrainer(); |
| 33 | +[BestFriend] |
| 34 | +internal delegate void SignatureSequenceTrainer(); |
| 35 | +[BestFriend] |
| 36 | +internal delegate void SignatureMatrixRecommendingTrainer(); |
| 37 | + |
| 38 | +/// <summary> |
| 39 | +/// The base interface for a trainers. Implementors should not implement this interface directly, |
| 40 | +/// but rather implement the more specific <see cref="ITrainer{TPredictor}"/>. |
| 41 | +/// </summary> |
| 42 | +[BestFriend] |
| 43 | +internal interface ITrainer |
| 44 | +{ |
38 | 45 | /// <summary> |
39 | | - /// The base interface for a trainers. Implementors should not implement this interface directly, |
40 | | - /// but rather implement the more specific <see cref="ITrainer{TPredictor}"/>. |
| 46 | + /// Auxiliary information about the trainer in terms of its capabilities |
| 47 | + /// and requirements. |
41 | 48 | /// </summary> |
42 | | - [BestFriend] |
43 | | - internal interface ITrainer |
44 | | - { |
45 | | - /// <summary> |
46 | | - /// Auxiliary information about the trainer in terms of its capabilities |
47 | | - /// and requirements. |
48 | | - /// </summary> |
49 | | - TrainerInfo Info { get; } |
| 49 | + TrainerInfo Info { get; } |
50 | 50 |
|
51 | | - /// <summary> |
52 | | - /// Return the type of prediction task for the produced predictor. |
53 | | - /// </summary> |
54 | | - PredictionKind PredictionKind { get; } |
| 51 | + /// <summary> |
| 52 | + /// Return the type of prediction task for the produced predictor. |
| 53 | + /// </summary> |
| 54 | + PredictionKind PredictionKind { get; } |
55 | 55 |
|
56 | | - /// <summary> |
57 | | - /// Trains a predictor. |
58 | | - /// </summary> |
59 | | - /// <param name="context">A context containing at least the training data</param> |
60 | | - /// <returns>The trained predictor</returns> |
61 | | - /// <seealso cref="ITrainer{TPredictor}.Train(TrainContext)"/> |
62 | | - IPredictor Train(TrainContext context); |
63 | | - } |
| 56 | + /// <summary> |
| 57 | + /// Trains a predictor. |
| 58 | + /// </summary> |
| 59 | + /// <param name="context">A context containing at least the training data</param> |
| 60 | + /// <returns>The trained predictor</returns> |
| 61 | + /// <seealso cref="ITrainer{TPredictor}.Train(TrainContext)"/> |
| 62 | + IPredictor Train(TrainContext context); |
| 63 | +} |
64 | 64 |
|
| 65 | +/// <summary> |
| 66 | +/// Strongly typed generic interface for a trainer. A trainer object takes training data |
| 67 | +/// and produces a predictor. |
| 68 | +/// </summary> |
| 69 | +/// <typeparam name="TPredictor"> Type of predictor produced</typeparam> |
| 70 | +[BestFriend] |
| 71 | +internal interface ITrainer<out TPredictor> : ITrainer |
| 72 | + where TPredictor : IPredictor |
| 73 | +{ |
65 | 74 | /// <summary> |
66 | | - /// Strongly typed generic interface for a trainer. A trainer object takes training data |
67 | | - /// and produces a predictor. |
| 75 | + /// Trains a predictor. |
68 | 76 | /// </summary> |
69 | | - /// <typeparam name="TPredictor"> Type of predictor produced</typeparam> |
70 | | - [BestFriend] |
71 | | - internal interface ITrainer<out TPredictor> : ITrainer |
72 | | - where TPredictor : IPredictor |
73 | | - { |
74 | | - /// <summary> |
75 | | - /// Trains a predictor. |
76 | | - /// </summary> |
77 | | - /// <param name="context">A context containing at least the training data</param> |
78 | | - /// <returns>The trained predictor</returns> |
79 | | - new TPredictor Train(TrainContext context); |
80 | | - } |
| 77 | + /// <param name="context">A context containing at least the training data</param> |
| 78 | + /// <returns>The trained predictor</returns> |
| 79 | + new TPredictor Train(TrainContext context); |
| 80 | +} |
81 | 81 |
|
82 | | - [BestFriend] |
83 | | - internal static class TrainerExtensions |
84 | | - { |
85 | | - /// <summary> |
86 | | - /// Convenience train extension for the case where one has only a training set with no auxiliary information. |
87 | | - /// Equivalent to calling <see cref="ITrainer.Train(TrainContext)"/> |
88 | | - /// on a <see cref="TrainContext"/> constructed with <paramref name="trainData"/>. |
89 | | - /// </summary> |
90 | | - /// <param name="trainer">The trainer</param> |
91 | | - /// <param name="trainData">The training data.</param> |
92 | | - /// <returns>The trained predictor</returns> |
93 | | - public static IPredictor Train(this ITrainer trainer, RoleMappedData trainData) |
94 | | - => trainer.Train(new TrainContext(trainData)); |
| 82 | +[BestFriend] |
| 83 | +internal static class TrainerExtensions |
| 84 | +{ |
| 85 | + /// <summary> |
| 86 | + /// Convenience train extension for the case where one has only a training set with no auxiliary information. |
| 87 | + /// Equivalent to calling <see cref="ITrainer.Train(TrainContext)"/> |
| 88 | + /// on a <see cref="TrainContext"/> constructed with <paramref name="trainData"/>. |
| 89 | + /// </summary> |
| 90 | + /// <param name="trainer">The trainer</param> |
| 91 | + /// <param name="trainData">The training data.</param> |
| 92 | + /// <returns>The trained predictor</returns> |
| 93 | + public static IPredictor Train(this ITrainer trainer, RoleMappedData trainData) |
| 94 | + => trainer.Train(new TrainContext(trainData)); |
95 | 95 |
|
96 | | - /// <summary> |
97 | | - /// Convenience train extension for the case where one has only a training set with no auxiliary information. |
98 | | - /// Equivalent to calling <see cref="ITrainer{TPredictor}.Train(TrainContext)"/> |
99 | | - /// on a <see cref="TrainContext"/> constructed with <paramref name="trainData"/>. |
100 | | - /// </summary> |
101 | | - /// <param name="trainer">The trainer</param> |
102 | | - /// <param name="trainData">The training data.</param> |
103 | | - /// <returns>The trained predictor</returns> |
104 | | - public static TPredictor Train<TPredictor>(this ITrainer<TPredictor> trainer, RoleMappedData trainData) where TPredictor : IPredictor |
105 | | - => trainer.Train(new TrainContext(trainData)); |
106 | | - } |
| 96 | + /// <summary> |
| 97 | + /// Convenience train extension for the case where one has only a training set with no auxiliary information. |
| 98 | + /// Equivalent to calling <see cref="ITrainer{TPredictor}.Train(TrainContext)"/> |
| 99 | + /// on a <see cref="TrainContext"/> constructed with <paramref name="trainData"/>. |
| 100 | + /// </summary> |
| 101 | + /// <param name="trainer">The trainer</param> |
| 102 | + /// <param name="trainData">The training data.</param> |
| 103 | + /// <returns>The trained predictor</returns> |
| 104 | + public static TPredictor Train<TPredictor>(this ITrainer<TPredictor> trainer, RoleMappedData trainData) where TPredictor : IPredictor |
| 105 | + => trainer.Train(new TrainContext(trainData)); |
107 | 106 | } |
0 commit comments