Skip to content

Commit

Permalink
Suggested changes to progress bar (dotnet#335)
Browse files Browse the repository at this point in the history
* progressbar

* added progressbar and refactoring

* reverted

* revert sign assembly

* added headers and removed exception rethrow

* bug fixes and updates to UI

* added friendly name printing for metric

* formatting
  • Loading branch information
srsaggam authored Apr 1, 2019
1 parent 701aa82 commit c674103
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
10 changes: 6 additions & 4 deletions src/mlnet/CodeGenerator/CodeGenerationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ public void GenerateCode()
{
ForegroundColor = ConsoleColor.Yellow,
ForegroundColorDone = ConsoleColor.DarkGreen,
BackgroundColor = ConsoleColor.DarkGray,
BackgroundCharacter = '\u2593'
BackgroundColor = ConsoleColor.Gray,
ProgressCharacter = '\u2593',
BackgroundCharacter = '─',
};
var wait = TimeSpan.FromSeconds(settings.MaxExplorationTime);
using (var pbar = new FixedDurationBar(wait, "", options))
Expand All @@ -114,9 +115,10 @@ public void GenerateCode()

if (t.IsCompleted == false)
{
logger.Log(LogLevel.Info, "Waiting for the last iteration to complete ...");
string originalMessage = pbar.Message;
pbar.Message = " Waiting for the last iteration to complete ...";
t.Wait();
}
t.Wait();
}

}
Expand Down
36 changes: 18 additions & 18 deletions src/mlnet/Utilities/ConsolePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ internal static void PrintMetrics(int iteration, string trainerName, RegressionM

internal static void PrintBinaryClassificationMetricsHeader(LogLevel logLevel)
{
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(logLevel, $"{Strings.MetricsForBinaryClassModels}");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(logLevel, $"{" ",-4} {"Trainer",-35} {"Accuracy",9} {"AUC",8} {"AUPRC",8} {"F1-score",9} {"Best",8} {"Duration",9}");
}

internal static void PrintMulticlassClassificationMetricsHeader(LogLevel logLevel)
{
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(logLevel, $"{Strings.MetricsForMulticlassModels}");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(logLevel, $"{" ",-4} {"Trainer",-35} {"AccuracyMicro",14} {"AccuracyMacro",14} {"Best",14} {"Duration",9}");
}

internal static void PrintRegressionMetricsHeader(LogLevel logLevel)
{
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(logLevel, $"{Strings.MetricsForRegressionModels}");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(logLevel, $"{" ",-4} {"Trainer",-35} {"R2-Score",9} {"LossFn",12} {"Absolute-loss",15} {"Squared-loss",15} {"RMS-loss",12} {"Best",12} {"Duration",9}");
}

Expand All @@ -70,61 +70,61 @@ internal static void PrintTopNHeader(int count)

internal static void ExperimentResultsHeader(LogLevel logLevel, string mltask, string datasetName, string labelName, string time, int numModelsExplored)
{
logger.Log(logLevel, $"===============================Experiment Results===================================");
logger.Log(logLevel, $"------------------------------------------------------------------------------------");
logger.Log(logLevel, $"==============================================Experiment Results==================================================");
logger.Log(logLevel, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(logLevel, $"{"ML Task",-7} : {mltask,-20}");
logger.Log(logLevel, $"{"Dataset",-7}: {datasetName,-25}");
logger.Log(logLevel, $"{"Label",-6} : {labelName,-25}");
logger.Log(logLevel, $"{"Exploration time",-20} : {time} Secs");
logger.Log(logLevel, $"{"Total number of models explored",-30} : {numModelsExplored}");
logger.Log(logLevel, $"------------------------------------------------------------------------------------");
logger.Log(logLevel, $"------------------------------------------------------------------------------------------------------------------");
}
internal static void PrintIterationSummary(IEnumerable<RunResult<BinaryClassificationMetrics>> results, BinaryClassificationMetric optimizationMetric, int count)
{
var metricsAgent = new BinaryMetricsAgent(optimizationMetric);
var topNResults = RunResultUtil.GetTopNRunResults(results, metricsAgent, count);
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"Top {topNResults?.Count()} models explored ");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
PrintBinaryClassificationMetricsHeader(LogLevel.Info);
int i = 0;
foreach (var result in topNResults)
{
PrintMetrics(++i, result.TrainerName, result.ValidationMetrics, metricsAgent.GetScore(result.ValidationMetrics), result.RuntimeInSeconds, LogLevel.Info);
}
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
}

internal static void PrintIterationSummary(IEnumerable<RunResult<RegressionMetrics>> results, RegressionMetric optimizationMetric, int count)
{
var metricsAgent = new RegressionMetricsAgent(optimizationMetric);
var topNResults = RunResultUtil.GetTopNRunResults(results, metricsAgent, count);
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"Top {topNResults?.Count()} models explored ");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
PrintRegressionMetricsHeader(LogLevel.Info);
int i = 0;
foreach (var result in topNResults)
{
PrintMetrics(++i, result.TrainerName, result.ValidationMetrics, metricsAgent.GetScore(result.ValidationMetrics), result.RuntimeInSeconds, LogLevel.Info);
}
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
}

