refactor worst features

This commit is contained in:
Filip Gralinski 2018-08-06 21:34:38 +02:00
parent 6a862c0e82
commit 3f3d1fd287

View File

@ -68,22 +68,24 @@ runLineByLine ordering spec = runLineByLineGeneralized ordering spec consum
formatScore = Data.Text.pack . printf "%f" formatScore = Data.Text.pack . printf "%f"
runWorstFeatures :: ResultOrdering -> GEvalSpecification -> IO () runWorstFeatures :: ResultOrdering -> GEvalSpecification -> IO ()
runWorstFeatures ordering spec = runLineByLineGeneralized ordering' spec consum runWorstFeatures ordering spec = runLineByLineGeneralized ordering' spec (worstFeaturesPipeline spec)
where consum :: ConduitT LineRecord Void (ResourceT IO) () where ordering' = forceSomeOrdering ordering
consum = (rank (lessByMetric $ gesMainMetric spec)
worstFeaturesPipeline :: GEvalSpecification -> ConduitT LineRecord Void (ResourceT IO) ()
worstFeaturesPipeline spec = rank (lessByMetric $ gesMainMetric spec)
.| evalStateC 0 extractFeaturesAndPValues .| evalStateC 0 extractFeaturesAndPValues
.| gobbleAndDo (sortBy featureOrder) .| gobbleAndDo (sortBy featureOrder)
.| CL.map (encodeUtf8 . formatFeatureWithPValue) .| CL.map (encodeUtf8 . formatFeatureWithPValue)
.| CC.unlinesAscii .| CC.unlinesAscii
.| CC.stdout) .| CC.stdout
formatOutput (LineRecord inp exp out _ score) = Data.Text.intercalate "\t" [ where formatOutput (LineRecord inp exp out _ score) = Data.Text.intercalate "\t" [
formatScore score, formatScore score,
escapeTabs inp, escapeTabs inp,
escapeTabs exp, escapeTabs exp,
escapeTabs out] escapeTabs out]
formatScore :: MetricValue -> Text formatScore :: MetricValue -> Text
formatScore = Data.Text.pack . printf "%f" formatScore = Data.Text.pack . printf "%f"
ordering' = forceSomeOrdering ordering
featureOrder (FeatureWithPValue _ p1 _ _) (FeatureWithPValue _ p2 _ _) = featureOrder (FeatureWithPValue _ p1 _ _) (FeatureWithPValue _ p2 _ _) =
p1 `compare` p2 p1 `compare` p2