-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Update MacroUtils to map trainer kinds to the correct suffix of trainer entry point names #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
02f72c9
ff6736d
1d01831
f1bbeda
db8492d
4267412
9bb6c89
be06047
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ private static Dictionary<TrainerKinds, TaskInformationBundle> | |
| { | ||
| TrainerKinds.SignatureBinaryClassifierTrainer, | ||
| new TaskInformationBundle { | ||
| TrainerFunctionName = "TrainBinary", | ||
| TrainerFunctionName = "BinaryClassifier", | ||
| TrainerSignatureType = typeof(SignatureBinaryClassifierTrainer), | ||
| EvaluatorInput = settings => new Models.BinaryClassificationEvaluator | ||
| { | ||
|
|
@@ -71,7 +71,7 @@ private static Dictionary<TrainerKinds, TaskInformationBundle> | |
| { | ||
| TrainerKinds.SignatureMultiClassClassifierTrainer, | ||
| new TaskInformationBundle{ | ||
| TrainerFunctionName = "TrainMultiClass", | ||
| TrainerFunctionName = "Classifier", | ||
| TrainerSignatureType = typeof(SignatureMultiClassClassifierTrainer), | ||
| EvaluatorInput = settings => new Models.ClassificationEvaluator | ||
| { | ||
|
|
@@ -87,7 +87,7 @@ private static Dictionary<TrainerKinds, TaskInformationBundle> | |
| { | ||
| TrainerKinds.SignatureRankerTrainer, | ||
| new TaskInformationBundle { | ||
| TrainerFunctionName = "TrainRanking", | ||
| TrainerFunctionName = "Ranker", | ||
| TrainerSignatureType = typeof(SignatureRankerTrainer), | ||
| EvaluatorInput = settings => new Models.RankerEvaluator | ||
| { | ||
|
|
@@ -103,7 +103,7 @@ private static Dictionary<TrainerKinds, TaskInformationBundle> | |
| { | ||
| TrainerKinds.SignatureRegressorTrainer, | ||
| new TaskInformationBundle{ | ||
| TrainerFunctionName = "TrainRegression", | ||
| TrainerFunctionName = "Regressor", | ||
| TrainerSignatureType = typeof(SignatureRegressorTrainer), | ||
| EvaluatorInput = settings => new Models.RegressionEvaluator | ||
| { | ||
|
|
@@ -119,7 +119,7 @@ private static Dictionary<TrainerKinds, TaskInformationBundle> | |
| { | ||
| TrainerKinds.SignatureMultiOutputRegressorTrainer, | ||
| new TaskInformationBundle { | ||
| TrainerFunctionName = "TrainMultiRegression", | ||
| TrainerFunctionName = "MultiOutputRegressor", | ||
| TrainerSignatureType = typeof(SignatureMultiOutputRegressorTrainer), | ||
| EvaluatorInput = settings => new Models.MultiOutputRegressionEvaluator | ||
| { | ||
|
|
@@ -135,7 +135,7 @@ private static Dictionary<TrainerKinds, TaskInformationBundle> | |
| { | ||
| TrainerKinds.SignatureAnomalyDetectorTrainer, | ||
| new TaskInformationBundle { | ||
| TrainerFunctionName = "TrainAnomalyDetection", | ||
| TrainerFunctionName = "AnomalyDetector", | ||
| TrainerSignatureType = typeof(SignatureAnomalyDetectorTrainer), | ||
| EvaluatorInput = settings => new Models.AnomalyDetectionEvaluator | ||
| { | ||
|
|
@@ -151,7 +151,7 @@ private static Dictionary<TrainerKinds, TaskInformationBundle> | |
| { | ||
| TrainerKinds.SignatureClusteringTrainer, | ||
| new TaskInformationBundle { | ||
| TrainerFunctionName = "TrainClustering", | ||
| TrainerFunctionName = "Clusterer", | ||
| TrainerSignatureType = typeof(SignatureClusteringTrainer), | ||
| EvaluatorInput = settings => new Models.ClusterEvaluator | ||
| { | ||
|
|
@@ -186,13 +186,29 @@ public static TrainerKinds SignatureTypeToTrainerKind(Type sigType) | |
| public static TrainerKinds[] SignatureTypesToTrainerKinds(IEnumerable<Type> sigTypes) => | ||
| sigTypes.Select(SignatureTypeToTrainerKind).ToArray(); | ||
|
|
||
| public static string GetTrainerName(TrainerKinds kind) => TrainerKindDict[kind].TrainerFunctionName; | ||
| private static string GetTrainerName(TrainerKinds kind) => TrainerKindDict[kind].TrainerFunctionName; | ||
|
|
||
| public static T TrainerKindApiValue<T>(TrainerKinds trainerKind) | ||
| { | ||
| if (Enum.GetName(typeof(TrainerKinds), trainerKind) is string name) | ||
| return (T)Enum.Parse(typeof(T), name); | ||
| throw new Exception($"Could not interpret enum value: {trainerKind}"); | ||
| } | ||
|
|
||
| public static bool IsTrainerOfKind(Type type, TrainerKinds trainerKind) | ||
| { | ||
| if (type == typeof(Trainers.BinaryLogisticRegressor)) | ||
| return trainerKind == TrainerKinds.SignatureBinaryClassifierTrainer; | ||
| if (type == typeof(Trainers.LogisticRegressor)) | ||
| return trainerKind == TrainerKinds.SignatureMultiClassClassifierTrainer; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. God, this is so ugly.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A better solution might be harder to imagine though. We might let this slide for now since this change will fix things that are broken now, but we ought definitely to file a new issue so we can imagine something a bit less fragile than this system. In reply to: 187421786 [](ancestors = 187421786)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be addressed when we change the mechanism to use the EntryPoint attribute?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The entry-point attribute may indeed be the best place to put a category like this -- something akin to the old-style In reply to: 187457279 [](ancestors = 187457279) |
||
|
|
||
| if (trainerKind != TrainerKinds.SignatureMultiClassClassifierTrainer && trainerKind != TrainerKinds.SignatureMultiOutputRegressorTrainer) | ||
| return type.Name.EndsWith(GetTrainerName(trainerKind)); | ||
|
|
||
| if (trainerKind == TrainerKinds.SignatureMultiClassClassifierTrainer) | ||
| return type.Name.EndsWith(GetTrainerName(trainerKind)) && !type.Name.EndsWith(GetTrainerName(TrainerKinds.SignatureBinaryClassifierTrainer)); | ||
|
|
||
| return type.Name.EndsWith(GetTrainerName(trainerKind)) && !type.Name.EndsWith(GetTrainerName(TrainerKinds.SignatureRegressorTrainer)); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You said something about a name suffix... is it a concern that the suffixes are not unique? So
Regressorabove would be a suffix of anyMultiOutputRegressor. We previously worked around this problem I guess by having every suffix start withTrain, but that solution has gone out the window I suppose.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar notes for
Classifiervs.BinaryClassifier.In reply to: 187424111 [](ancestors = 187424111)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK now I know you've special cased this. :) Hmmm I'd still rather have a different solution.
In reply to: 187424194 [](ancestors = 187424194,187424111)