internal static void PrintIterationSummary(IEnumerable<RunResult<MultiClassClassifierMetrics>> results, MulticlassClassificationMetric optimizationMetric, int count)
{
var metricsAgent = new MultiMetricsAgent(optimizationMetric);
var topNResults = RunResultUtil.GetTopNRunResults(results, metricsAgent, count);
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"Top {topNResults?.Count()} models explored ");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
PrintMulticlassClassificationMetricsHeader(LogLevel.Info);
int i = 0;
foreach (var result in topNResults)
{
PrintMetrics(++i, result.TrainerName, result.ValidationMetrics, metricsAgent.GetScore(result.ValidationMetrics), result.RuntimeInSeconds, LogLevel.Info);
}
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------");
logger.Log(LogLevel.Info, $"------------------------------------------------------------------------------------------------------------------");
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions src/mlnet/Utilities/ProgressHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ private void UpdateBestResult(RunResult<RegressionMetrics> iterationResult)
if (MetricComparator(GetScore(iterationResult), GetScore(bestResult), isMaximizing) > 0)
{
bestResult = iterationResult;
progressBar.Message = $"Best {this.optimizationMetric} : {GetScore(bestResult)} , Best Algorithm : {iterationResult.TrainerName}";
progressBar.Message = $"Best {this.optimizationMetric} : {GetScore(bestResult):F2} , Best Algorithm : {bestResult.TrainerName}, Last Algorithm : {bestResult.TrainerName}";
}
else
{
progressBar.Message = $"Best {this.optimizationMetric} : {GetScore(bestResult):F2} , Best Algorithm : {bestResult.TrainerName}, Last Algorithm : {iterationResult.TrainerName}";
}
}
}
Expand Down Expand Up @@ -82,7 +86,11 @@ private void UpdateBestResult(RunResult<BinaryClassificationMetrics> iterationRe
if (MetricComparator(GetScore(iterationResult), GetScore(bestResult), isMaximizing) > 0)
{
bestResult = iterationResult;
progressBar.Message = $"Best {this.optimizationMetric} : {GetScore(bestResult)} , Best Algorithm : {iterationResult.TrainerName}";
progressBar.Message = $"Best {this.optimizationMetric} : {GetScore(bestResult):F2} , Best Algorithm : {bestResult.TrainerName}, Last Algorithm : {bestResult.TrainerName}";
}
else
{
progressBar.Message = $"Best {this.optimizationMetric} : {GetScore(bestResult):F2} , Best Algorithm : {bestResult.TrainerName}, Last Algorithm : {iterationResult.TrainerName}";
}
}
}
Expand Down Expand Up @@ -117,7 +125,11 @@ private void UpdateBestResult(RunResult<MultiClassClassifierMetrics> iterationRe
if (MetricComparator(GetScore(iterationResult), GetScore(bestResult), isMaximizing) > 0)
{
bestResult = iterationResult;
progressBar.Message = $"Best {this.optimizationMetric} : {GetScore(bestResult)} , Best Algorithm : {iterationResult.TrainerName}";
progressBar.Message = $"Best {this.optimizationMetric} : {GetScore(bestResult):F2} , Best Algorithm : {bestResult.TrainerName}, Last Algorithm : {bestResult.TrainerName}";
}
else
{
progressBar.Message = $"Best {this.optimizationMetric} : {GetScore(bestResult):F2} , Best Algorithm : {bestResult.TrainerName}, Last Algorithm : {iterationResult.TrainerName}";
}
}
}
Expand Down

0 comments on commit c674103

Please sign in to comment.