checkpoint alternate table layout

This commit is contained in:
Simon Gruber
2023-11-20 14:50:23 +01:00
parent 9ac01e6b12
commit e58fbc2d06
3 changed files with 21 additions and 26 deletions
+8 -18
View File
@@ -24,29 +24,19 @@ internal readonly struct ImageStats
public IEnumerable<IEnumerable<string>> ToTable()
{
// Title
yield return Stats.Select(s => s.ProcessorName).Prepend("Reference");
yield return Reference
.Prepend("Processor")
.Append("WER")
.Append("CER (avg)")
.Append("CER (sum)");
// Spacer
yield return Stats.Select(s => "---").Prepend("---");
yield return Enumerable.Range(0, Reference.Count + 4).Select(_ => "---");
// Content
foreach (var reference in Reference)
foreach (var stat in Stats)
{
yield return Stats.SelectMany(s => s.ToRow(reference)).Prepend(reference);
yield return stat.ToRow();
}
// Spacer
yield return Stats.Select(s => "---").Prepend("---");
// Summaries
yield return Stats
.Select(s => s.CharacterStats.Average(s => s.CharacterError).ToString("F2"))
.Prepend("CER (avg)");
yield return Stats
.Select(s => s.CharacterStats.Sum(s => s.CharacterError).ToString("F2"))
.Prepend("CER (sum)");
yield return Stats
.Select(s => s.WordError.ToString("F2"))
.Prepend("WER");
}
}
@@ -25,9 +25,12 @@ internal readonly struct ProcessorStat
).ToArray();
}
public IEnumerable<string> ToRow(string word) => CharacterStats
.Where(s => string.Equals(s.Reference, word))
.Select(s => s.ToString());
public IEnumerable<string> ToRow() => CharacterStats
.Select(s => s.ToString())
.Append(WordError.ToString("F2"))
.Append(CharacterStats.Average(s => s.CharacterError).ToString("F2"))
.Append(CharacterStats.Sum(s => s.CharacterError).ToString("F2"))
.Prepend(ProcessorName);
/// <summary>
/// Finds the smallest possible CER by calculating the levenshtein
@@ -65,12 +68,14 @@ internal readonly struct ProcessorStat
static double CalculateWer(ICollection<string> expected, ICollection<string> actual)
{
if (!actual.Any())
{
return double.PositiveInfinity;
}
// Amount of words that need to be substituted to match the original
int substitutions = expected
.Zip(
actual,
(e, a) => string.Equals(e, a) ? 0 : 1
)
.Zip(actual, (e, a) => string.Equals(e, a) ? 0 : 1)
.Sum();
// todo this isn't correct i think
+1 -1
View File
@@ -42,7 +42,7 @@ internal static class Program
var scanFileLookup = scanFileInfos.ToLookup(i => i.ImageName);
return tagFileInfos.Select(i => new ImageStats(
i.ImageName,
i.GetWords(),
i.GetWords().OrderBy(w => w).ToArray(),
scanFileLookup[i.ImageName]
));
}